1. 安装

我是懒人,不习惯make/make install, 直接用aptitude安装了

$ sudo aptitude install nginx

$ sudo aptitude install php

$ sudo aptitude install php-fpm

目前是直接安装了最新版的php7、php-fpm7

2. 配置

php-fpm默认不需要配置,并且安装好后自动就启动了,可以使用

ps -aux | grep fpm

查看有没有启动。

安装的位置是:

/usr/sbin/php-fpm7.0

不过和旧版本的使用 fastcgi://127.0.0.1:9000的网络接口相比,新版本使用了Unix域套接字(Unix domain socket),是在文件系统里的文件,php-fpm的unix域套接字是:

unix:/run/php/php7.0-fpm.sock

因此配置nginx.conf的时候,要使用这个。

Unix域套接字同样可以用netstat -apn | grep fpm查看。

重要的是配置nginx.conf

我的位置是在 /etc/nginx/nginx.conf

deepin安装的nginx.conf中,包含了配置/etc/nginx/sites-enabled/default,默认的配置文件其实在这,可以配置这个default文件。

sudo vim /etc/nginx/sites-enabled/default

在default中,默认包含了nginx的配置,所做的是取消井号#,修改一下就好了。

默认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.html index.htm index.nginx-debian.html;
server_name _; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; } # pass the PHP scripts to FastCGI server # listening on 127.0.0.1:9000 # #location ~ \.php$ { #include snippets/fastcgi-php.conf; # # # With php5-cgi alone: # fastcgi_pass 127.0.0.1:9000; # # With php5-fpm: #fastcgi_pass unix:/var/run/php5-fpm.sock; #} }

 

修改为:

server {
 listen 80 default_server;
 listen [::]:80 default_server;
# 这儿是你自定义的www根目录
 root /home/deepin/docs/wwwdir;
 # Add index.php to the list if you are using PHP
 index index.html index.htm index.nginx-debian.html index.php; #增加index.php

 server_name _;

 location / {
 # First attempt to serve request as file, then
 # as directory, then fall back to displaying a 404.
 try_files $uri $uri/ =404;
 }
 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#去掉下面两行井号
location ~ \.php$ {
include snippets/fastcgi-php.conf;
# # # With php5-cgi alone: # fastcgi_pass 127.0.0.1:9000; # # With php5-fpm: # 去掉下面这行井号,并修改为正确的unix套接字,可在shell中用sudo netstat -apn|grep php查看 fastcgi_pass unix:/run/php/php7.0-fpm.sock; #} }

 

3. 启动

/etc/init.d/php7.0-fpm restart

/etc/init.d/nginx restart

4. 测试

在配置的root目录下建一个index.php

内容是:

<?php phpinfo(); ?>

标签: none 阅读量: 1056

添加新评论