环境准备:
centos7.3
添加EPEL软件源:
yum -y install http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-8.noarch.rpm
安装NGINX&PHP:
yum -y install nginx php php-fpm php-mysql php-curl php-gd php-intl php-pear php-imap php-mcrypt php-memcache php-pspell php-recode php-snmp php-tidy php-xmlrpc php-xsl
查看一下php版本:
php-fpm -v
&
nginx -v
根据需要是否将/etc/php.ini中的cgi.fix_pathinfo设置为0,默认1,据说是一个 NGINX文件类型错误解析漏洞,亦有保持默认的其它解决方案。大喵做为测试环境就保持默认了
注意关闭系统防火墙:
systemctl status firewalld.service
&
systemctl stop firewalld.service
&
systemctl disable firewalld.service
设置nginx和fastcgi的通信方式为unix socket方式:
编辑/etc/php-fpm.d/www.conf
;listen = 127.0.0.1:9000 ##注释掉 listen = /var/run/php-fpm/php-fpm.sock
去掉注释:
listen.owner = nobody listen.group = nobody
修改:
user = nginx group = nginx
添加nginx&php开机启动并启动php:
systemctl enable nginx systemctl enable php-fpm systemctl start php-fpm
建立一个NGINX虚拟主机:/etc/nginx/conf.d/
server { listen 80; ##虚拟主机用的端口 server_name xx.xx.xx.xx;#虚拟主机绑定的域名 root /var/www/html;#虚拟主机对应的站点资源目录 index index.php index.html index.htm;#虚拟主机默认的入口文件 location / {#请求根目录,默认的入口 try_files $uri $uri/ =404; } error_page 404 /404.html;#404错误页面 error_page 500 502 503 504 /50x.html;#5xxx错误文件 location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$ { try_files $uri =404; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
PS#注意下面图片的默认入口文件少了index.php请勿完全照抄图片
测试PHP:
安装mysql(Mariadb):
yum -y install mariadb-server systemctl enable mariadb-server systemctl start mariadb mysql_secure_installation
1、安装mariadb
2、添加sql开机启动
3、启动mysql
4、mysql初始化
GRANT ALL PRIVILEGES ON *.* TO '用户名'@'%' IDENTIFIED BY '密码' WITH GRANT OPTION;
#设置用户远程登陆