1024programmer Nginx Linux system compiles and installs Nginx+PHP+MySQL environment

Linux system compiles and installs Nginx+PHP+MySQL environment

Nginx is a high-performance HTTP and reverse proxy server, and it is also an IMAP/POP3/SMTP proxy server. The program is developed by Russia Rambler.ru
Site development, Nginx is famous for its stable performance and low system resource consumption. In recent years, Nginx has become hot in China, such as Tencent, NetEase, 51CTO, Thunder, Dangdang, 51, Renren and many other large websites. Nginx has been used as a web server, so it is very necessary for us to learn how to use Nginx. Let’s take a look at how Nginx is built on the Linux platform.
Before installation, first use the yum command to install and upgrade the required library

yum -y install gcc gcc-c++ autoconf libjpeg
libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2
libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel
bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs
e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl
openssl-devel openldap openldap-devel nss_ldap
openldap-clients openldap-servers

1. Install MySQL
the
At present, web servers rarely run static pages. If you want to run dynamic websites, of course you cannot do without the database. Although I wrote how to install MySQL in the previous article, I feel that MySQL has not been installed for a long time. Now I only post the steps. Come out, I won’t explain too much
#groupadd mysql
#useradd Cg mysql mysql
#tar zxvf mysql-5.0.40.tar.gz
#cd mysql-5.0.40
#./configure ??prefix=/usr/local/mysql
#make && make install
#scripts/mysql_install_db
Cuser=mysql
Install the mysql database and give all permissions to the mysql user
#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 MySQL password
#cp support-files/my-medium.cnf
/etc/my.cnf
Copy the appropriate configuration file
#cp support-files/mysql.server
/etc/init.d/mysql
Copy mysql startup script service
#chkconfig Cadd
mysql
Add mysql service
#chkcoonfig Clist
mysql
Check the running status of the mysq service
#/usr/local/mysql/bin/mysql_install_db
??user=mysql
//Initialize the MySQL database
#echo “/usr/local/mysql/bin/mysqld_safe
&” >>/etc/rc.local set boot start
# /etc/init.d/mysqld start
(restart) Start myspl service
If there is a permission problem, enter the command:
#chmod a+rwx /etc/init.d/mysqld

2. Install PCRE
the
PCRE is a regular expression used by perl, the purpose is to make the installed software support regular expressions. By default, Nginx only handles static web page requests, that is, html. If it is from a dynamic web page request, such as *.php, then Nginx will query the path according to the regular expression, and then hand over *.PHP to PHP for processing
#rpm -qa | grep
pcre
//Query whether PCRE is installed in the system. Generally, the system is installed by default, so we need to delete the built-in system
#cp /lib/libpcre.so.0
/
//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 related, and if there is no libpcre.so.0 file after deletion, we will not be able to install PCRE.
on
#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 backed up before we deleted the PCRE that comes with the system to the /lib directory.x=/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: For Nginx+PHP integration, you must enable ??enable-fastcgi and
??enable-fpm, what these two options do is described above. After the execution, the system will prompt that ??enable-fastcgi is an unknown option, we don’t have to pay attention to it
#make
#make install
#cp php.ini-dist
/usr/local/php/etc/php.ini
Below we will start PHP-FPM
#/usr/local/php/sbin/php-fpm start
the
The above error will be reported when PHP-FPM is started. The reason is that PHP-FPM itself does not 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. ), then PHP-FPM will run PHP as nobody user and group.
#vi /usr/local/php/etc/php-fpm.conf
#/usr/local/php/sbin/php-fpm start
#ps -aux | grep php
#echo “/usr/local/php/sbin/php-fpm
start” >>/etc/rc.local

5. Integrate Nginx and PHP
the
As mentioned above, Nginx itself does not handle requests for dynamic webpages, and Nginx forwards the obtained dynamic requests to PHP. Next, let’s open the configuration file of Nginx to have a look
#vi
/usr/local/nginx/conf/nginx.conf
//The marked part is what we will modify later
the
Looking at the picture above, Nginx already knows how to pass the request to PHP. When Nginx gets a *.php request, it will pass the request to PHP through port 9000. Let’s remove these comments, as shown below
Note: The above /usr/local/nginx/html is the path where our PHP website is placed
the
Then only Nginx knows how to find PHP, but PHP needs to know how to find Nginx. PS: Have you seen JJMM on the street who know each other when they are dating, or do you not know how to connect with each other? We don’t need to worry about this, PHP-FPM has defined in the configuration file where to accept PHP requests, we can open the configuration file to see
#vi /usr/local/php/etc/php-fpm.conf
the
As shown in the figure above, we have seen that Nginx forwards PHP requests to PHP through port 9000 of the local machine. In the figure above, we can see that PHP itself listens to data from port 9000 of the machine. Nginx and PHP completes the data request through the local port 9000.
6. Test
the
We have defined the storage path of the PHP website in the nginx configuration file, and the path is /usr/local/nginx/html
Below we create a new PHP page test page in this directory, the file name is test.php, and the content is as follows
Enter the following into the file
<?php
phpinfo();
?>
the
After restarting PHP and nginx (it can be closed by killing the process, and then restarted), we enter http://localhost/test.php in the browser, and the following interface appears successfully

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/linux-system-compiles-and-installs-nginxphpmysql-environment/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索