Home > Backend Development > PHP Problem > How to compile and install php5.6 php-fpm

How to compile and install php5.6 php-fpm

藏色散人
Release: 2023-03-14 14:18:01
Original
3316 people have browsed it

php5.6 php-fpm compilation and installation method: 1. Install the php dependency package and download the php5.6.36 version; 2. Specify the software installation directory as "/usr/local/php"; 3. Perform nginx Just configure and parse php.

How to compile and install php5.6 php-fpm

The operating environment of this article: ubuntu16.04 system, php5.6.36 version, Dell G3 computer.

php5.6 php-fpm nginx installation and configuration

Today I found a website based on the php version, and then I went online to collect information and installed it again. try.
1. First install the php dependency package.

yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers gd gd2 gd-devel gd2-devel perl-CPAN pcre-devel
Copy after login

2. Download the php5.6.36 version

http://php.net/get/php-5.6.36.tar.gz/from/a/mirror
Copy after login

php-fpm component description

nginx in the LNMP environment does not support php, you need Process PHP requests through the fastcgi plug-in. PHP requires the php-fpm component to provide this function. In versions before php5.3.3, php-fpm existed in the form of a patch package. After php5.3.3, you only need to use --enable-fpm to load the module during compilation and installation, without installing it separately.

3. Install php

First create the directory where php needs to be installed

cd /etc/
mkdir php
cd /usr/local/
mkdir php
tar -xzvf php-5.6.36.tar.gz
cd php-5.6.36
Copy after login

In the following configuration, specify the software installation directory as /usr/local/php , the configuration file installation directory is

/etc/php
./configure --prefix=/usr/local/php --with-config-file-path=/etc/php --enable-fpm --enable-pcntl --enable-mysqlnd --enable-opcache --enable-sockets --enable-sysvmsg --enable-sysvsem  --enable-sysvshm --enable-shmop --enable-zip --enable-ftp --enable-soap --enable-xml --enable-mbstring --disable-rpath --disable-debug --disable-fileinfo --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pcre-regex --with-iconv --with-zlib --with-gd --with-openssl --with-mhash --with-xmlrpc --with-curl --with-imap-ssl


Thank you for using PHP.
config.status: creating php5.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/fpm/php-fpm.conf
config.status: creating sapi/fpm/init.d.php-fpm
config.status: creating sapi/fpm/php-fpm.service
config.status: creating sapi/fpm/php-fpm.8
config.status: creating sapi/fpm/status.html
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands


[root@localhost php-5.6.36]# make
[root@localhost php-5.6.36]# make install
Copy after login

View the contents of the software installation directory

[root@localhost php-5.6.30]# ls /usr/local/php
bin  etc  include  lib  php  sbin  var
Copy after login

Copy the configuration file template to the configuration file directory

[root@localhost php-5.6.30]# cp php.ini-development /etc/php/php.ini
Copy after login

Create a soft connection

[root@localhost ~]# ln -s /usr/local/php/bin/php /usr/bin/php
[root@localhost ~]# ln -s /usr/local/php/bin/phpize /usr/bin/phpize
[root@localhost ~]# ln -s /usr/local/php/sbin/php-fpm /usr/bin/php-fpm
Copy after login

Check the installed version

[root@localhost ~]# /usr/local/php/bin/php --version
[root@localhost ~]# cd /usr/local/php/etc/
[root@localhost ~]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@localhost ~]# ln -s /usr/local/php/etc/php-fpm.conf /etc/php/php-fpm.conf #添加软连接到 /etc/php目录
[root@localhost ~]# vim /usr/local/php/etc/php-fpm.conf
pid = run/php-fpm.pid #取消前面的分号
[root@localhost ~]# cp 源码目录/php-5.6.36/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm #拷贝php-fpm到启动目录
 
[root@localhost ~]# chmod +x /etc/rc.d/init.d/php-fpm #添加执行权限
 
[root@localhost ~]# chkconfig php-fpm on #设置开机启动
Copy after login

Check whether the port is occupied

[root@localhost ~]# netstat -tunlp |grep 9000
Copy after login

Start the service

[root@localhost ~]# cd /etc/rc.d/init.d/
[root@localhost ~]# ./php-fpm start
[root@localhost ~]# netstat -tunlp |grep 9000
[root@localhost ~]# ps -ef|grep fpm
Copy after login

Four , nginx configuration parsing php

1. Enter the nginx directory

[root@localhost ~]# cd /usr/local/nginx/conf
Copy after login

2. Edit the configuration file

[root@localhost ~]# vim nginx.conf
Copy after login

and find it under server

location / {
    root html;
    index index.html index.htm 
index.php
;    #加上index.php,让nginx服务器默认支持index.php为首页
}
Copy after login

Configure below. The php request is sent to the back-end php-fpm module. By default, the php configuration block is commented. At this time, remove the comment and modify it to the following content:

       location ~ \.php$ {
            root /usr/local/nginx/html;   #修改html路径
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
       fastcgi_param SCRIPT_FILENAME 
$document_root
$fastcgi_script_name;   #这里原来是/scripts,需要改成$document_root
            include fastcgi_params;
        }
Copy after login

Reload nginx after saving

[root@localhost ~]# /usr/local/nginx/nginx -s t
[root@localhost ~]# /usr/local/nginx/nginx -s reload
http://192.168.1.11/index.php
Copy after login



5. Related queries
1. Use the command to check how many php-cgi processes are opened on the server

 ps -fe |grep "php-fpm"|grep "pool"|wc -l
Copy after login

2. Check how many php-cgi processes are used to handle tcp requests

  netstat -anp|grep "php-fpm"|grep "tcp"|grep "pool"|wc -l
Copy after login

3. In the linux nginx php environment, each php-fpm process Memory limit

Setting method:

Edit the php-fpm.conf configuration file
php_admin_value[memory_limit] = 128M (the configuration file on my server is in /etc/php5/fpm/pool .d/www.conf This file is included in php-fpm.conf) The following numbers can be changed at will: 32M, 64M, 128M, 256M, 512M. This setting can be based on the memory size of your server and your needs. To write, you need to load the php-fpm service after modification

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to compile and install php5.6 php-fpm. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template