Build php-nginx environment

不言
Release: 2023-03-29 15:12:01
Original
1858 people have browsed it

This article mainly introduces the construction of php-nginx environment, which has certain reference value. Now I share it with everyone. Friends in need can refer to it

***Background: I use Centos6.4 installed Linux system, when the system installation is completed, perform the following operations***

1. Install nginx system

UseSource packageInstall Nginx

Place the nginx source package in the linux /usr/local/src directory

搭建lnmp环境(nginx) - L_H_Orz - li_hang的博客

Use command tar -zxvf nginx-1.9.15.tar.gz Decompress the source package

搭建lnmp环境(nginx) - L_H_Orz - li_hang的博客

After decompression is completed The folder appears nginx-1.9.15

搭建lnmp环境(nginx) - L_H_Orz - li_hang的博客

Usecd nginx-1.9.15 Enter the nginx-1.9.15 directory

Use ./configure --prefix=/usr/local/nginx Command configuration information This command will automatically generate the nginx folder in the /usr/local directory

搭建lnmp环境(nginx) - L_H_Orz - li_hang的博客

The following picture appears, gcc is missing and you need to install gcc

Use the command: yum -y install gcc Install gcc through yum

搭建lnmp环境(nginx) - L_H_Orz - li_hang的博客

Continue to use the command after gcc installation is complete./configure --prefix=/usr/local/nginx Configuration information

搭建lnmp环境(nginx) - L_H_Orz - li_hang的博客

The following situation appears: Use yum install pcre-devel to install pcre-devel
搭建lnmp环境(nginx) - L_H_Orz - li_hang的博客
After the pcre-devel installation is completed, continue to use the command ./configure --prefix =/usr/local/nginx Configuration information

搭建lnmp环境(nginx) - L_H_Orz - li_hang的博客

The following situation appears: Use yum install zlib-devel to install zlib-devel

搭建lnmp环境(nginx) - L_H_Orz - li_hang的博客 Continue to use the command after zlib-devel installation is complete ./configure --prefix=/usr/local/nginx Configuration information

搭建lnmp环境(nginx) - L_H_Orz - li_hang的博客

After configuring the information, use the command: make && make install Install Nginx

搭建lnmp环境(nginx) - L_H_Orz - li_hang的博客

##The following message appears to indicate that the installation is complete

nginx Path:

/usr/local/nginx

搭建lnmp环境(nginx) - L_H_Orz - li_hang的博客

nignx startup 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

搭建lnmp环境(nginx) - L_H_Orz - li_hang的博客

2. Install php-7.1.8

Use

source packageInstall PHP

nginx uses php-fpm, so we not only need to install php, but also need to install php-fpm.


Source code package address: http://php.net/releases/

Place the php source code package in the linux /usr/local/src directory

搭建lnmp环境(php7.1.8-源码) - L_H_Orz - li_hang的博客

Use the command tar -zxvf php-7.1.8.tar.gz to decompress the source code package

搭建lnmp环境(php7.1.8-源码) - L_H_Orz - li_hang的博客

The folder appears after decompression is completed php-7.1.8

搭建lnmp环境(php7.1.8-源码) - L_H_Orz - li_hang的博客

##Use cd php -7.1.8 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 )

搭建lnmp环境(php7.1.8-源码) - L_H_Orz - li_hang的博客

The following situation occurs, libxml2 is missing, and libxml2 needs to be installed

Use the command: yum -y install libxml2 Install libxml2 through yum

搭建lnmp环境(php7.1.8-源码) - L_H_Orz - li_hang的博客##After the installation of libxml2 is completed, continue to use ./configure --prefix=/usr /local/php --enable-fpm Configuration information

搭建lnmp环境(php7.1.8-源码) - L_H_Orz - li_hang的博客#The same error occurs again, you need to install libxml2-devel

Use the command: yum install libxml2-devel Install libxml2-devel through yum

## After the installation of libxml2-devel is completed, continue to use ./configure --prefix=/usr/local/php --enable-fpm configuration information 搭建lnmp环境(php7.1.8-源码) - L_H_Orz - li_hang的博客

After configuring the information, use the command: make && make install to install php搭建lnmp环境(php7.1.8-源码) - L_H_Orz - li_hang的博客

##The following information appears, php installation Complete

搭建lnmp环境(php7.1.8-源码) - L_H_Orz - li_hang的博客

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

搭建lnmp环境(php7.1.8-源码) - L_H_Orz - li_hang的博客Create the

php.ini

file:

In Use the command in the source code package directory: cp php.ini-production /usr/local/php/etc/php.ini

will php.ini-production file Copy to the

/usr/local/php/etc

directory and rename it to php.ini

Create

php-fpm.conf搭建lnmp环境(php7.1.8-源码) - L_H_Orz - li_hang的博客File:

Use command:cd /usr/local/php/etc Enter the /usr/local/php/etc directory

Use the command in the directory: cp php-fpm.conf.default php-fpm.conf Copy the

php-fpm.conf.default

file in the directory to the same directory Download and rename it to php-fpm.conf

搭建lnmp环境(php7.1.8-源码) - L_H_Orz - li_hang的博客

Create www.conf file:

Use command: cd /usr/local/php/etc/php-fpm. dEnter the /usr/local/php/etc/php-fpm.d directory

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

搭建lnmp环境(php7.1.8-源码) - L_H_Orz - li_hang的博客


##Create the

php.ini file in 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 Copy the php.ini file in this directory Go to the /usr/local/php/lib directory

搭建lnmp环境(php7.1.8-源码) - L_H_Orz - li_hang的博客##Configuration file created!

3.

Connection between nginx and php

After the configuration file is created, you need to modify nginx.conf to connect php and nginx

Use the command:

cd /usr/local/nginx/conf

Enter the nginx configuration file directory Use the command:

vi nginx.conf

Edit the configuration fileModify The location marked by the red box: Configure the server root directory to /www, and add index.php to the default access file.


##                                                                         Location: Enable the connection between nginx and php. 搭建lnmp环境(php7.1.8-源码) - L_H_Orz - li_hang的博客

##                                                                                                                                 After modifying the nginx configuration, you need to restart nginx.

The above php installation is completed!

搭建lnmp环境(php7.1.8-源码) - L_H_Orz - li_hang的博客php-fpm startup command:

/usr/local/php/sbin/php-fpm

php-fpm View process: 搭建lnmp环境(php7.1.8-源码) - L_H_Orz - li_hang的博客ps -ef | grep php-fpm

(php can be stopped by killing pid)

搭建lnmp环境(php7.1.8-源码) - L_H_Orz - li_hang的博客

##4. Test

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

server {
                                    listen       80;
                                    server_name  localhost;
                                    root /www;       //将根目录改为/www
                                    #charset koi8-r;
 
                                    #access_log  logs/host.access.log  main;
                                   location / {
                                                #  root /www;   
                                               index  index.html index.htm index.php;
                                    }
Copy after login

The above is the detailed content of Build php-nginx environment. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template