系统环境:
Ubuntu 16.04.2 LTS
nginx version: nginx/1.10.3 (Ubuntu)
PHP 7.0.22-0ubuntu0.16.04.1
mysql Ver 14.14 Distrib 5.7.20
一、环境准备:
检测网络环境
ping -c2 baidu.com
更新apt源
sudo apt update
二、安装Nginx
1.安装Nginx
sudo apt-get install nginx -y
2.编辑配置nginx文件
sudo vim /etc/nginx/sites-available/default
#index行添加index.php
index index.php index.html index.htm index.nginx-debian.html;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
# With php7.0-cgi alone:
#fastcgi_pass 127.0.0.1:9000;
# With php7.0-fpm:
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
三、安装php7.0
1.安装php php-fpm
$sudo apt-get install php7.0 php7.0-fpm -y
2.编辑配置文件php.ini,找到 cgi.fix_pathinfo=0,将值改为1
$sudo vim /etc/php/7.0/fpm/php.ini
760 cgi.fix_pathinfo=0
3.重启服务
$sudo systemctl restart nginx php7.0-fpm
四、安装mysql
$sudo apt install mysql-server mysql-client libmysqld-dev -y
根据提示输入root用户密码
$sudo apt install -y php7.0-mysql
五、验证
$echo "<?php phpinfo();?>" > /var/www/html/index.php
浏览器访问http://localhost