Build and install Nginx+PHP+MySql environment under Centos7

  • 2020-05-17 07:36:17
  • OfStack

The preface

This is a tough one. All are compiled manually, except for the compiler installed using yum. Hum ~

They seem to be Nginx, PHP and MySql, but they are so damn dependent on others.

No way, to use them you have to honestly provide them with what they want.

The first one relies on the lib library,

If you're a lazy person, just follow these commands and type them separately. Then go straight to the configuration section. (but this isn't the latest version)

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- install Nginx + PHP + MySql -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

1.1 install or update gcc gcc-c ++

Because the Centos I installed is absolutely pure drop. Nothing. The feeling. You have to install a compiler first.


# yum install gcc gcc-c++

1.2 create the directory you need to use

source is a folder for storing source code. package is used to store compiled library files. lnmp is what we really need to put in there. (nginx + mysql + + php memcached)


# mkdir /source/
# mkdir /package/
# mkdir /lnmp/

2. Start installation (nginx)

2.1 unzip pcre

[official website] http: / / www pcre. org /

Command flow:


# cd /source/
# wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.38/pcre-8.38.tar.gz
# tar -zxvf pcre-8.38.tar.gz

Note: no need to compile, just need to decompress on the line.

2.2 unzip zlib

[official website] http:// zlib.net /

Command flow:


# cd /source/
# wget http://zlib.net/zlib-1.2.8.tar.gz
# tar -zxvf zlib-1.2.8.tar.gz

Note: no need to compile, just need to decompress on the line.

2.3 installation nginx

[official website] http:// nginx.org /

Command flow:


# cd /source/
# wget http://nginx.org/download/nginx-1.8.0.tar.gz
# tar -zxvf nginx-1.8.0.tar.gz
# cd nginx-1.8.0
# ./configure --prefix=/lnmp/nginx --with-pcre=/source/pcre-8.38 --with-zlib=/source/zlib-1.2.8
# make
# make install

-- with-pcre: the source directory used to set pcre.

-- with-zlib: the source directory used to set zlib.

Because compiling nginx requires the source code for both libraries.

Chapter summary:

The installation of nginx has been completed. We can satisfy our desires first. Open the nginx service and check out Hello World.

Start the nginx


# /lnmp/nginx/sbin/nginx

Once started, you can open the page in the browser and it will display the nginx default page.

3. Start installation (php)

3.1 installation libxml2

[official website] http: / / xmlsoft org /

Command flow:


# cd /source/
# wget ftp://xmlsoft.org/libxml2/libxml2-2.9.3.tar.gz
# tar -zxvf libxml2-2.9.3.tar.gz
# cd libxml2-2.9.3
# ./configure \
# --prefix=/package/libxml2 --with-python=no
# make
# make install

Here - with - python = no is

3.2 installation php

[official website] http: / / php net /

Command flow:


# cd /source/
# wget http://cn2.php.net/distributions/php-7.0.2.tar.gz
# tar -zxvf php-7.0.2.tar.gz
# cd php-7.0.2

# ./configure \
# --prefix=/lnmp/php \
# --with-libxml-dir=/package/libxml2 \ // Open the libxml2 The support of the library 
# --with-config-file-path=/lnmp/php/etc \ // The directory where the configuration files are located 
# --enable-mbstring \      // support mbstring library 
# --enable-fpm \       // support php-fpm (recommended open) 
# --with-mysqli       // Open the mysqli The module 

# make
# make install

4. Start installation (mysql)

4.1 installation cmake

[official website] https: / / cmake org /

Command flow:


# wget https://cmake.org/files/v3.4/cmake-3.4.1.tar.gz
# tar -zxvf cmake-3.4.1.tar.gz
# cd cmake-3.4.1
# ./configure --prefix=/package/cmake
# make
# make install
# export PATH=/package/cmake/bin:$PATH // Set environment variables. Can be ignored, just for your future use cmake Convenient point. 

4.2 installation ncurses

[official website] http: / / ftp gnu. org/gnu ncurses /

Command flow:


# wget http://ftp.gnu.org/gnu/ncurses/ncurses-6.0.tar.gz
# tar -zxvf ncurses-6.0.tar.gz
# cd ncurses-6.0
# ./configure --prefix=/package/ncurese
# make
# make install

4.3 installation mysql

[official website] http: / / www mysql. com /

Command flow:

No boost installation


# mkdir /source/
# mkdir /package/
# mkdir /lnmp/
0

Built-in boost installation


# wget http://cdn.mysql.com/Downloads/MySQL-5.7/mysql-boost-5.7.10.tar.gz
# tar -zxvf mysql-boost-5.7.10.tar.gz
# cd mysql-5.7.10
# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
# -DWITH_BOOST=/boost/boost_1_59_0      //boost The path of the library 
# -DCURSES_LIBRARY=/package/ncurese/lib/libncurses.a \ //ncurses library libncurses.a
# -DCURSES_INCLUDE_PATH=/package/ncurses/include   //ncurses Library header files 
# make 
# make install

Note: mysql has needed support for the boost library since version 5.7. Also, it is disgusting that mysql needs to specify the version number of boost. If it is too high or too low, the compilation may fail.

At this point, the new Web module, commonly used on CentOS7, is almost complete. All that remains is to configure the software. Haha, in fact, the code is more, but after understanding really quite simple, just a few commands. How's that? Isn't it simple?

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - configuration Nginx + PHP + MySql -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

1. Preparation

1.1 installation vim


# yum install vim

2. Start configuration (nginx)

2.1 modify nginx conf


# mkdir /source/
# mkdir /package/
# mkdir /lnmp/
3

2.2 find the following and delete the characters marked in red


# mkdir /source/
# mkdir /package/
# mkdir /lnmp/
4

2.3 completion of modification


# mkdir /source/
# mkdir /package/
# mkdir /lnmp/
5

2.4 output phpinfo file


# mkdir /source/
# mkdir /package/
# mkdir /lnmp/
6

2.5 start nginx


/lnmp/nginx/sbin/nginx

Chapter summary:

Completing the above changes will enable nginx to forward php's dynamic script requests.

However, you cannot open the php file yet, because php-fpm is not yet open.

Let's keep looking down.

3. Start configuration (php-fpm)

3.1 copy default configuration file


# cd /source/php-7.0.2
# cp php.ini-development /lnmp/php/etc/php.ini

# cd /lnmp/php/etc
# cp php-fpm.conf.default php-fpm.conf

# cd /lnmp/php/etc/php-fpm.d/
# cp www.conf.default www.conf

3.2 run php - fpm


# mkdir /source/
# mkdir /package/
# mkdir /lnmp/
9

2. Common commands

nginx common commands

Start the nginx


# /lnmp/nginx/sbin/nginx

Restart nginx


# /lnmp/nginx/sbin/nginx -s reload

Close the nginx


# /lnmp/nginx/sbin/nginx -s stop

php-fpm common commands

Start the php - fpm


# /lnmp/php/sbin/php-fpm -c /lnmp/php/etc/php.ini

Restart php - fpm


# kill -SIGUSR2 `cat /lnmp/php/var/run/php-fpm.pid`

Close the php - fpm


# kill -SIGINT `cat /lnmp/php/var/run/php-fpm.pid`

Signal interpretation:

SIGINT, SIGTERM terminate immediately SIGQUIT smooth termination SIGUSR1 re-opens the log file SIGUSR2 smoothly overloads all worker processes and reloads the configuration and 2-bit modules

Related articles: