Detailed configuration of CentOS + Nginx + PHP + MySQL (illustration)

Source: Internet
Author: User
Tags php website

I. Install MySQL currently, web servers rarely run static pages. If you want to run dynamic websites, you can't do without the database. Although I have mentioned how to install MySQL in my previous articles, but I feel that I haven't installed MySQL for a long time, now I only paste the steps out, do not explain 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 MySQL password # cp support-files/my-medium.cnf/etc/my. cnf # echo "/usr/local/mysql/bin/mysqld_safe &">/etc/rc. local 2. Installing PCRE is the regular expression used by perl, so that the installed software supports regular expressions. By default, Nginx only processes static webpage requests, that is, html. for dynamic webpage requests, such *. php, then Nginx needs to query the path based on the regular expression, and then set *. PHP is handed over to PHP for processing # rpm-qa | grep pcre // whether the PCRE is installed in the query system. Generally, the system is installed by default, so we need to delete the # cp/lib/libpcre that comes with the system. so.0 // before deleting the built-in PCRE, back up libpcre first. so.0 file, because the RPM package is too correlated, no libpcre after deletion. so.0 this file when we install PCRE is not installed # rpm-e -- nodeps pcre-6.6-1.1 // Delete the system comes with PCRE # tar zxvf pcre-8.00.tar.gz # cd pcre-8.00 # cp/libpcre. so.0/lib // Delete the libpcre backed up before the built-in PCRE. copy so.0 #. /Configure // configure PCRE. Because PCRE is a library rather than a program such as pache, php, and postfix, you can select the default path during installation, this will avoid unnecessary troubles when installing other things in the future. After executing this section, it will be displayed, the above shows our PCRE configuration # make & make install 3. Installing Nginx on the Internet, it is very troublesome for many people to install Nginx, and a lot of options are used for configuration, are you sure you have implemented that many functions? The more I see it, the more depressing it is. The installation of Nginx is according to the above steps Step by step, 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 # make & make install #/usr/local/nginx/sbin/nginx // start Nginx # echo "/usr/local/nginx/sbin/nginx">/etc/rc. after localNginx is started, there are two processes, master is the main process, and worker is the working process. After NGINX is started, you can enter http: // localhost in the browser to view the process, 4. install PHP. Since PHP is installed, GD is indispensable. Do not describe it here. 1. Install libpng # tar xvf li Bpng-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/bin # mkdir/usr/local/jpeg/lib # mkdir/usr/local/jpeg/include # mkdir/usr/local/jpeg/man # mkdir/usr/local/ jpeg/man/man1 # tar xvf ready src.v7.tar.tar # cd jpeg-7 #. /configure -- prefix =/usr/local/jpeg -- enable-shared -- enable-stat Ic # 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 install4, install the 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 install5, 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 install6. Installing PHP is the most important place, because Nginx and PHP do not feel any of them by default. Many friends have built Apache + PHP. After compiling Apache + PHP, the module File is generated, while Nginx + PHP requires PHP to generate executable files, therefore, fastcgi technology should be used to achieve integration of nginx and PHP, As long as FastCGI is enabled for installation. This time we install PHP not only use FastCGI, but also use the PHP-FPM such a stuff, PHP-FPM said White is a management FastCGI a manager, it as a PHP plug-in pure in, install PHP in the form of a patch to install the PHP-FPM to php to use the PHP-FPM, and PHP to be consistent with the PHP-FPM version, this is necessary, remember! # 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 the php-5.3.0 in the form of 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, you must enable -- enable-fastcgi and -- enable-fpm during installation. The two options are as described above. After execution, the system will prompt that -- enable-fastcgi is an unknown option, so we don't have to worry about # make install # cp php. ini-dist/usr/local/php/etc/php. ini below we need to start the PHP-FPM #/usr/local/php/sbin/php-fpm start will report the above error when starting the PHP-FPM, the reason is that the PHP-FPM does not know which user and group to run PHP, so we need to modify a file, remove the comment in the file (open the file to delete the red part ), the PHP-FPM then runs 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 5. Integration of Nginx and PHP as mentioned above, Nginx does not process dynamic web page requests, and Nginx transfers the dynamic requests to PHP, next let's open the Nginx configuration file to see # vi/usr/local/nginx/conf/nginx. conf // The mark part is to be modified later. Nginx already knows how to send the obtained request to PHP, and Nginx is getting *. when a php request is sent, the request is sent to PHP through port 9000. We can remove these annotations, as shown in the following figure: the above/usr/local/nginx/html is the path of our PHP website, so only Nginx knows how to find PHP is not enough, but also need PHP to know how to find Nginx, PS: have you ever seen JJMM meet each other on the street, or do not know how to connect with each other? We don't need to worry about this. The 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, as shown in, we have seen that Nginx forwards PHP requests to PHP through port 9000 of the local machine, and we can see that PHP listens on data from port 9000 of the local machine, nginx and PHP complete data requests through the local port 9000. 6. test that we have defined the storage path of the PHP website in the nginx configuration file, path:/usr/local/nginx/html. Under this directory, create a PHP page to test the webpage. The file name is test. php, the content is as follows: After restarting PHP and nginx (you can close the process by killing it, and then start it) We enter http: // localhost/test in the browser. php. The following interface is displayed successfully.
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.