目录
一、安装nginx
1、关闭防火墙和selinux
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# iptables -F
2、安装依赖软件
[root@localhost ~]# yum -y install pcre-devel zlib-devel gcc gcc-c++ lrzsz
3、创建管理nginx用户
[root@localhost ~]# useradd -M -s /sbin/nologin nginx
4、解压源码包
[root@localhost ~]# rz
[root@localhost ~]# tar xf nginx-1.16.0.tar.gz -C /usr/src
[root@localhost ~]# cd /usr/src/nginx-1.16.0/
[root@localhost nginx-1.16.0]#
5、安装nginx
[root@localhost nginx-1.16.0]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --user=nginx
[root@localhost nginx-1.16.0]# make && make install
6、优化nginx命令
[root@localhost ~]# ln -s /usr/local/nginx/sbin/* /usr/local/sbin/
7、检测配置文件是否有错误
[root@localhost ~]# nginx -t
8、启动nginx
[root@localhost ~]# nginx
9、编辑nginx脚本(可根据自己需求编辑)
[root@localhost etc]# vim /etc/init.d/nginx
#!/bin/bash
#chkconfig:2345 99 20
# description: Nginx Server Control Script
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
PROG_FPM="/usr/local/sbin/php-fpm"
PIDF_FPM="/usr/local/php5/var/run/php-fpm.pid"
case "$1" in
start)
$PROG
$PROG_FPM
;;
stop)
kill -s QUIT $(cat $PIDF)
kill -s QUIT $(cat $PIDF_FPM)
;;
restart)
$0 stop
$0 start
;;
reload)
kill -s HUP $(cat $PIDF)
;;
*)
echo "Usage: $0 (start|stop|restart|reload)"
exit 1
esac
exit 0
[root@localhost ~]# chmod +x /etc/init.d/nginx
[root@localhost ~]# chkconfig --add nginx #优化命令
二、安装mysql数据库
1、先查看有没有libaio依赖包
[root@localhost conf]# yum -y install libaio
2、上传MySQL二进制安装包解压、安装
[root@localhost ~]# tar xf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz -C /usr/local #解压MySQL
[root@localhost ~]# cd /usr/local/
[root@localhost local]# mv mysql-5.7.24-linux-glibc2.12-x86_64/ mysql #改名字
3、添加用户和组
[root@localhost local]# useradd -s /sbin/nologin mysql
[root@localhost local]# cd mysql/
[root@localhost mysql]# chown -R mysql:mysql ./ #将当前目录下的用户和组都递归给入权限
4、初始化数据库
[root@localhost ~]# /usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize #将初始化完成后的最后那串密码给保存下来
5、进入主配置文件
[root@localhost mysql]# vim /etc/my.cnf
[mysqld]
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
[mysqld_safe]
log-error=/usr/local/mysql/data/mysql.log
pid-file=/usr/local/mysql/data/mysql.pid
6、启动服务
[root@localhost mysql]# ./support-files/mysql.server start
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld #将
MySQL服务加入到系统服务当中
[root@localhost mysql]# chmod +x /etc/init.d/mysqld #将脚本加入执行权限
[root@localhost ~]# chkconfig --add mysqld #优化命令
[root@localhost ~]# systemctl start mysqld #启动
[root@localhost ~]# ln -s /usr/local/mysql/bin/* /usr/bin/
7、更改MySQL数据库登陆密码
[root@localhost ~]# mysqladmin -uroot -p'T;PNK1Odu:i<' password 123456 #修改MySQL密码
[root@localhost ~]# mysql -uroot -p123456 #登录MySQL
三、安装PHP
1、安装依赖包
[root@localhost ~]# yum -y install gd libxml2-devel.x86_64 libjpeg-devel libpng-devel
2、上传PHP安装包
[root@localhost ~]# tar xf php-5.6.39.tar.gz -C /usr/src #解压安装包
[root@localhost ~]# cd /usr/src/php-5.6.39/ #进入到解压路径
[root@localhost php-5.6.39]# ./configure --prefix=/usr/local/php5 --with-gd --with-zlib --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-config-file-path=/usr/local/php5 --enable-mbstring --enable-fpm --with-jbeg-dir=/usr/lib && make && make install #进行安装
[root@localhost php-5.6.39]# cp php.ini-production /usr/local/php5/php.ini #准备配置文件
3、命令优化
[root@localhost php-5.6.39]# ln -s /usr/local/php5/bin/* /usr/local/bin/
[root@localhost php-5.6.39]# ln -s /usr/local/php5/sbin/* /usr/local/sbin/
4、上传 zend -loader安装包
[root@localhost ~]# tar xf zend-loader-php5.6-linux-x86_64_update1.tar.gz #解压
[root@localhost ~]# cd zend-loader-php5.6-linux-x86_64/ #进入解压路径
[root@localhost zend-loader-php5.6-linux-x86_64]# cp ZendGuardLoader.so /usr/local/php5/lib/php #复制
5、编辑配置文件
zend_extension=/usr/local/php5/lib/php/ZendGuardLoader.so
zend_loader.enable=1 #在底部写入两行
[root@localhost zend-loader-php5.6-linux-x86_64]# cd /usr/local/php5/etc/
[root@localhost etc]# mv php-fpm.conf.default php-fpm.conf #改文件名
[root@localhost etc]# vim php-fpm.conf #进入主配置文件
149行 user = php
150行 group = php
241行 pm.max_children = 50
246行 pm.start_servers = 20
251行 pm.min_spare_servers = 5
256行 pm.max_spare_servers = 35
7、创建用户并启动
[root@localhost etc]# useradd -M -s /sbin/nologin php
[root@localhost etc]# /usr/local/sbin/php-fpm
8、进入nginx主配置文件
[root@localhost html]# vim /usr/local/nginx/conf/nginx.conf
添加一个location
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
在location也要加一个index.php
9、重启nginx
[root@localhost html]# systemctl restart nginx
10、编写测试文件
[root@localhost html]# vim /usr/local/nginx/html/php.php
<?php
phpinfo();
?>
客户端浏览http://192.168.2.222/php.php
连接MySQL
[root@localhost html]# vim /usr/local/nginx/html/mysql.php
<?php
$link=mysqli_connect('localhost','root','123456');
if($link) echo"<h1>大功告成</h1>";
mysqli_close();
?>
访问:http://192.168.2.222/mysql.php
四、部署电影网站
1、解压安装
[root@localhost ~]# unzip SKYUC.v3.4.2.SOURCE.zip
[root@localhost ~]# cd SKYUC.v3.4.2.SOURCE
[root@localhost SKYUC.v3.4.2.SOURCE]# rm -rf /usr/local/nginx/html/*
[root@localhost SKYUC.v3.4.2.SOURCE]# cp -rf wwwroot/ /usr/local/nginx/html/
[root@localhost SKYUC.v3.4.2.SOURCE]# cd /usr/local/nginx/html
2、添加属主属组
[root@localhost html]#cd wwwroot
[root@localhost wwwroot]# chown -R php:php admincp/ data/ templates/ upload/
3、创建数据库和授权用户
[root@localhost html]# mysql -u root -p123456
mysql> create database skyuc;
mysql> grant all on skyuc.* to skyuc@localhost identified by '123';
mysql> flush privileges;
4、访问
http://192.168.2.222/wwwroot/index.php
配置完成删除/usr/local/nginx/html/wwwroot/目录下的install目录,防止下次登录清除网站界面信息
登陆后台入口
客户端访问页面