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

CentOS+Nginx+PHP+MySQL detailed configuration diagram

Aug 08, 2016 am 09:22 AM
nbsp nginx php usr

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.

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP's Purpose: Building Dynamic Websites PHP's Purpose: Building Dynamic Websites Apr 15, 2025 am 12:18 AM

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP: Handling Databases and Server-Side Logic PHP: Handling Databases and Server-Side Logic Apr 15, 2025 am 12:15 AM

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

How to configure cloud server domain name in nginx How to configure cloud server domain name in nginx Apr 14, 2025 pm 12:18 PM

How to configure an Nginx domain name on a cloud server: Create an A record pointing to the public IP address of the cloud server. Add virtual host blocks in the Nginx configuration file, specifying the listening port, domain name, and website root directory. Restart Nginx to apply the changes. Access the domain name test configuration. Other notes: Install the SSL certificate to enable HTTPS, ensure that the firewall allows port 80 traffic, and wait for DNS resolution to take effect.

How to check nginx version How to check nginx version Apr 14, 2025 am 11:57 AM

The methods that can query the Nginx version are: use the nginx -v command; view the version directive in the nginx.conf file; open the Nginx error page and view the page title.

How to start nginx server How to start nginx server Apr 14, 2025 pm 12:27 PM

Starting an Nginx server requires different steps according to different operating systems: Linux/Unix system: Install the Nginx package (for example, using apt-get or yum). Use systemctl to start an Nginx service (for example, sudo systemctl start nginx). Windows system: Download and install Windows binary files. Start Nginx using the nginx.exe executable (for example, nginx.exe -c conf\nginx.conf). No matter which operating system you use, you can access the server IP

PHP: An Introduction to the Server-Side Scripting Language PHP: An Introduction to the Server-Side Scripting Language Apr 16, 2025 am 12:18 AM

PHP is a server-side scripting language used for dynamic web development and server-side applications. 1.PHP is an interpreted language that does not require compilation and is suitable for rapid development. 2. PHP code is embedded in HTML, making it easy to develop web pages. 3. PHP processes server-side logic, generates HTML output, and supports user interaction and data processing. 4. PHP can interact with the database, process form submission, and execute server-side tasks.

PHP vs. Python: Use Cases and Applications PHP vs. Python: Use Cases and Applications Apr 17, 2025 am 12:23 AM

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

See all articles