树莓派装nginx+php

修改软件源为阿里云的。。。

nano /etc/apt/sources.list
deb http://mirrors.aliyun.com/raspbian/raspbian/ jessie main non-free contrib
deb-src http://mirrors.aliyun.com/raspbian/raspbian/ jessie main non-free contrib

为什么用nano?我本来是想用vim的。。。但是没有vim。。。vi出了点奇奇怪怪的问题。。
来来来 先update一下

apt-get update
apt-get upgrade

没啥毛病
先装个vim!!

apt install vim

安装nginx

apt install nginx -y

看下启动没有

root@raspberrypi:~# netstat -ant
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN     
tcp        0    216 192.168.100.180:22      192.168.100.161:14882   ESTABLISHED
tcp        0      0 192.168.100.180:49540   222.218.84.180:80       TIME_WAIT  
tcp6       0      0 :*                    LISTEN     
tcp6       0      0 :*                    LISTEN 

唔 安装个php,这个装的是php5-fpm

apt-get install php5-fpm php5-mysql php5-cgi -y

安装完成。。。改一下nginx的配置文件

vim /etc/nginx/sites-available/default

主意 这里。。。可能和别人的有点不一样。。。因为。。我刚想了想直接把nginx和php删了。。用lnmp装。。。不过最后安装失败了。。。我就又uninstall了nginx。。。。至于为什么别的不删。。因为其他全都没有安装成功。。只有nginx安装成功了。。。

有几个地方要修改一下,

#location ~ \.php$ {
#    include snippets/fastcgi-php.conf;
#
#    # With php-fpm (or other unix sockets):
#    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
#    # With php-cgi (or other tcp sockets):
#    fastcgi_pass 127.0.0.1:9000;
#}

看好 这里是原来的,没修改前的,我从别的机器抄过来的。。。。我们把几个注释去掉,顺便改一下fastcgi_pass unix:的值
修改完成如下

location ~ \.php$ {
        include snippets/fastcgi-php.conf;
#       fastcgi_index index.php;
#       # With php5-cgi alone:
#       fastcgi_pass 127.0.0.1:9000;
#       # With php5-fpm:
        fastcgi_pass unix:/var/run/php5-fpm.sock;
}

这里我去掉了location的注释和include的注释还有fastcgi_pass unix:的注释并把值改成了/var/run/php5-fpm.sock;
千万不要搞错。。。。我在这出错了好久。。。。
最后。。创建一个文件

mkdir /home/wwwlogs
touch /home/wwwlogs/nginx_error.log

最后的最后 在default里的server最后一个"}"前加上启用错误日志,级别为debug

error_log    /home/wwwlogs/nginx_error.log    debug;

唔。。。到这里理论上说应该就没问题了。。。有问题可以联系我。。。虽然我也不一定能解决

Last modification:March 3rd, 2018 at 10:00 pm

Leave a Comment