Home >Backend Development >PHP Problem >nginx php mysql installation and configuration method

nginx php mysql installation and configuration method

藏色散人
藏色散人Original
2020-10-16 09:26:051935browse

nginx php mysql installation and configuration method: first install Nginx, PHP and MySql; then modify the nginx.conf configuration; then start nginx; and finally configure php-fpm.

nginx php mysql installation and configuration method

Recommended: "PHP Video Tutorial"

Preface

This time I played hard. Except for the compiler, which is installed using yum, everything else is compiled manually. Hum~

It seems that there are only three things: Nginx, PHP, and MySql, but they are too dependent on others.

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

First of all, some modules depend on some lib libraries.

If you are lazy, just follow the following commands and enter them separately. Then look directly at the configuration chapter. (However, this installation is not the latest version)

#----------------Install Nginx PHP MySql --- -------------------

1.1 Install or update gcc gcc-c

Because I installed Centos It's absolutely pure. Nothing. No choice. Just install a compiler first.

# yum install gcc gcc-c++

1.2 Create the directory you need to use

source is the folder used to store source code. Package is used to store compiled library files. lnmp is put in it only when we really need it. (nginx mysql memcached php)

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

2. Start the installation (nginx)

2.1 Unzip pcre

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

Command process:

# 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

Description: No need to compile, just decompress.

2.2 Decompress zlib

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

Command process:

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

Description: No compilation required, only Just need to decompress.

2.3 Install nginx

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

Command process:

# 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: use To set the source code directory of pcre.

--with-zlib: Used to set the source code directory of zlib.

Because compiling nginx requires the source code of these two libraries.

Summary of small chapter:

This comes to an end, nginx installation is completed. We can first satisfy our own desires. Open the nginx service and see Hello World.

Start nginx

# /lnmp/nginx/sbin/nginx

After starting, you can open the page in the browser, and the nginx default page will be displayed.

3. Start the installation (php part)

3.1 Install libxml2

[Official website] http://xmlsoft.org/

Command process:

# 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 Install php

[Official website] http://php.net/

Command process:

# 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 \ //打开libxml2库的支持
# --with-config-file-path=/lnmp/php/etc \ //配置文件所在目录
# --enable-mbstring \      //支持mbstring库
# --enable-fpm \       //支持php-fpm(推荐打开)
# --with-mysqli       //打开mysqli模块

# make
# make install

4. Start the installation (mysql)

4.1 Install cmake

[Official website] https: //cmake.org/

Command process:

# 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 //设置环境变量。可忽略,只是为了你以后使用cmake方便点。

4.2 Install ncurses

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

Command process:

# 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 Install mysql

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

Command process:

Installation without boost

// 这个是不带boost版本的mysql源码。你可以使用以下的参数在编译过程中自动下载boost
// -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/package/boost

# wget http://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.10.tar.gz
# tar -zxvf mysql-5.7.10.tar.gz
# cd mysql-5.7.10
# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
# -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/package/boost \  //设置自动下载boost库,并放到-DWITH_BOOST指定的路径里。
# -DCURSES_LIBRARY=/package/ncurses/lib/libncurses.a \ //ncurses库libncurses.a
# -DCURSES_INCLUDE_PATH=/package/ncurses/include  //ncurses库头文件
# make # make install

Installation with boost

# 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库的路径
# -DCURSES_LIBRARY=/package/ncurese/lib/libncurses.a \ //ncurses库libncurses.a
# -DCURSES_INCLUDE_PATH=/package/ncurses/include   //ncurses库头文件
# make 
# make install

Note: Mysql requires the support of the boost library from version 5.7 onwards. And what is very disgusting is that mysql needs to specify the boost version number. If it is too high or too low, it may cause the compilation to fail.

At this point, the use of the new Web modules commonly used on CentOS7 has basically been completed. The only thing left is to configure these software. Haha, there is actually a lot of code, but after understanding it, it is really simple, just a few commands. How about it? Isn't it quite simple?

----------------Configuring Nginx PHP MySql ------------------ ------

1. Preparation

1.1 Install vim

# yum install vim

2. Start configuration (nginx)

2.1 Modify nginx.conf

# vim nginx.conf

2.2 Find the following content and delete the characters marked in red

  # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  #
  #location ~ \.php$ {
  #  root   html;
  # fastcgi_pass 127.0.0.1:9000;
  # fastcgi_index index.php;
  #  fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
   # include  fastcgi_params;
  #}

2.3 Modification completed

  # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  #
  location ~ \.php$ {
   root   html;
   fastcgi_pass 127.0.0.1:9000;
   fastcgi_index index.php;
   fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
   include  fastcgi_params;
  }

2.4 Output phpinfo file

echo "<?php echo phpinfo(); ?>" > /lnmp/nginx/html/index.php

2.5 Start nginx

/lnmp/nginx/sbin/nginx

Summary of small chapter:

After completing the above modifications, nginx can forward PHP's dynamic script requests.

However, the php file cannot be opened yet because php-fpm has not been opened yet.

We continue to look down.

3. Start configuration (php-fpm)

3.1 copy the 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

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

2. Common commands

##nginx common commands

Start nginx

# /lnmp/nginx/sbin/nginx

Restart nginx

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

Close nginx

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

php-fpm common commands

Start 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 php-fpm

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

Signal interpretation:


    SIGINT, SIGTERM terminate immediately
  • SIGQUIT terminate smoothly
  • SIGUSR1 Reopen Log file
  • SIGUSR2 Gracefully reloads all worker processes and reloads configuration and binary modules

The above is the detailed content of nginx php mysql installation and configuration method. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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
Previous article:How to hide url in phpNext article:How to hide url in php