首先安装Nginx
1、更新源和安装Nginx
$ sudo apt-get update $ sudo apt-get install Nginx
2、安装Nginx完成后可查看版本号,输入
root@ubuntu:~# Nginx -v Nginx version: Nginx/1.12.1 (Ubuntu)
安装PHP5.6
1、添加PPA
$ sudo apt-get install python-software-properties software-properties-common $ sudo add-apt-repository ppa:ondrej/PHP $ sudo apt-get update
2、安装PHP5.6以及所需的一些扩展
$ sudo apt-get install PHP5.6-fpm PHP5.6-mysql PHP5.6-common PHP5.6-curl PHP5.6-cli PHP5.6-mcrypt PHP5.6-mbstring PHP5.6-dom
3、配置PHP5.6
vim /etc/PHP/5.6/fpm/pool.d/www.conf #增加用户和用户组 user = www-data group = www-data #去掉前面的分号 security.limit_extensions = .PHP .PHP3 .PHP4 .PHP5
安装MysqL
$ sudo apt-get install MysqL-server MysqL-client
$ MysqL -uroot -p
然后输入刚刚设置的密码,能成功进入即成功安装。
配置Nginx 中的PHP
新建一个文件夹 /etc/Nginx/vhost,同时建一个文件domain.conf
mkdir /etc/Nginx/vhost && touch /etc/Nginx/vhost/domain.conf
vim domain.conf server{ listen 80; server_name www.beixuan.com;#根据自己的域名配置 root /var/www/html/jishuge;#根据自己的根目录配置 location / { try_files $uri $uri/ /index.PHP?$query_string; index index.html index.htm index.PHP l.PHP; autoindex off; } location ~ \.PHP(.*)$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.PHP; fastcgi_split_path_info ^((?U).+\.PHP)(/?.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; include fastcgi_params; } access_log /var/www/html/jishuge/log/access.log;#配置访问日志 error_log /var/www/html/jishuge/log/error.log;#配置错误日志 }
include /etc/Nginx/vhost/*.conf;
问题处理:
#第一: listen = /run/PHP/PHP5.6-fpm.sock #修改成下面内容 listen =127.0.0.1:9000 #第二: security.limit_extensions = .PHP .PHP3 .PHP4 .PHP5 #去掉前面的分号
- Access denied.(访问被拒绝)
#找到cgi.fix_pathinfo选项,去掉注释;,然后将值设置为1: cgi.fix_pathinfo = 1;