nginx+php部署

时间:2023-03-09 03:14:42
nginx+php部署

(1) 下载并安装nginx

 mkdir nginx-src && cd nginx-src
wget http://nginx.org/download/nginx-1.7.3.tar.gz
tar xzf nginx-1.7.3.tar.gz
cd nginx-1.7.3
./configure --prefix=/home/cyw/tools/nginx/source
make
make install

其中,--prefix表示了安装的目录。就像在window中选择安装文件的路径一样。安装完成后,在source文件夹下可以看到如下的文件结构:

nginx+php部署

(2) 下载并安装php

wget http://cn2.php.net/distributions/php-5.4.7.tar.gz
tar zvxf php-5.4.7.tar.gz
cd php-5.4.7
./configure --prefix=/home/oduyub/tools/php/source --enable-fastcgi --enable-debug --enable-fpm
make
make install

make步骤要花费比较长的时间。安装完成后,可以在文件夹下面看到如下的文件夹列表。安装完成后,可以在source文件夹下看到如下的文件结构:

安装完成后,可以在source文件夹下看到如下的文件目录:

nginx+php部署

(3) 启动php服务

采用的是php-fpm的启动方式。

启动命令为:

> cd /sbin/

> ./php-fpm

启动后,执行

  ps -ef|grep php

可以看到输出如下:

nginx+php部署

(4) 启动nginx服务

启动之前需要先修改nginx.conf文件

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME html$fastcgi_script_name;
# include fastcgi_params;
#}

【注意】需要将上面的#去掉。

注意root行的html和fasstcgi_param中的/html需要对应。表明php寻找的路径

> cd /sbin/

>sudo ./nginx -s reload

输入 http://服务器地址:端口号/

如果能出现Nginx的首页,说明nginx安装成功

(5) 测试是否可以启动

写一个简单的php的测试文件index.php

<?php

  phpinfo()

>

在url中输入如下的链接: http://服务器地址:端口号/index.php。

如果出现php的统计网页,就表明可以在Php中执行指令了。  

(5) 错误列表