Home > Backend Development > PHP Tutorial > CentOS+Nginx+PHP+MySQL detailed configuration diagram

CentOS+Nginx+PHP+MySQL detailed configuration diagram

WBOY
Release: 2016-08-08 09:22:40
Original
925 people have browsed it

1. Install MySQL

At present, few web servers run static pages. If you want to run a dynamic website, of course you cannot do without a database. Although I have written about how to install MySQL in previous articles, it feels like it has been a long time. MySQL is not installed, so I will just post the steps without explaining too much

#useradd mysql

#tar zxvf mysql-5.0.40.tar.gz

#cd mysql-5.0.40

# ./configure --prefix=/usr/local/mysql

#make && make install

#/usr/local/mysql/bin/mysql_install_db --user=mysql //Initialize MySQL database

#chown -R mysql /usr/local/mysql/var

#/usr/local/mysql/bin/mysqld_safe &​​​​ //Start MySQL

#/usr/local/mysql/bin/mysqladmin -u root password 123456​​ //Set the MySQL password

#cp support-files/my-medium.cnf /etc/my.cnf

#echo "/usr/local/mysql/bin/mysqld_safe &" >>/etc/rc.local

2. Install PCRE

                                  PCRE is a regular expression used by perl. The purpose is to make the installed software support regular expressions. By default, Nginx only processes static web page requests, that is, html. If it comes from a dynamic web page request, such as *.php, then Nginx will query the path based on the regular expression, and then hand over *.PHP to PHP for processing

#rpm -qa | grep pcre                                                                                                                                                                                                                                                                                    /Before deleting the PCRE that comes with the system, you must first back up the libpcre.so.0 file. Because the RPM package is too closely related, if there is no libpcre.so.0 file after deletion, we will not be able to install PCRE.

#rpm -e --nodeps pcre-6.6-1.1 //Delete the PCRE that comes with the system

# tar zxvf pcre-8.00.tar.gz

#cd pcre-8.00

#cp /libpcre.so .0/lib // copy the libpcre.so.0 before the PCRE that we comes with the PCRE that comes with the PCRE to/lib directory

#./Configure // Configure PCRE, because PCRE is a library, not like Pache Pache , php, postfix and other such programs, so we can just choose the default path when installing. This will avoid some unnecessary trouble when installing other things later. After executing this, the following picture will be displayed. The above shows our PCRE configuration

#make && make install

CentOS+Nginx+PHP+MySQL detailed configuration diagram

3. Install Nginx

On the Internet, I saw that many people are very troublesome when installing Nginx. They use a lot of options during configuration. Can you really implement it? So many functions? It made me more and more depressed. If you follow the author’s steps to install Nginx this time, you only need to specify the installation path of Nginx when installing Nginx

#tar zxvf nginx-0.8.24.tar.gz

#cd nginx-0.8 .24

#./configure --prefix=/usr/local/nginx //You only need to specify a path in this link

#make && make install

#/usr/local/nginx/sbin/nginx //Start Nginx

#echo "/usr/local/nginx/sbin/nginx" >>/etc/rc.local

There are two processes after Nginx starts, master is the main process and worker is the working process. As shown in the picture below

CentOS+Nginx+PHP+MySQL detailed configuration diagramAfter starting NGINX, we can enter http://localhost in the browser to view it, as shown in the picture below

CentOS+Nginx+PHP+MySQL detailed configuration diagram

IV. Install PHP

Since PHP is installed, then GD is It is essential and the installation of GD will not be described here.

1. Install libpng

#tar xvf libpng-1.2.10.tar.tar

#cd libpng-1.2.10

#./configure -- prefix=/usr/local/png

#make;make install

#ln -s /usr/local/png/lib/* /usr/lib/

2. Install jpeg

#mkdir /usr/local /jpeg

#mkdir /usr/local/jpeg/bin

#mkdir /usr/local/jpeg/lib

#mkdir /usr/local/jpeg/include

#mkdir /usr/local/jpeg/man

#mkdir /usr/local/jpeg/man/man1

#tar xvf jpegsrc.v7.tar.tar

#cd jpeg-7

#./configure --prefix=/usr/local/jpeg - -enable-shared --enable-static

#make;make install

#ln -s /usr/local/jpeg/lib/* /usr/lib/

3. Install freetype

#tar xvf freetype- 2.3.9.tar.tar

#cd freetype-2.3.9

#./configure --prefix=/usr/local/freetype

#make;make install

4. Install fontconfig

#tar zxvf fontconfig-2.4.2.tar.gz

#cd fontconfig-2.4.2

#./configure --prefix=/usr/local/fontconfig --with-freetype-c/local/freetype/bin/freetype-config

#make;make install

5. Install GD

#tar zxvf gd-2.0.32.tar.gz

#cd gd-2.0.32

