Centos+nginx+php+mysql detailed configuration (diagram) _linux

Source: Internet
Author: User
Tags bz2 diff fpm install php mkdir
First, install MySQL
At present, the Web server has very few run static page, if you want to run dynamic Web site that of course can not be separated from the database, although in the previous article has written how MySQL is installed, but feel a long time did not install MySQL, now only to post the steps, do not do too much explaining the
#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//initialization of 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 MySQL password
#cp support-files/my-medium.cnf/etc/my.cnf
#echo "/usr/local/mysql/bin/mysqld_safe &" >>/etc/rc.local
Second, install Pcre
Pcre is a regular expression used in Perl to allow the installed software to support regular expressions. By default, Nginx handles only static Web requests, that is, HTML. If it is from a dynamic Web request, such as *.php, then Nginx will query the path according to the regular expression and then the *. PHP is given to PHP to handle
#rpm-qa | grep pcre//query system has not installed Pcre, the general installation system is the default installed, so we have to delete the system from the
#cp/lib/libpcre.so.0///before removing the pcre from the system, you should back up libpcre.so.0 this file, because the RPM package is too relevant, we can not install pcre when we do not libpcre.so.0 this file when we delete it.
#rpm-E--nodeps pcre-6.6-1.1//delete system with Pcre
# tar ZXVF pcre-8.00.tar.gz
#cd pcre-8.00
#cp/libpcre.so.0/lib///libpcre.so.0 copy to/lib directory before we remove the pcre from the system
#./configure//Configuration Pcre, because Pcre is a library, not like Pache, PHP, Postfix and so on, so we choose the default path when installing, this will be installed in the back of other things to avoid unnecessary trouble, After this is done, the following figure appears, showing our configuration of the Pcre
#make && make Install
Iii. installation of Nginx
On the Internet, see a lot of people installed nginx very troublesome, configuration with a lot of options, I ask you really realize so multi-functional mody? The more I watched the more depressed. The installation nginx if it is to follow the steps of the author Step-by-Step down, installation nginx only need to specify Nginx installation path can be
#tar ZXVF nginx-0.8.24.tar.gz
#cd nginx-0.8.24
#./configure--prefix=/usr/local/nginx//Here you only need to specify a path in this link
#make && make Install
#/usr/local/nginx/sbin/nginx//Kai Nginx
#echo "/usr/local/nginx/sbin/nginx" >>/etc/rc.local
Nginx started with two processes, master main process, worker for the work process, the following figure
After starting Nginx, we can enter http://localhost view in the browser, the following figure
Four, install PHP
Since the installation of PHP, that GD is indispensable, this GD installation is no longer described
1. Installation 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. Installation FreeType
#tar XVF Freetype-2.3.9.tar.tar
#cd freetype-2.3.9
#./configure--prefix=/usr/local/freetype
#make; make install
4. Installation Fontconfig
#tar ZXVF fontconfig-2.4.2.tar.gz
#cd fontconfig-2.4.2
#./configure--prefix=/usr/local/fontconfig--with-freetype-config=/usr/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-fontconfig=/usr/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 Nginx and PHP are a little bit out of touch with each other. In the past, a lot of friends have built apache+php,apache+php compiled after the module file, and nginx+php need PHP to generate executable files, so to use fastcgi technology to achieve n Ginx and PHP integration, This is as long as our installation is enabled fastcgi. This time we installed PHP not only used fastcgi, but also used php-fpm such a dongdong, PHP-FPM plainly is a management of a fastcgi manager, it as a PHP plug-in pure in, In the installation of PHP to use PHP-FPM need to php-fpm in the form of patches installed into PHP, and PHP to be consistent with the PHP-FPM version, this is necessary, remember!
First we download PHP and php-fpm to the same directory, this time for php-5.3.0.tar.bz2 and php-5.3.0-fpm-0.5.12.diff.gz, download to 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 in patch form
#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 consolidation must be enabled when installing--enable-fastcgi and--ENABLE-FPM, both options are described above. After execution, the system will prompt--enable-fastcgi is an unknown option, we do not have to ignore
#make
#make Install
#cp Php.ini-dist/usr/local/php/etc/php.ini
Now we're going to start php-fpm.
#/usr/local/php/sbin/php-fpm start
This error is reported when you start PHP-FPM, because PHP-FPM doesn't know to run PHP with that user and group, so we have to modify a file to remove the comments from the file (open the file to delete the red part), Then PHP-FPM will run PHP with nobody users and groups.
#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
V. Integrating Nginx with PHP
As has been said above, Nginx not handle the request of dynamic Web pages, and Nginx will get the dynamic request to PHP, the following we open Nginx configuration file to see
#vi/usr/local/nginx/conf/nginx.conf//Marked part is the one we want to revise later.
Looking at the graph, Nginx already knows how to get the requested message to Php,nginx when *.php request is received, the request passes through 9000 ports to PHP. Let's get rid of these annotations, as shown below
Note: The/usr/local/nginx/html above is the path to our PHP site placement
Then only nginx himself know how to find PHP is not good, but also need PHP know how to find Nginx,ps: You see the street on the jjmm date is not mutual know each other, or do not know what method and the other joint? We don't need to worry about that, PHP-FPM has defined in the configuration file where to accept the PHP request, we can open the configuration file to see
#vi/usr/local/php/etc/php-fpm.conf
As shown in the figure above, we have already seen nginx through the local 9000 port to the PHP request to PHP, and the above figure we can see that PHP is from the local 9000-port listening data, Nginx and PHP through the local 9000 port to complete the data request.
VI. Testing
We have already defined the PHP site's storage path in the Nginx configuration file, the path asks/usr/local/nginx/html
Below we create a new PHP page test page in this directory, the file name is test.php, the contents are as follows
After restarting PHP and Nginx (you can kill the process by shutting it down and then starting) we enter http://localhost/test.php in the browser and the following interface is successful
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.