Centos+nginx+php+mysql Detailed configuration plots

Source: Internet
Author: User
Tags diff php tutorial
First, install MySQL

At present, the Web server has rarely run static pages, if you want to run a dynamic site that of course, can not be separated from the database, although in the previous article has written how to install MySQL, but feel for a long time not installed MySQL, now only the steps posted out, do not do too much to explain

#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//initializing 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, installation Pcre

Pcre is a regular expression used by Perl to allow the installed software to support regular expressions. By default, Nginx only handles static Web requests, which is HTML. If it is from a dynamic Web request, such as *.php, then Nginx will query the path according to the regular expression, then the *. PHP to handle PHP

#rpm-qa | grep pcre//query system There is no installation of pcre, the general loading system is installed by default, so we have to delete the system comes with the

#cp/lib/libpcre.so.0///PCRE before deleting the system, to back up the libpcre.so.0 this file, because the RPM package is too strong correlation, after the deletion of the file is not libpcre.so.0 we can not install Pcre

#rpm-E--nodeps pcre-6.6-1.1//delete system comes with Pcre

# tar ZXVF pcre-8.00.tar.gz

#cd pcre-8.00

#cp/libpcre.so.0/lib///Remove us from the libpcre.so.0 copy of the Pcre before the system comes back to the/lib directory

#./configure//Configuration Pcre, because Pcre is a library, and not like Pache, PHP, postfix and other such programs, so we install the default path can be installed, this will install other things in the back to avoid unnecessary trouble, after the execution of this will show , which shows our configuration of the pcre.

#make && make Install

Third, install Nginx

On the Internet, see a lot of people are very troublesome to install Nginx, configuration with a lot of options, do you really realize so multifunctional? The more I see the more depressed. This installation nginx if is to follow the above author step by step step down, install nginx only need to specify the installation path of Nginx

#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 session

#make && make Install

#/usr/local/nginx/sbin/nginx//Kai Nginx

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

Nginx Boot has two processes, master process, worker for the worker process, such as

After you start the Nginx, we can enter http://localhost view in the browser, such as

Iv. Installation of PHP

Since the installation of PHP, that GD is not rare, the installation of this GD 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-c/local/freetype/bin/freetype-config

#make; make install

5. Installing 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 Nginx and PHP, by default, have a little feeling between them. Before, many friends have built apache+php,apache+php compiled after the build is a module file, and nginx+php need PHP to generate executable files, so to use fastcgi technology to achieve the integration of N Ginx and PHP, This as long as we install is enabled fastcgi can. This time we installed PHP not only use the fastcgi, but also used php-fpm such a thing, PHP-FPM is a management fastcgi a manager, it as a PHP plugin pure, In the installation of PHP to use PHP-FPM will need to PHP-FPM as a patch installed in PHP, and PHP to be consistent with the PHP-FPM version, it is necessary, remember!

First we downloaded 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, downloaded 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 integration, must be enabled at the time of installation--enable-fastcgi and--ENABLE-FPM, these two options are done what is 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

The above error will be reported when starting PHP-FPM, because php-fpm do not know to run PHP with that user and group, so we have to modify a file, remove the comments in 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

Five, the integration of Nginx and PHP

As already mentioned above, Nginx does not handle the request of Dynamic Web page, and Nginx will get the dynamic request to PHP, below we open nginx configuration file to see

#vi/usr/local/nginx/conf/nginx.conf//The part that we want to modify later

Look, Nginx already knows how to convey the request to Php,nginx in the *.php request, will send the request through 9000 port to PHP. Let's get rid of these annotations, as

Note: The above/usr/local/nginx/html is the path of our PHP site placement

Then only nginx himself know how to find PHP not yet, but also need PHP know how to find Nginx,ps: You have seen the street on the jjmm date when there is not mutual understanding of each other, or do not know what method and the other joint? We don't have to worry about that, PHP-FPM has defined in the config 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, we have seen in the previous nginx is through the local port 9000 to the PHP request forwarded to PHP, and we can see PHP itself from the local 9000 port listening data, Nginx and PHP through the local port 9000 to complete the data request.

VI. Testing

We have defined in the Nginx configuration file the PHP site's storage path, the path asked/usr/local/nginx/html

Below we are in this directory to create a new PHP page test page, the file name is test.php, the content is as follows

After restarting PHP and Nginx (can be used to kill the process of the way to shut down, and then start) we enter the http://localhost/test.php in the browser, the following interface is successful

The above describes the Centos+nginx+php+mysql detailed configuration diagram, including the aspects of the content, I hope the PHP tutorial interested in a friend helpful.

  • 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.