#./configure --prefix=/usr/local/gd --with-png=/usr/local/png --with- jpeg=/usr/local/jpeg --with- freetype=/usr/local/freetype --with-fontc/local/fontconfig

#cp /usr/local/png/include/png.h ./

# cp /usr/local/png/include/pngconf.h ./

#make;make install

6. Install PHP

                                         This place is the most important place, because by default, there is a gap between Nginx and PHP There is no feeling at all. In the past, many friends have built Apache+PHP. Apache+PHP generates module files after compilation, while Nginx+PHP requires PHP to generate executable files, so fastcgi technology must be used to realize the integration of Nginx and PHP. This only requires us to install and enable FastCGI. This time we installed PHP not only using FastCGI, but also using something like PHP-FPM. To put it bluntly, PHP-FPM is a manager for managing FastCGI. It is purely a plug-in for PHP. If you want to use it when installing PHP When using PHP-FPM, you need to install PHP-FPM into PHP in the form of a patch, and PHP must be consistent with the PHP-FPM version. This is a must, remember!

First we downloaded PHP and PHP-FPM to the same directory. This time we used php-5.3.0.tar.bz2 and php-5.3.0-fpm-0.5.12.diff.gz. They were downloaded. In the same directory

#tar xvf php-5.3.0.tar.bz2

#gzip -cd php-5.3.0-fpm-0.5.12.diff.gz | patch -d php-5.3.0 -p1 / /Add php-5.3.0-fpm-0.5.12.diff.gz to php-5.3.0 as a patch

#cd php-5.3.0

#./configure --prefix=/usr/ local/php --with-gd=/usr/local/gd --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/png --with-freetype-dir =/usr/local/freetype --with-mysql=/usr/local/mysql --enable-fastcgi --enable-fpm

Note: Nginx+PHP integration, --enable-fastcgi and - must be enabled during installation -enable-fpm, what these two options do is already described above. After execution, the system will prompt that --enable-fastcgi is an unknown option, we don’t need to ignore it

CentOS+Nginx+PHP+MySQL detailed configuration diagram

#make

#make install

#cp php.ini-dist /usr/local/php/etc/php .ini

Now we will start PHP-FPM

#/usr/local/php/sbin/php-fpm start

CentOS+Nginx+PHP+MySQL detailed configuration diagram

The above error will be reported when starting PHP-FPM. The reason is PHP-FPM We don't know which user and group to run PHP, so we need to modify a file and remove the comments in the file (open the file and delete the red part), and then PHP-FPM will run PHP as the nobody user and group.

#vi /usr/local/php/etc/php-fpm.conf

CentOS+Nginx+PHP+MySQL detailed configuration diagram

#/usr/local/php/sbin/php-fpm start

#ps -aux | grep php

CentOS+Nginx+PHP+MySQL detailed configuration diagram

#echo "/usr/local/php/sbin/php-fpm start" >>/etc/rc.local

5. Integrate Nginx and PHP

As mentioned above, Nginx does not handle it itself Dynamic web page requests, and Nginx will transfer the dynamic requests to PHP. Let’s open the Nginx configuration file and take a look

#vi /usr/local/nginx/conf/nginx.conf //The target part is what we will modify later

CentOS+Nginx+PHP+MySQL detailed configuration diagram

Looking at the picture above, Nginx already knows how to convey the request to PHP. When Nginx gets the *.php request, it will pass the request to PHP through port 9000. Let’s just remove these comments, as shown below

CentOS+Nginx+PHP+MySQL detailed configuration diagram

Note: The above /usr/local/nginx/html is the path where our PHP website is placed

Then only Nginx itself knows how to find PHP. No, you still need PHP to know how to find Nginx. PS: Have you ever seen JJMM on the street know each other when dating, or do you not know how to connect with each other? We don’t need to worry about this. PHP-FPM has already defined in the configuration file where to accept PHP requests. We can open the configuration file and take a look

#vi /usr/local/php/etc/php-fpm.conf

CentOS+Nginx+PHP+MySQL detailed configuration diagram

As shown in the picture above, we have seen before that Nginx forwards PHP requests to PHP through the 9000 port of the machine. In the picture above, we can see that PHP itself listens to data from the 9000 port of the machine. , Nginx and PHP completed the data request through the 9000 port of the local machine.

6. Test

We have defined the storage path of the PHP website in the nginx configuration file. The path is /usr/local/nginx/html

Next, we will create a new PHP page test page in this directory. The file name is test.php and the content is as follows

CentOS+Nginx+PHP+MySQL detailed configuration diagram

After restarting PHP and nginx (you can kill the process to close it and then start it up) we are browsing Enter http://localhost/test.php in the server, and the following interface appears, which is considered successful

CentOS+Nginx+PHP+MySQL detailed configuration diagram

The above introduces the detailed configuration diagram of CentOS+Nginx+PHP+MySQL, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

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