欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

centos 7 源码编译安装php5.6.37步骤及连接nginx简述

程序员文章站 2022-05-17 18:39:41
...

获取并解压 PHP 源代码

wget http://cn2.php.net/distributions/php-5.6.37.tar.gz
tar zxf php-5.6.37.tar.gz
cd php-5.6.37

为了防止编译出错安装依赖包

yum -y install gcc gcc-c++ autoconf libjpeg-turbo-static libjpeg-turbo-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel pcre pcre-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5-libs krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss-pam-ldapd openldap-clients openldap-servers bison lrzsz libmcrypt libmcrypt-devel mcrypt mhash ImageMagick ImageMagick-devel libmemcached libmemcached-devel
  •  

然后编译

./configure --prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-bz2 \
--with-curl \
--enable-ftp \
--enable-sockets \
--disable-ipv6 \
--with-gd \
--with-jpeg-dir=/usr/local \
--with-png-dir=/usr/local \
--with-freetype-dir=/usr/local \
--enable-gd-native-ttf \
--with-iconv-dir=/usr/local \
--enable-mbstring \
--enable-calendar \
--with-gettext \
--with-ldap \
--with-libxml-dir=/usr/local \
--with-zlib \
--with-pdo-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-mysql=mysqlnd \
--enable-dom \
--enable-xml \
--enable-fpm \
--with-libdir=lib64 \
--enable-bcmath
--with-mysqli
  •  

安装

make &&  make install
  •  

修改配置文件

cp /root/php-5.6.37/php.ini-production /usr/local/php/etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
ln -s /usr/local/php/sbin/php-fpm /usr/local/sbin/php-fpm(创建php-fpm启动命令)
[aaa@qq.com etc]# cat php-fpm.conf
[global]
[www]
user = nginx(与nginx配置文件保持一致。我nginx中user是“nginx”)
group = nginx(同上)
listen = 127.0.0.1:9000
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
  •  

然后启动 php-fpm 服务

php-fpm
  •  

配置 Nginx 使其支持 PHP 应用 
修改默认的 location 块,使其支持 .php 文件:

location / {
    root   html;
    index  index.php index.html index.htm;
}
  •  

下一步配置来保证对于 .php 文件的请求将被传送到后端的 PHP-FPM 模块, 取消默认的 PHP 配置块的注释,并修改为下面的内容:

location ~ \.php$ {
    root           html;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
} 
  •  

重载nginx

\usr\local\nginx\sbin\nginx -s reload

 

创建PHP测试文件
打开浏览器,访问 相应IP地址,将会显示 phpinfo() 
centos 7 源码编译安装php5.6.37步骤及连接nginx简述
注: 
nginx+php运行原理 
nginx本身不能处理PHP,它只是个web服务器,当接收到请求后,如果是php请求,则发给php解释器处理,并把结果返回给客户端。 
nginx一般是把请求发fastcgi(php-fpm就是其中的一种)管理进程处理,fascgi管理进程选择cgi子进程处理结果并返回被nginx 
同样php-fpm程序也如同nginx一样,需要监听端口,并且有master和worker进程。worker进程直接管理每一个php进程