Describes how to install the php environment in Linux and Configure Nginx to support the php-fpm module.

Source: Internet
Author: User
This article describes how to install the php environment in Linux and Configure Nginx to support the php-fpm module. it has some reference value. if you are interested, you can refer to it. This article mainly introduces the detailed description # wiki/1497.html "target =" _ blank "> installing the php environment in Linux and configuring Nginx to support the php-fpm module has some reference value, for more information, see.

The following uses CentOS 7.2 as an example to install the php runtime environment. first, open the php official website and click Downloads in the navigation bar to go to the download page. download the latest php 7.0.5 source code package:

  

Download the package and upload it to the server.

Because php installation requires compilation, the server should ensure the installation of gcc and g ++ environments.

First release the installation package:

tar -xvzf php-7.0.5.tar.gzcd php-7.0.5

Next configure the parameters, and errors are reported if libxml2 and libxml2-devel are not present before the configuration, so libxml2 should be updated and the libxml2-devel should be installed, using online installation:

yum -y install libxml2yum -y install libxml2-devel

In addition, because different operating system environments have different levels of system installation and development environment packages, we recommend that you make the necessary choices when installing the operating system, you can also run all the commands in a unified manner to install the components that are not installed. if they are already installed, they may be upgraded. if the versions are completely consistent, no operation will be performed, in addition to the preceding two commands, the command is summarized as follows:

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-develyum -y install pcreyum -y install pcre-develyum -y install libxsltyum -y install libxslt-develyum -y install bzip2yum -y install bzip2-devel

The above packages are basically enough. if any problem is found, add the package. after the installation is complete, execute the configuration:

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 above, which can be used. /configure -- help command to view all options. Note that in php7, the native support for "with-mysql" does not exist and the operations are changed to "mysqli" or "pdo; these options are sufficient in normal php Development. if you need them later, you can manually enable the corresponding module.

Then execute the compilation:

make

The compilation time may be a little long. after the compilation is complete, execute the installation:

make install

The default installation location of php has been specified as/usr/local/php. configure the corresponding file:

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: vim/usr/local/php/lib/php. ini open the php configuration file and find cgi. fix_pathinfo configuration item, which is commented out by default and has a value of 1, as described in the official documentation here to prevent Nginx from sending requests to the backend PHP-FPM module when the file does not exist, to avoid malicious script injection attacks, this option should be removed and set to 0.

  

Save the settings and exit.

Another note is php. the ini configuration file can be set in the configuration parameters before Compilation. the compilation parameters can be written as follows: -- with-config-file-path =/usr/local/php, php will go back to the specified directory to read php. ini configuration file. If this parameter is not added, the default location is the lib directory under the php installation directory. for details, see the phpinfo () output interface. if ini is placed in another location and php cannot read it, all configuration modifications will not take effect.

At this point, you should first create a web user:

groupadd www-datauseradd -g www-data www-data

Then some tutorials on the web asked the modify php-fpm.conf to add the user and group created above, at this time using vim/usr/local/etc/php-fpm.conf to open the file and cannot find the location officially prompted:

  

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

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

By default, the user and group are set to nobody and changed to www-data.

  

Many of them are default. root is the root directory where php programs are configured. The main change is/scripts in fastcgi_param is $ document_root.

After the preceding modification, return to nginx. the first line of conf is # user nobody by default. here, the comment should be removed and changed to user www-data; or the user www-data; indicates that the nginx server has the permission to www-data.

Save and exit after modification, and then restart nginx:

/usr/local/nginx/nginx -s stop/usr/local/nginx/nginx

Next, edit a test php program, create the test. php file in the html directory under nginx, and print the php configuration:

 

Open the browser and enter the corresponding address for access. the output page shows that nginx and php are configured successfully:

Related articles:

Mac uses its own installed php by default

Centos6.7 php7 installation details

Describes the sample code for compiling and installing PHP 7 in CentOS7 (figure)

The above section details how to install the php environment in Linux and Configure Nginx to support the php-fpm module (image and text). For more information, see other related articles in the first PHP community!

Related Article

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.