This article we mainly share with you how Linux installs PHP, this article in the form of graphics and pictures to share, I hope to help everyone.
1. Download the appropriate version from the PHP website
Because the PHP download page only a few recent versions, download the older version in the download page has not been found, can only be manually downloaded through the following URL,
HTTP://CN.PHP.NET/DISTRIBUTIONS/PHP-5.3.9.TAR.BZ2, this page will list some of the older versions, where the 5.3 version is used, the download is in GZ format
2. Install PHP
Unpack the tar package and go to the unpack directory-execute command:./configure--prefix=/opt/local/php, "/opt/local/php" is the installation path that can be changed to the installation path you want.
(1) Some of the necessary plugins may be missing here, which can be installed using the Yum command, such as the most likely error: Configure Xml2-config not found. Please check your LIBXML2 installation, execute command at this time: yum-y install LIBXML2 libxml2-devel, installation of the appropriate plug-in, etc.
After all plug-ins are installed, execute again
./configure--prefix=/opt/local/php
(2) If you want to install the PHP-FPM feature, you need yum to install more plugins, for example:
Yum-y install OpenSSL openssl-devel bzip2 bzip2-devel Curl curl-devel readline-devel fcgi php-mcrypt libmcrypt libmcrypt- Devel
where installation php-mcrypt Libmcrypt Libmcrypt-devel may be prompted to find the package, this time to be resolved through the update source, the specific command is as follows:
Yum-y Install Epel-release
Yum Update
Where update executes two times before it succeeds and then executes configure
./configure--prefix=/opt/local/php5.3.29--with-config-file-path=/etc--enable-inline-optimization-- Disable-debug--disable-rpath--enable-shared--enable-opcache--enable-fpm--with-fpm-user=www--with-fpm-group=www --with-mysql=mysqlnd--with-mysqli=mysqlnd--with-pdo-mysql=mysqlnd--with-gettext--enable-mbstring--with-iconv-- With-mcrypt--with-mhash--with-openssl--enable-bcmath--enable-soap--with-libxml-dir--enable-pcntl--enable-shmop --enable-sysvmsg--enable-sysvsem--enable-sysvshm--enable-sockets--with-curl--with-zlib--enable-zip--with-bz2-- With-readline--without-sqlite3--without-pdo-sqlite--with-pear
Execute make after passing
You may receive the following prompt
PEAR Package php_archive not installed:generated Phar would require PHP ' s Phar Extension be enabled.
This can be ignored, wait, and then install again in the PHP directory to do the make all install
If PHP-FPM is installed, you will also need to execute the following command to copy a configuration file from the Php/etc directory
CP Etc/php-fpm.conf.default etc/php-fpm.conf
Copy the Php/lib/php.ini to the/etc/
3. Initial installation of Phar
This can be done
wget Http://pear.php.net/go-pear.phar
Then execute
/opt/local/php/bin/php/opt/local/go-pear.phar
After the prompt, choose 1, select the Phar installation directory, and then go all the way to install
Finally make PHP soft chain, make PHP global available
Ln-s/opt/local/php/bin/php/usr/bin/php
4. Verification
Perform php-v and sbin/php-fpm-v to check the PHP version to verify that PHP is installed
5. Start PHP-FPM
INT, term immediately terminates
QUIT Smooth Termination
USR1 Reopen log file
USR2 smoothly overloads all worker processes and reloads the configuration and binary modules
Example:
PHP-FPM off:
Kill-int ' cat /opt/local/php/var/run/php-fpm.pid'
PHP-FPM Restart:
KILL-USR2 ' cat /opt/local/php/var/run/php-fpm.pid'
If you cannot find the php-fpm.pid file, you can restart and close by looking for the PHP-FPM process number
For example
[Root@sh-dev local]# Ps-aux|grep PHP-FPM
Root 141735 0.0 0.0 201840 3892?
Ss 16:27 0:00 php-fpm:master process (/opt/local/php5.3.29/etc/php-fpm.conf)
KILL-USR2 141735
6. Modify the PHP-FPM configuration
(1) If you use Fastcgi_pass unix:/tmp/php-cgi.sock in nginx.conf, you need to modify php-fpm.conf to find the following code snippet:
; The address on which to accept FastCGI requests.
; Valid syntaxes is:
; ' Ip.add.re.ss:port '-to listen in a TCP socket to a specific address on
; a specific port;
; ' Port '-to listen in a TCP socket to all addresses on a
; Specific port;
; '/path/to/unix/socket '-to listen on a UNIX socket.
; Note:this value is mandatory.
; listen = 127.0.0.1:9000
Listen =/tmp/php-cgi.sock
; Set Listen (2) backlog. A value of '-1 ' means unlimited.
; Default value:128 ( -1 on FreeBSD and OpenBSD)
; listen.backlog = 1
; Set Permissions for UNIX sockets, if one is used. In Linux, Read/write
; Permissions must is set in order to allow connections from a Web server. Many
; Bsd-derived systems allow connections regardless of permissions.
; Default Values:user and group are set as the running user
; Mode is set to 0660
Listen.owner = Nobody
Listen.group = Nobody
Listen.mode = 0660
the original listen andListen.owner,Listen.groupparagraph is modified as above, whereListen.owner,Listen.group for Nginx start user name, so do not modify, will prompt
Nginx error Connect to Php-fpm.sock failed (13:permission denied)
Of course, if you put sock in memory,/dev/shm/php-fpm.sock will be faster.
(2) Modify the number of PHP-FPM threads
; Per Pool Prefix
; It only applies on the following directives:
; -' Slowlog '
; -' Listen ' (unixsocket)
; -' chroot '
; -' chdir '
; -' php_values '
; -' php_admin_values '
; Dynamic-the number of child processes is set dynamically based on the
; Following directives. With this process management, there'll be
; Always at least 1 children.
; Pm.max_children-the Maximum number of children that can
; Be alive at the same time.
; Pm.start_servers-the number of children created on startup.
; Pm.min_spare_servers-the minimum number of children in ' idle '
; State (waiting to process). If the number
; of ' idle ' processes is less than this
; Number then some children'll be created.
; Pm.max_spare_servers-the Maximum number of children in ' idle '
; State (waiting to process). If the number
; of ' idle ' processes is greater than this
; Number then some children'll be killed.
; Ondemand-no Children is created at startup. Children'll be forked when
; New requests would connect. The following parameter is used:
; Pm.max_children-the Maximum number of children that
; Can is alive at the same time.
; Pm.process_idle_timeout-the number of seconds after which
; An idle process would be killed.
; Note:this value is mandatory.
PM = dynamic
#如何控制子进程, the options are static and dynamic. If Static is selected, the number of fixed child processes is specified by Pm.max_children. If dynamic is selected, it is determined by the following parameters
; The number of child processes to being created when PM was set to ' static ' and the
; Maximum number of processes when PM was set to ' dynamic ' or ' OnDemand '.
; This value sets the limit on the number of simultaneous requests that would be
; Served. Equivalent to the apachemaxclients directive with Mpm_prefork.
; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP
; Cgi. The below defaults is based on a server without much resources. Don ' t
; Forget to tweak pm.* to fit your needs.
; note:used when PM was set to ' static ', ' dynamic ' or ' OnDemand '
; Note:this value is mandatory.
Pm.max_children = 8
#子进程最大数
; The number of child processes created on startup.
; Note:used only if PM is set to ' dynamic '
; Default value:min_spare_servers + (max_spare_servers-min_spare_servers)/2
Pm.start_servers = 8
#启动时的进程数
; The desired minimum number of idle server processes.
; Note:used only if PM is set to ' dynamic '
; Note:mandatory when PM was set to ' dynamic '
Pm.min_spare_servers = 1
#保证空闲进程数最小值, if the idle process is less than this value, a new child process is created
; The desired maximum number of idle server processes.
; Note:used only if PM is set to ' dynamic '
; Note:mandatory when PM was set to ' dynamic '
Pm.max_spare_servers = 8
#保证空闲进程数最大值, this is cleaned up if the idle process is larger than this value