您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Linux下安装php,并配置到nginx

2025/6/17 18:24:34发布14次查看
1、 下载
        libxml2-2.6.32.tar.gz  http://download.csdn.net/detail/netlong339/1351852
        php-5.3.16.tar.gz      http://download.csdn.net/detail/aiyunbreak/5366061
2、建立目标文件夹
    mkdir /usr/local/php
    也就是说等下安装的php要安装到这个文件夹里面
3、解压:
将下载好的文件放在服务器上的某个位置:比如/root/xiebin
①先安装libxml,解压libxml2-2.6.32.tar.gz,
tar -zxvf libxml2-2.6.32.tar.gz
cd /root/xiebin/libxml2-2.6.32
执行: ./configure
执行:make  
执行:make install
②在安装php,解压tar -zxvf php-5.3.16.tar.gz
cd /root/xiebin/php-5.3.16
执行:./configure --prefix=/usr/local/php --with-libxml-dir=/usr/local/libxml2 --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-libevent-dir=libevent
这里超级重要,php5.3以后支持php-fpm启动,如果这里没有配置好,就会导致后面无法启动php【apache作为服务器的话,无所谓,但我们现在是nginx】
./configure --prefix=/usr/local/php --with-libxml-dir=/usr/local/libxml2 --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-libevent-dir=libevent
执行:make  
执行:make install
4、配置文件
①ini文件:将安装文件中的php.ini-development拷贝到/usr/local/php/lib下
    cp /root/xiebin/php-5.3.16/php.ini-development  /usr/local/php/lib
将文件重命名成php.ini;我用的工具是winscp,可以直接f2重命名,所以我一般先是拷贝,在f2命名
直接cp的时候被提示not find 这样的
②php-fpm文件:php自5.3以后将php-fpm集成过来了,这个很重要!!!下面需要启动php的时候用到。
将php-fpm.conf.default重命名成php-fpm.conf,即去掉.default
修改php-fpm中的配置:122行  将www换成root
                                           140行   user=root  
                                           group=root
5、启动php:实际上是启动php-fpm
   /usr/local/php/etc/php-fpm
这里你会遇到一个问题:please specify user and group other than root
                     fpm initialzation failed
   报错了,提示运行php-fpm运行用户和组只能选择其它的除了root以外.
   于是查看php-fpm文档,会发现其中一个选项:-r
所以正确的启动应该是:/usr/local/php/etc/php-fpm -r
/usr/local/php/etc/php-fpm -r
查看是否启动成功:
netstat -lnt | grep 9000
netstat -lnt | grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* listen
或者使用如下命令,查看是否9000端口被php-fpm占用:
netstat -tunpl | grep 9000
tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   listen      2124/php-fpm
5、nginx配置
  在nginx的配置文件中加一段
  # pass the php scripts to fastcgi server listening on 127.0.0.1:9000
location ~ \.php$ {
root           /www/web/;
fastcgi_pass   127.0.0.1:9000;
fastcgi_index  index.php;
#fastcgi_param  script_filename  /scripts$fastcgi_script_name;
fastcgi_param  script_filename  /www/web/$fastcgi_script_name;
include        fastcgi_params;
}
# pass the php scripts to fastcgi server listening on 127.0.0.1:9000 location ~ \.php$ { root /www/web/; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; #fastcgi_param script_filename /scripts$fastcgi_script_name; fastcgi_param script_filename /www/web/$fastcgi_script_name; include fastcgi_params; }
ps:如何找到nginx的位置:#whereis nginx.conf
                        再送一个命令:找到文件which nginx  可执行文件名称 
   配置好了后,再次在家nginx,执行:/usr/sbin/nginx -s reload
/usr/sbin/nginx -s reload
写个测试页面
以上就介绍了linux下安装php,并配置到nginx,包括了方面的内容,希望对php教程有兴趣的朋友有所帮助。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product