一、安装nginx和php7.2
sudo apt-get install nginx
sudo apt-get install php7.2-fpm
安装nautilus(可选)
是一款图形化的文件夹资源管理器
sudo apt-get install naultius
二、配置php7.2
找到/etc/php/7.2/fpm/pool.d/www.conf文件,找到这一句
listen = /run/php/php7.2-fpm.sock
把这个文件地址记录下来,第4步需要用到。
三、配置nginx
使用sudo nautilus打开资源管理器,找到/etc/nginx/sites-available/default文件,进行编辑,
1)去掉sock位置的#
2)增加一句include fastcgi_params;
3)更改默认的fastcgi_pass的位置,填写步骤3的内容
# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
}
4)如果没有指定网站目录位置,网站默认是在/var/www/html下,指定网站目录位置
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /home/www; <-----此处设置网站目录位置
四、修改权限
简单的修改了一下访问权限(非安全)
chmod 777 /run/php/php7.2-fpm.sock
五、重启服务
sudo service php7.2-fpm restart
六、配置扩展
让PHP支持sqlite3、pgsql等
sudo apt-get install php7.2-sqlite3 php7.2-pgsql
安装之后,在/usr/lib/php/20170718/目录下面会多出来sqlite3.so和pgsql.so文件