Lnmp Installing PHP

Source: Internet
Author: User
Tags apache php fpm sapi

Here to declare, for nginx PHP installation and for Apache PHP installation is different, because
For Nginx in the PHP is a fastcgi way to combine Nginx. Can be understood as Nginx proxy php fastcgi,
and Apache is calling PHP as its own module. Similarly, Amin recommends that you use version 5.4. PHP Officer
Party: http://www.php.net/downloads.php. The installation process is as follows:
(1) Download PHP source package
#cd/USR/LOCAL/SRC
#wget http://au1.php.net/distributions/php-5.4.44.tar.bz2
(2) Unzip the source package, create an account
#tar JXF php-5.4.44.tar.bz2
#useradd-S/sbin/nologin php-fpm
This account is used to run the PHP-FPM service, and in the LNMP Environment, PHP serves as a service.
Install some dependency packages in advance, and avoid compilation errors as little as possible
Yum install-y libjpeg-devel libxml2-devel OpenSSL openssl-devel bzip2 bzip2-devel libpng libpng-devel freetype freetype-d Evel Epel-release Libmcrypt Libcurl-devel
Yum Install-y libmcrypt-devel
(3) Configuring compilation options
./configure \
--prefix=/usr/local/php \
--WITH-CONFIG-FILE-PATH=/USR/LOCAL/PHP/ETC \
--ENABLE-FPM \
--WITH-FPM-USER=PHP-FPM \
--WITH-FPM-GROUP=PHP-FPM \
--with-mysql=/usr/local/mysql \
--with-mysql-sock=/tmp/mysql.sock \
--with-libxml-dir \
--WITH-GD \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-iconv-dir \
--with-zlib-dir \
--with-mcrypt \
--ENABLE-SOAP \
--ENABLE-GD-NATIVE-TTF \
--ENABLE-FTP \
--enable-mbstring \
--ENABLE-EXIF \
--enable-zend-multibyte \
--disable-ipv6 \
--with-pear \
--with-curl \
--with-openssl
Error message:
Configure:error:Please Reinstall the Libcurl distribution-
Easy.h should is in <curl-dir>/include/curl/
Workaround:
#yum install-y Libcurl-devel
(4) Compiling PHP
#make
In this step, you will usually encounter some errors, no relationship, and encountering errors is good, so that you can increase your handling
Experience of the problem. I also encountered an error:
/usr/bin/ld:cannot Find-lltdl
Collect2:ld returned 1 exit status
Make: * * [SAPI/FPM/PHP-FPM] Error 1
That's how I solved it:
#yum install-y Libtool-ltdl-devel
(5) Installing PHP
#make Install
Each of the above steps, if not fully executed correctly, then the next step is not possible, whether you still remember the sentence
Is the correct way to execute the fault? Use echo $? See if the result is "0", if not, it is not executed correctly.
(6) Modify the configuration file
#cp Php.ini-production/usr/local/php/etc/php.ini
#vim/usr/local/php/etc/php-fpm.conf
Write the following to the file:
[Global]
PID =/usr/local/php/var/run/php-fpm.pid
Error_log =/usr/local/php/var/log/php-fpm.log
[WWW]
Listen =/tmp/php-fcgi.sock
user = PHP-FPM
Group = PHP-FPM
PM = dynamic
Pm.max_children = 50
Pm.start_servers = 20
Pm.min_spare_servers = 5
Pm.max_spare_servers = 35
Pm.max_requests = 500
Rlimit_files = 1024
Listen.owner = Nobody
Listen.group = Nobody
#slowlog =/tmp/www_slow.log
#request_slowlog_timeout = 5
#php_admin_value [open_basedir]=/data/www/:/tmp/

Description
The global section is the universal configuration, specifying the PID file path and the Error_log path.
[www] is a pool, we can actually write a second pool, the second pool and the first different
Place, first the name of the pool, for example called [WWW2]. Then listen must not be the same, such as can listen
=/tmp/php-fcgi2.sock. User,group can also be different from what is defined in [www]. Listen.owner this is
Defines who the owner of this file is, and/tmp/php-fcgi.sock the socket file permissions after the php5.4 version
The RW-------is programmed by default, and if you do not define Listen.owner then Nginx calls this socket without permission
, so here we define Listen.owner for Nginx listener user.
PM = dynamic means to start dynamically, and after the php5.3 version it can support both dynamic and static,
If it is static, that is pm=static, the following configuration is only Pm.max_children.
The pm.max_children represents a child process that initiates several php-fpm. If it is dynamic, the following configuration will take effect,
Pm.max_children indicates that a maximum number of child processes can be started.
Pm.start_servers indicates that several child processes are started at the beginning.
Pm.min_spare_servers indicates that there are at least a few child processes when PHP-FPM is idle, that is, if the idle process is small
To this value, a new child process is created. Pm.max_spare_server indicates that there are at most a few child processes when PHP-FPM is idle,
That is, if the idle process is larger than this value, cleanup occurs.
Pm.max_requests represents the maximum number of requests a child process can accept, such as setting to 500.
The child process automatically destroys after accepting 500 requests.
Rlimit_files represents how many file handles are opened by each child process.

After you save the configuration file, verify that the configuration is correct by:
#/usr/local/php/sbin/php-fpm-t

If the word "test is successful" appears, the configuration is not a problem, otherwise you will need to check the
If there is a problem with the file.
(7) Start PHP-FPM
The first thing to do is to copy a startup script to/etc/init.d/.
#cp/USR/LOCAL/SRC/PHP-5.3.27/SAPI/FPM/INIT.D.PHP-FPM/ETC/INIT.D/PHP-FPM
Give it a change permission of 755
#chmod 755/ETC/INIT.D/PHP-FPM
#service php-fpm Start
If you want it to boot, execute:
#chkconfig PHP-FPM on
Detect whether to start:
#ps aux |grep php-fpm
See if there are a lot of processes (about 20 or more).

Lnmp Installing PHP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.