Build Php-nginx Environment

Source: Internet
Author: User
This article mainly introduces about building Php-nginx environment, has a certain reference value, now share to everyone, the need for friends can refer to

Background: I used the centos6.4 installed Linux system, when the system installation is complete, the following actions * * *

I. Installing the NGINX system

Installing Nginx using the source package

Put the Nginx source package in the Linux /usr/local/src directory

Use the command TAR-ZXVF nginx-1.9.15.tar.gz Extract the source package

Folder nginx-1.9.15 appears after decompression is complete

Use CD nginx-1.9.15 to enter the nginx-1.9.15 directory

Use the ./configure--prefix=/usr/local/nginx Command configuration Information This command automatically generates Nginx folders in the/usr/local directory

Presence, lack of GCC, need to install GCC

Use command:yum-y install gcc installs GCC by yum mode

Continue using the command after the GCC installation is complete ./configure--prefix=/usr/local/nginx configuration information

What happens: Install Pcre-devel using yum install Pcre-devel

Pcre-devel continue to use the command after installation is complete ./configure--prefix=/usr/local/nginx configuration information

What happens: Install Zlib-devel using yum install Zlib-devel

Zlib-devel continue to use the command after installation is complete ./configure--prefix=/usr/local/nginx configuration information

After the configuration information is complete, use the command: Make && make install installation Nginx

The following information appears to indicate that the installation is complete

Nginx path:/usr/local/nginx

Nignx Start command:/usr/local/nginx/sbin/nginx

Nginx Stop command:/usr/local/nginx/sbin/nginx-s stop

Nginx Restart command:/usr/local/nginx/sbin/nginx-s Reload

View Nginx process:ps-ef | grep nginx

Two. Installing php-7.1.8

Installing PHP using the source package

Nginx uses the thing php-fpm, so we not only to install PHP, but also need to install PHP-FPM.

SOURCE Package Address: http://php.net/releases/

Put the PHP source package in the LINUX/USR/LOCAL/SRC directory

Use the command TAR-ZXVF php-7.1.8.tar.gz extract the source package

Folder php-7.1.8 appears after decompression is complete

Use CD php-7.1.8 to enter the php-7.1.8 directory

Configuration

(./configure--prefix=/usr/local/php-7.1.8--with-config-file-path=/usr/local/php-7.1.8 \
--with-mysql \
--WITH-MYSQLI \
--with-pdo-mysql \
--WITH-GD \
--with-freetype-dir \
--with-curl \
--WITH-XMLRPC \
--with-curl \
--with-iconv=/usr/local/libiconv-1.14 \
--with-zlib \
--with-jpeg-dir \
--with-png-dir \
--WITH-OPENSSL \
--with-libxml-dir \
--with-mcrypt=/usr/local/libmcrypt-2.5.7 \
--ENABLE-FPM \
--enable-static \
--disable-inline-optimization \
--enable-sockets \
--enable-zip \
--enable-calendar \
--enable-bcmath \
--ENABLE-SOAP \
--ENABLE-FTP \
--enable-mbstring \
--enable-shared \
--disable-fileinfo)

There is a situation, missing libxml2, need to install LIBXML2

Use the command: yum-y Install LIBXML2 install LIBXML2 with yum mode

LIBXML2 after the installation is complete, continue to use the./configure--prefix=/usr/local/php--ENABLE-FPM configuration information

Same error again, need to install Libxml2-devel

Use the command: Yum install libxml2-devel through yum installation Libxml2-devel

Libxml2-devel after the installation is complete, continue to use the./configure--prefix=/usr/local/php--ENABLE-FPM configuration information

After the configuration information is complete, use the command: Make && make install PHP

The following information appears and the PHP installation is complete

After the installation is complete, you need to create a PHP configuration file

To create a php.ini file:

Using the command in the source package directory:CP Php.ini-production/usr/local/php/etc/php.ini

Copy the php.ini-production file to the /usr/local/php/etc directory and rename it to php.ini

To create a php-fpm.conf file:

Using the command:cd/usr/local/php/etc into the/usr/local/php/etc directory

Use command in directory:CP php-fpm.conf.default php-fpm.conf Copy the php-fpm.conf.default file under this directory to the same directory and rename it to Php-fpm.conf

To create a www.conf file:

Using the command:CD/USR/LOCAL/PHP/ETC/PHP-FPM.D into the/USR/LOCAL/PHP/ETC/PHP-FPM.D directory

Use the command in the directory:CP www.conf.default www.conf Copy the www.conf.default file under the directory to the same directory and rename it to www.conf


Create a php.ini file under the lib directory

Use the command: cd/usr/local/php/etc Enter the/USR/LOCAL/PHP/ETC directory

Use the command in the directory: CP Php.ini/usr/local/php/lib/php.ini The directory under the php.ini files are copied to /usr/local/php/lib directory under

Profile Creation Complete!

Three. Nginx connection to PHP

After the configuration file is created, you need to modify nginx.conf to connect PHP with Nginx.

Using the command:cd/usr/local/nginx/conf into the nginx configuration file directory

Using the command:VI nginx.conf editing the configuration file

Modify the location of the red box callout: Configure the server root directory under/www, and add the default Access file to index.php.


Modify the location of the red box callout: Open the connection between Nginx and PHP.

After modifying the Nginx configuration, you need to restart Nginx.

The above PHP installation is complete!

PHP-FPM Start command:/usr/local/php/sbin/php-fpm

PHP-FPM View process:ps-ef | grep php-fpm (Stop PHP by kill PID)

Four. Testing

Modify the project root directory in the nginx.conf file and then access the root directory, if the access is successful, it is no problem! Congratulations on installation success!

server {listen 80;                                    server_name localhost;       root/www;                                     Change the root directory to/www #charset koi8-r;                                   #access_log Logs/host.access.log Main;                                                  Location/{# root/www;                                    Index index.html index.htm index.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.