Web Platform Architecture: LNMP (centos6.5+nginx+mysql+php)
In order to write Nginx series of tutorials, in the introduction of Nginx features, can have a test environment, so write a LNMP architecture, so that those who look at the document can set up their own environment to test nginx function. However, usually nginx is used as a pure Web site is not many, more is the use of nginx in the reverse proxy environment. However, due to the superior performance of nginx processing static files, it is often possible to use Nginx in conjunction with PHP to achieve static and dynamic separation, which is the function of Web response acceleration.
1. Preparatory work
Os:centos6.5x64
Hostname:test2.lxm.com
ip:10.0.10.12
Software:/root/soft/
Nginx-1.6.1.tar.gz
Pcre-8.33.tar.gz
Openssl-1.0.1i.tar.gz
Mysql-5.5.27.tar.gz
Php-5.5.16.tar.gz
Libmcrypt-2.5.7.tar.gz
Mhash-0.9.9.tar.gz
Software Install path:/usr/local/
Note: In preparation, prepare a CentOS system, configure the network environment and the Yum source, prepare the package to be used, decide where to place the package and where to install it. Second, the installation process all use the source package compiled installation.
#yum-y install gcc* compact-gcc* autoconf automake make CMake
Install the compiled software required for compiling and installation, if the system is already installed, you do not need to install it again
#iptables-f;service iptables stop;chkconfig iptables off
Shutting down the firewall is not recommended in production environments iptables
Temporarily close SELinux
#setenforce 0
If you want to permanently turn selinux off, modify the configuration file
2. Installing Nginx
#cd/root/soft
#tar-ZXVF openssl-1.0.1i.tar.gz
#tar-ZXVF pcre-8.35.tar.gz
#tar-ZXVF nginx-1.6.1.tar.gz
#cd nginx-1.6.1
#mkdir-pv/usr/local/nginx {client_body_temp,proxy_temp,fastcgi_temp,uwsgi_temp,scgi_temp}
#./configure--prefix=/usr/local/nginx/--with-pcre=/root/soft/pcre-8.35--with-http_ssl_module--with-openssl=/ root/soft/openssl-1.0.1i--with-http_gzip_static_module--with-http_realip_module--with-http_stub_status_module- -http-client-body-temp-path=/usr/local/nginx/client_body_temp/--http-proxy-temp-path=/usr/local/nginx/proxy_ temp/--http-fastcgi-temp-path=/usr/local/nginx/fastcgi_temp/--http-uwsgi-temp-path=/usr/local/nginx/uwsgi_temp /--http-scgi-temp-path=/usr/local/nginx/scgi_temp/
#make && make Install
#make Clean
In this case, if there is no error, the basic installation is successful. But it's important to note that Pcre and OpenSSL use source packages.
Test Nginx:
#/usr/local/nginx/sbin/nginx//Start Nginx
#ps aux | grep nginx//To see if nginx process started successfully
#netstat-NULTP | grep 80//View 80 port is listening, nginx default listener on 80 port
Browser testing;
http://10.0.10.12 //If the Nginx Welcome page appears normally, the Nginx installation is successful
Expand:
Introduce to you a Linux text browser elinks, later local testing, you can directly in the Linux system to test.
#yum-y Install ELinks
#links--dump http://10.0.10.12 //Print out the contents of the Web site directly, if you want to access it in an interactive interface, type ELinks enter directly.
3. Install MySQL
#yum-y install zlib-devel openssl-devel ncurses-devel bison//because the following compilation MySQL uses these development files, so must be installed
#cd/root/soft/
#tar-ZXVF mysql-5.5.27.tar.gz
#cd mysql-5.5.27
#mkdir/usr/local/mysql
#useradd-S/sbin/nologin mysql-m
#cmake
-dcmake_install_prefix=/usr/local/mysql
-dmysql_datadir=/data/mysqldata (Note: Here in the enterprise environment, usually a separate directory for the MySQL data files, if the business can not be used, the default is placed under/var/lib/mysql)
-dsysconfdir=/etc
-dwith_innobase_storage_engine=1
-dwith_archive_storage_engine=1
-dwith_blackhole_storage_engine=1
-dmysql_unix_addr=/tmp/mysqld.sock
-denabled_local_infile=1
-dwith_readline=1
-dwith_ssl=system
-dwith_zlib=system
-dwith_libwrap=0
-dmysql_tcp_port=3306
-dextra_charsets=all
-ddefault_charset=utf8
-ddefault_collation=utf8_general_ci
-dwith_extra_charsets:string=all
-dmysql_user=mysql
-dwith_debug=0
#make
#make Install
#make Clean
#chown-R Mysql.mysql/usr/local/mysql
#chown-R Mysql.mysql/data/mysqldata
#cd/usr/local/mysql/scripts
#mysql_install_db--datadir=/data/mysqldata--basedir=/usr/local/mysql--user=mysql
#cd: /support-files
#cp my-large.cnf/etc/rc.d/my.cnf
#cp-P Mysql.server/etc/rc.d/init.d/mysqld
#chown-R Root.mysql/usr/local/mysql
#service mysqld Start
#mysqladmin-U root Passwod "LXM"//Set the password of the MySQL root user
#mysql-U root-p
Enter the root password to test if the MySQL installation was successful
To this, if everything is not wrong, it means that MySQL installation is successful
4. Install PHP
The installation and use of PHP is really worth talking about, but it's a simple installation. For detailed installation use will be a detailed chat in lamp ...
To install the necessary packages:
#yum-y install ncurses-devel net-snmp-devel bzip2 bzip2-devel Curl curl-devel libjpeg libjpeg-devel libpng libpng-devel Freetype-devel libxml2 libxml2-devel libxslt libxslt-devel zlib zlib-devel expat expat-devel OpenSSL openssl-devel gd PHP -GD libjpeg libjpeg-devel libtool Libtool-ltdl libtool-ltdl-devel
Install Libmcrypt and Mhash//These two things are for PHP to provide the encryption algorithm related to the library file
#cd/root/soft
#tar-ZXVF libmcrypt-2.5.7.tar.gz
#cd libmcrypt-2.5.7
#mkdir/usr/local/libmcrypt
#./configure--prefix=/usr/local/libmcrypt
#make && make Install
#make Clean
#cd/root/soft
#tar-ZXVF mhash-0.9.9.tar.gz
#cd mhash-0.9.9
#mkdir/usr/local/mhash
#./configure--prefix=/usr/local/mhash
#make && make Install
#make Clean
Install PHP:
#cd/root/soft/
#tar-ZXVF php-5.5.16.tar.gz
#cd php-5.5.16
#mkdir/usr/local/php55
#./configure--prefix=/usr/local/php55/--with-libxml-dir=/usr/include/libxml2/--with-config-file-path=/etc-- With-mysql=mysqlnd--with-mysqli=mysqlnd--with-gd--enable-gd-native-ttf--with-zlib--with-mcrypt=/usr/local/ libmcrypt/--with-mhash=/usr/local/mhash/--with-pdo-mysql=mysqlnd--enable-fpm--enable-shmop--enable-soap-- Enable-sockets--enable-wddx--enable-zip--with-xmlrpc--enable-mbstring--with-zlib-dir=/usr/lib--with-bz2-- With-curl--enable-exif--enable-ftp--with-jpeg-dir=/usr/lib--with-png-dir=/usr/lib--with-freetype-dir=/usr/lib- -with-pcre-dir--enable-bcmath--with-config-file-scan-dir=/etc/php.d/--with-openssl
If there are no errors, the following will be displayed:
Generating files
Configure:creating./config.status
Creating MAIN/INTERNAL_FUNCTIONS.C
Creating MAIN/INTERNAL_FUNCTIONS_CLI.C
+--------------------------------------------------------------------+
| License: |
| This software was subject to the PHP License, available in this |
| Distribution in the file LICENSE. By continuing this installation |
| Process, you is bound by the terms of this License agreement. |
| If you don't agree with the terms of this license, you must abort |
| The installation process at this point. |
+--------------------------------------------------------------------+
Thank for using PHP.
Config.status:creating Php5.spec
Config.status:creating Main/build-defs.h
Config.status:creating scripts/phpize
Config.status:creating scripts/man1/phpize.1
Config.status:creating Scripts/php-config
Config.status:creating Scripts/man1/php-config.1
Config.status:creating SAPI/CLI/PHP.1
Config.status:creating sapi/fpm/php-fpm.conf
Config.status:creating SAPI/FPM/INIT.D.PHP-FPM
Config.status:creating Sapi/fpm/php-fpm.service
Config.status:creating sapi/fpm/php-fpm.8
Config.status:creating sapi/fpm/status.html
Config.status:creating SAPI/CGI/PHP-CGI.1
Config.status:creating Ext/phar/phar.1
Config.status:creating Ext/phar/phar.phar.1
Config.status:creating main/php_config.h
config.status:executing default Commands
#make && make Install
If there is no error, the following is displayed:
Installing Shared extensions:/usr/local/php55/lib/php/extensions/no-debug-non-zts-20121212/
Installing PHP CLI binary:/usr/local/php55/bin/
Installing PHP CLI man page:/usr/local/php55/php/man/man1/
Installing PHP FPM binary:/usr/local/php55/sbin/
Installing PHP FPM config:/usr/local/php55/etc/
Installing PHP FPM man page:/usr/local/php55/php/man/man8/
Installing PHP FPM Status page:/usr/local/php55/php/fpm/
Installing PHP CGI binary:/usr/local/php55/bin/
Installing PHP CGI man page:/usr/local/php55/php/man/man1/
Installing Build Environment:/usr/local/php55/lib/php/build/
Installing header files:/usr/local/php55/include/php/
Installing helper Programs:/usr/local/php55/bin/
Program:phpize
Program:php-config
Installing man pages:/usr/local/php55/php/man/man1/
Page:phpize.1
Page:php-config.1
Installing PEAR Environment:/usr/local/php55/lib/php/
[PEAR] archive_tar-installed:1.3.12
[PEAR] console_getopt-installed:1.3.1
[PEAR] structures_graph-installed:1.0.4
[PEAR] xml_util-installed:1.2.3
[PEAR] pear-installed:1.9.5
Wrote PEAR system config file at:/usr/local/php55/etc/pear.conf
Want to add:/usr/local/php55/lib/php to your php.ini include_path
/root/soft/php-5.5.16/build/shtool install-c Ext/phar/phar.phar/usr/local/php55/bin
Ln-s-f/usr/local/php55/bin/phar.phar/usr/local/php55/bin/phar
Installing PDO headers:/usr/local/php55/include/php/ext/pdo/
#make Clean
#cp Php.ini-production/etc/php.ini
#cd/usr/local/php55/bin
#./php-m | Less//view PHP compiled built-in modules, if not you need to add additional, specifically how to configure see lamp
Note: A common error when testing PHP modules is that you cannot load certain modules, for example: PHP warning:php startup:unable to load dynamic library '/usr/local/php55/lib/php/ Extensions/no-debug-non-zts-20121212/curl.so '-/usr/local/php55/lib/php/extensions/no-debug-non-zts-20121212/ Curl.so:cannot open Shared object file:no such file or directory in Unknown on line 0. Make such a mistake, don't be nervous. This is because you are a compiled and installed PHP module, and here you are prompted that the modules you cannot load are usually the modules that need to be loaded when you install the RPM package. The configuration files of these modules are usually in the/etc/php.d/directory, you only need to delete these files, test again will not be wrong. And you find that failed to load the module, in the PHP built-in module is already ready to use, this is the PHP source code compilation.
#cd/usr/local/php55/etc///Hint: Why always use absolute path, is afraid of some people do not know I cut to cut, where to cut. Fool's technology, must let you know why ....
#cp-P Php-fpm.conf.default php-fpm.conf
[[email protected] etc]#/USR/LOCAL/PHP55/SBIN/PHP-FPM//start FPM process
[[Email protected] etc]# PS aux | grep fpm
Root 17161 0.0 0.9 207092 4972? Ss 10:38 0:00 php-fpm:master process (/usr/local/php55/etc/php-fpm.conf)
Nobody 17162 0.0 0.8 207092 4388? S 10:38 0:00 Php-fpm:pool www
Nobody 17163 0.0 0.8 207092 4388? S 10:38 0:00 Php-fpm:pool www
Root 17165 0.0 0.1 103244 848 pts/0 s+ 10:38 0:00 grep fpm
[Email protected] etc]# NETSTAT-NULTP | grep fpm
TCP 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 17161/php-fpm
From the above information, PHP-FPM has been successfully launched and supervised the interpretation of PHP programs
Related Content Introduction:
1.freetype: Some of the most popular font libraries
2.zlib: The compression library of the universal format on the Internet
3.--enable-sockets: Allow PHP to support socket communication
4.mcrypt: Additional encryption library with encryption enabled
5. If you are using PHP5.3 or above, to connect to the MySQL database, you can specify MYSQLND so that you do not have to install the MySQL or MySQL development package first. Mysqlnd is available from php5.3, and can be bound to it at compile time (instead of relying on a specific MySQL client binding, but it is the default from the beginning of the php5.4.
#./configure--with-mysql=mysqlnd--with-pdo-mysql=mysqlnd--with-mysqli=mysqlnd
6.--ENALBE-FPM This option is to compile PHP into a separate server managed by PHP-FPM. Nginx does not integrate PHP into the internal functions like Apache, so you must add this option when compiling PHP, otherwise nginx and PHP will not be integrated through fastcgi. Because of this feature, PHP can be made into clusters.
5. Integration of Nginx and PHP
Nginx and PHP integration can be proxy_pass and fastcgi two ways to integrate, but usually through the fastcgi way to integrate, as for the benefits of fastcgi, please check it yourself ...
Modify configuration file:/usr/local/nginx/conf/nginx.conf
Ensure that you have the following configuration for the consolidated PHP:
Location ~ \.php$ {
root/usr/local/nginx/html; This is the root directory of the specified Web site, php files outside the root of the site are not interpreted and will prompt file not found.
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
# Fastcgi_param Script_filename/scripts$fastcgi_script_name; This is the Nginx document default configuration, but in the new version of Nginx is not valid, will be prompted not to the root directory
Fastcgi_param script_filename $document _root$fastcgi_script_name;
Include Fastcgi_params;
}
#service nginx configtest//Check the configuration file for syntax errors
#service nginx Restart//I have configured the Nginx boot file, if you need to, please go to nginx installation deployment inside copy one.
#cd/usr/local/nginx/html
Create a index.php test file with the following content:
<?php
Phpinfo ();
?>
Test the PHP page for normal parsing and access to:
Browser:
http://10.0.10.12/index.php
If everything works, it will return to the PHP test page, which is also a page that looks at the parameters and functions of PHP, and must be
6. Testing the LNMP architecture
Installed nginx,mysql,php, the final test of these three programs on the Linux platform is able to run through, here with a simple PHP test file can be.
#cd/usr/local/nginx/html
#vim index.php
Modify the contents of the configuration file as follows:
<?php
$links = mysql_connect (' localhost ', ' root ', ' lxm ');
if ($links)
echo "Yes";
Else
echo "No";
?>
Process: When the client requests the PHP file, Nginx will submit the PHP file to the backend php-fpm for parsing, and then PHP call Mysql_connect to the back-end database connection test, if successful return yes, failure will return no
Test:
http://10.0.10.12/index.php
650) this.width=650; "style=" Float:none; "title=" 2.jpg "src=" http://s3.51cto.com/wyfs02/M00/47/88/ Wkiol1p8fdgzjveyaacvuwprdlc992.jpg "alt=" Wkiol1p8fdgzjveyaacvuwprdlc992.jpg "/>
The result returned is: no
What is this? To view logs:
650) this.width=650; "style=" Float:none; "title=" 3.jpg "src=" http://s3.51cto.com/wyfs02/M02/47/86/ Wkiom1p8exrijvqeaag9gjwttsy648.jpg "alt=" Wkiom1p8exrijvqeaag9gjwttsy648.jpg "/>
Look at the above error, it seems that mysql_connect this function is not found. Strange Why? After many tests, found that the original MySQL sock file location problem. When compiling above, using the--enable-sockets,php default is to find/var/lib/ MySQL under the Mysqld.sock file, which is also the default location of MySQL storage sock, but this document when installing MySQL, sock placed in the TMP directory, so you need to modify the php.ini file to specify the location of the sock file.
#vim/etc/php.ini
Locate the following option and specify the Soket location
Mysql.default_socket =/tmp/mysqld.sock
Restart PHP-FPM:
#pkill PHP-FPM
#/usr/local/php55/sbin/php-fpm
At this point, the test again, return yes, indicating that the test was successful and that the entire LNMP architecture has been measured.
650) this.width=650; "style=" Float:none; "title=" 1.jpg "src=" http://s3.51cto.com/wyfs02/M01/47/86/ Wkiom1p8exrdcgaaaacdcu8gjck406.jpg "alt=" Wkiom1p8exrdcgaaaacdcu8gjck406.jpg "/>
To this, LNMP platform is completed, more technical documents please see tell .....
End!!!
Fool's technical------not afraid you will NOT!!!!
This article is from the "Fool's Technology" blog, please be sure to keep this source http://mingyang.blog.51cto.com/2807508/1545100
Web Platform Architecture: LNMP (centos6.5+nginx+mysql+php)