Detailed Introduction Linux installation PHP environment and configuration Nginx Support PHP-FPM module (graphics)

Source: Internet
Author: User
Tags install openssl phpinfo nginx server
This article mainly introduces the detailed http://www.php.cn/wiki/1497.html "target=" _blank ">linux Install PHP environment and configure Nginx support PHP-FPM module, with a certain reference value, Interested in the small partners can refer to.

The following CentOS 7.2 For example, install PHP operating environment, first open the PHP official dot click the navigation bar downloads into the download page here to download the latest version of the PHP 7.0.5 source package:

  

Upload to server after download

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-7.0.5.TAR.GZCD php-7.0.5

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-develyum-y install bzip2yum-y I Nstall Bzip2-devel

These packages are basically sufficient, and if the problem is found to be replenished, after the installation is complete, the configuration is performed:

The code is as follows:

./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/lib/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/lib/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

Also note that one place is the location of the php.ini configuration file can be set in pre-compilation configuration parameters, compile parameters can be written as:--with-config-file-path=/usr/local/php In this case, PHP will go back to the specified directory to read the php.ini configuration file, if not add the default location is the PHP installation directory of the Lib directory, can also be viewed in the phpinfo () output interface, If PHP.ini is placed in another location, PHP cannot read it, then all configuration changes are not effective, this should be noted

At this point you should create a Web user first:

Groupadd www-datauseradd-g Www-data Www-data

Then online some tutorials say let modify php-fpm.conf add the above created users and groups, at this time use vim/usr/local/etc/php-fpm.conf open the file after the official prompt location is not found:

  

If you add in a location at this point, then the next time you start PHP-FPM, you will report the directory can not find errors, so do not add users and groups in php-fpm.conf, this time to php-fpm.conf the last line will find the following ( If you add the--prefix option at compile time the following location will be automatically complete, the default is the following is empty, pay attention to):

  

All the Conf configuration files in the PHP-FPM.D directory are introduced here, but none needs to be modified to our actual directory:/usr/local

  

By default, etc/php-fpm.d/has a configuration user file named Www.conf.defalut, which executes the following command to copy a new file and open:

cp/usr/local/etc/php-fpm.d/www.conf.default/usr/local/etc/php-fpm.d/www.confvim/usr/local/etc/php-fpm.d/ Www.conf

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 port 9000 by default, using Netstat-tln | GREP 9000 can view port usage:

  

9000 port normal use, indicating PHP-FPM service started successfully

Then execute the 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 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:

/usr/local/nginx/nginx-s Stop/usr/local/nginx/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:

Related articles:

Mac defaults to your own installed PHP

centos6.7 Installation PHP7 Detailed introduction

Detailed description of the sample code for CENTOS7 compiling and installing PHP7 (figure)

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.