Because the PHP installation needs to be compiled, the server should ensure that the GCC and g++ environments are installed
First release the installation package:
Tar-xvzf PHP-5.6.27.TAR.GZCD php-5.6.27
The next parameter configuration, if there is no libxml2 and Libxml2-devel error before configuration, so should update libxml2 and install Libxml2-devel, using online installation:
Yum-y Install libxml2yum-y Install Libxml2-devel
Supplement, because of different operating system environment, the system installs the development environment package is not the same degree of completeness, so it is recommended to install the operating system to do the necessary choice, you can also uniformly execute all the commands, install the components that are not installed, if the installation may be upgraded, the version is fully consistent will not do anything , the command is summarized as follows in addition to the 2 above:
Yum-y Install opensslyum-y Install openssl-develyum-y install curlyum-y install curl-develyum-y install libjpegyum-y Install libjpeg-develyum-y install libpngyum-y install libpng-develyum-y install freetypeyum-y install Freetype-devel Yum-y Install pcreyum-y Install pcre-develyum-y install libxsltyum-y install Libxslt-devel
These packages are basically sufficient, and if the problem is found to be replenished, after the installation is complete, the configuration is performed:
./configure--prefix=/usr/local/php--with-curl--with-freetype-dir--with-gd--with-gettext--with-iconv-dir-- With-kerberos--with-libdir=lib64--with-libxml-dir--with-mysqli--with-openssl--with-pcre-regex--with-pdo-mysql- -with-pdo-sqlite--with-pear--with-png-dir--with-jpeg-dir--with-xmlrpc--with-xsl--with-zlib--with-bz2-- With-mhash--enable-fpm--enable-bcmath--enable-libxml--enable-inline-optimization--enable-gd-native-ttf-- Enable-mbregex--enable-mbstring--enable-opcache--enable-pcntl--enable-shmop--enable-soap--enable-sockets-- Enable-sysvsem--enable-sysvshm--enable-xml--enable-zip
In fact, there are more configuration items here than the above, you can use the ./configure--help command to see all the options, note that in PHP7--with-mysql native support no longer exists and the operation becomes mysqli or PDO. The above options are fully sufficient in normal PHP development, and can be selected manually to open the appropriate module if needed later .
Then perform the compilation:
Make
The compilation time may be a bit long and after the compilation is complete, the installation is performed:
Make install
The default installation location for PHP is already specified as/usr/local/php, and the appropriate files are then configured:
CP php.ini-development/usr/local/php/php.inicp/usr/local/php/etc/php-fpm.conf.default/usr/local/php/etc/ PHP-FPM.CONFCP Sapi/fpm/php-fpm/usr/local/bin
Then set php.ini, use: Vim/usr/local/php/php.ini open PHP configuration file to find Cgi.fix_pathinfo configuration items, this item is commented by default and the value is 1, according to the official documentation, here in order to when the file does not exist , which prevents Nginx from sending the request to the backend's PHP-FPM module, thus avoiding the attack of a malicious script injection, so this item should be stripped of the comment and set to 0
Save and exit after Setup
At this point you should create a Web user first:
Groupadd www-datauseradd-g Www-data Www-data
Use vim/usr/local/php/etc/php-fpm.conf at this time
The default user and group settings are nobody, which is changed to Www-data
After the modification is complete, save and exit, and then execute the following command to start the PHP-FPM service:
/usr/local/bin/php-fpm
After the boot is complete, the PHP-FPM service uses 9000 ports by default, using netstat-tln | grep 9000 to view port usage:
9000 port normal use, indicating PHP-FPM service started successfully
Then execute vim/usr/local/nginx/nginx.conf edit nginx configuration file, the specific path according to the actual nginx.conf configuration file location editing, the following major changes in the Nginx server {} configuration block content, Modify the location block, append index.php let Nginx server default support index.php home page:
Then configure the. PHP request to be routed to the backend PHP-FPM module, where the PHP configuration block is annotated by default, and the comment is removed and modified to the following:
Many of these are default, root is the configuration of PHP program placement root directory, the main modification is fastcgi_param in the/scripts for $document_root
Modify the above, go back to the first line nginx.conf, the default is #user nobody; This is to remove the comment to user www-data, or user Www-data Www-data, which indicates that the permissions of the Nginx server are Www-data
Modify these save and exit, and then restart Nginx:
Next edit a test PHP program, in the Nginx under the HTML directory to create the test.php file, print the PHP configuration:
<?php phpinfo ();? >
Then open the browser to enter the corresponding address to access, see the output page, stating that Nginx and PHP are configured successfully:
Install PHP environment under Linux and configure Nginx support PHP-FPM module