1.首先,升级软件包
sudo apt-get update
sudo apt-get upgrade
2.安装nginx
sudo apt-get install nginx
在浏览器输入服务器ip测试nginx是否安装成功
3.安装数据库
sudo apt-get install mysql-server php5-mysql
输入mysql -u root -p 测试数据库是否安装成功
4.安装php-fpm
PHP-FPM是一个PHPFastCGI管理器,是只用于PHP的。使用PHP-FPM来控制PHP-CGI的FastCGI进程
sudo apt-get install php5-fpm
(1)配置php-fpm
sudo vi /etc/php5/fpm/php.ini
将 cgi.fix_pathinfo=1 改为 cgi.fix_pathinfo=0
(2)sudo service php5-fpm restart
5.解决nginx打开php文件总是显示下载框的问题
sudo vi /etc/nginx/sites-available/default
将
location ~ .php$ {
# fastcgi_split_path_info ^(.+.php)(/.+)$;
# # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
#
# # With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php5-fpm:
# fastcgi_pass unix:/var/run/php5-fpm.sock;
# fastcgi_index index.php;
# include fastcgi_params;
}
改为
location ~ .php$ {
fastcgi_split_path_info ^(.+.php)(/.+)$;
# # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
#
# # With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
最后,记得重启nginx服务器!
sudo service nginx restart
6.测试nginx是否解析PHP
cd /usr/share/nginx/html
vim index.php
输入
<?php phpinfo();
保存退出
在浏览器访问 http://服务器ip/index.php