nginx运行php需要安装哪些,nginx的安装及配置支持PHP运行笔记

本文档记录了在Linux环境下安装Nginx和配置PHP-FPM的过程。首先,通过./configure命令安装Nginx,然后在80端口被占用的情况下,将Nginx配置为监听8000端口。接着,由于需要支持PHP,需要重新编译PHP以启用fastcgi,并解决libltdl.so库找不到的问题。最后,配置Nginx以使用fastcgi_pass连接到php-fpm,并成功运行PHP文件。
摘要由CSDN通过智能技术生成

1、软件在外链网址已屏蔽下载

2、安装方法及参数说明在外链网址已屏蔽,文档说明外链网址已屏蔽(有关nginx的详细说明都在这里了)

3、开始安装,这里我们选择的默认的安装(未加任何的选项)。

[jhj@localhost nginx-1.6.0]$ ./configure

执行上述命令后,会在最后给出一些默认的配置信息,包括安装位置等一些信息,如下:

Configuration summary

+ using system PCRE library

+ OpenSSL library is not used

+ md5: using system crypto library

+ sha1: using system crypto library

+ using system zlib library

nginx path prefix: "/usr/local/nginx"

nginx binary file: "/usr/local/nginx/sbin/nginx"

nginx configuration prefix: "/usr/local/nginx/conf"

nginx configuration file: "/usr/local/nginx/conf/nginx.conf"

nginx pid file: "/usr/local/nginx/logs/nginx.pid"

nginx error log file: "/usr/local/nginx/logs/error.log"

nginx http access log file: "/usr/local/nginx/logs/access.log"

nginx http client request body temporary files: "client_body_temp"

nginx http proxy temporary files: "proxy_temp"

nginx http fastcgi temporary files: "fastcgi_temp"

nginx http uwsgi temporary files: "uwsgi_temp"

nginx http scgi temporary files: "scgi_temp"

好了,试着make && make install一下吧

[root@localhost nginx-1.6.0]# make && make install

安装好了,我们试着启动一下吧

[root@localhost nginx]# ./sbin/nginx

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] still could not bind()

怎么回事?这么多failed。这里应该是80端口被占用了,因为机子里面有apache在运行着。好吧,我们换一个

试着改一下配置文件

[root@localhost nginx]# vi ./conf/nginx.conf

server {

listen       8000;       #改为8000总可以了吧

server_name  localhost;

#这里已经省略了一些内容

}

重新启动了下,可以了。

[root@localhost nginx]# ps aux | grep nginx

root      4622  0.0  0.0   5292   552 ?        Ss   05:15   0:00 nginx: master process ./sbin/nginx

nobody    4623  0.0  0.0   5476   908 ?        S    05:15   0:00 nginx: worker process

root      4649  0.0  0.0   4356   720 pts/0    S+   05:19   0:00 grep nginx

在浏览器访问下外链网址已屏蔽,说明成功了(文件在nginx安装文件夹内的html/index.html)

Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer tonginx.org.

Commercial support is available at.

Thank you for using nginx.

4、好了静态html文件算是可以解析了,可是php的文件还没有可以解析,那么配置吧。

网上查了下资料发现要支持php要使用fastcgi模式,而之前在虚拟机安装php的时候没有安装支持fastcgi,这个东西貌似不重新编译又不行(行吗?)。

重新安装php(增加参数--enable-fpm)并支持fastcgi后,重新配置下nginx与php

(

题外:重新编译--enable-fpm的时候出现了/usr/bin/ld: cannot find -lltdl,解决方法如下(来源:外链网址已屏蔽):

查看/usr/lib库中是否存在,我这里发现是存在的

[root@localhost lib]# ll | grep libltdl

lrwxrwxrwx.  1 root root       16 May  2  2013 libltdl.so.7 -> libltdl.so.7.2.1

-rwxr-xr-x.  1 root root    36852 Aug 25  2010 libltdl.so.7.2.1

#关键在下边,这样设置后就可以过make了

[root@localhost lib]# ln -svf libltdl.so.7.2.1 libltdl.so

[root@localhost lib]# ll | grep libltdl

lrwxrwxrwx.  1 root root       16 May 27 06:50 libltdl.so -> libltdl.so.7.2.1

lrwxrwxrwx.  1 root root       16 May  2  2013 libltdl.so.7 -> libltdl.so.7.2.1

-rwxr-xr-x.  1 root root    36852 Aug 25  2010 libltdl.so.7.2.1

)

以默认配置启动php-fpm

[root@localhost sbin]# ./php-fpm

设置nginx

server {

#这里已经省略了一些内容

location ~ \.php$ {

root          /usr/local/nginx/html;

fastcgi_pass   127.0.0.1:9000;

fastcgi_index  index.php;

fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;

include        fastcgi_params;

}

}

重启nginx

[root@localhost conf]# ../sbin/nginx -s reload

html目录

[root@localhost html]# pwd;ll;cat t.php

/usr/local/nginx/html

total 12

-rw-r--r--. 1 root root 537 May 27 05:05 50x.html

-rw-r--r--. 1 root root 612 May 27 05:05 index.html

-rw-r--r--. 1 root root  16 May 27 05:23 t.php

echo 111;

打开浏览器外链网址已屏蔽

输出了111,成功了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值