先添加ppa
sudo apt-add-repository ppa:ondrej/php
安装php
sudo apt install php7.0
安装各种包
sudo apt-get install php7.0-fpm php7.0-mysql php7.0-common php7.0-curl php7.0-cli php7.0-mcrypt php7.0-mbstring php7.0-dom php7.0-dev libpcre32-3
打开php.ini配置文件:
sudo vim /etc/php/7.0/fpm/php.ini
找到cgi.fix_pathinfo
选项,去掉注释;,然后将值设置为0:
cgi.fix_pathinfo = 0;
修改nginx配置
sudo vim /etc/nginx/sites-available/default
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
location = /50x.html {
root /var/www/html;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
之后重启nginx加载配置文件
创建/var/www/html/info.php
#/var/www/html/info.php
<?php
phpinfo();
?>
host访问localhost:8080
得到