Linux:centos5. 5 Nginx: 1.7. 8 . tar.gzphp: 5.6. 3. tar.gz
- What is the difference between LNMP and lamp?
LNMP (linux+nginx+mysql+php) is a reference to lamp (linux+apche+mysql+php).
Why did you abandon Apache with Nginx?
Nginx Network IO is in the way of Epoll,apache network IO for SELECT. The difference between the two details, please: http://www.cnblogs.com/simpman/p/4150005.html
Personal understanding of Epoll: Create a file descriptor queue and notify the Web container after the file description queue is ready. is equivalent to maintaining a queue in which members in the queue are ready to notify the thread.
Select mode: Requires a Web container to open a thread to scan which file descriptor is ready. Equivalent to maintaining an array.
Epoll has been introduced in apache2.4.1 instead of select. The older version of Apache is not capable of handling high-concurrency static file requests due to the use of select mode.
Nginx is achieved by using php-fastcgi. Apache is generally implemented through the mod_php module. I used to use Apache in this way.
Here's how Nginx and php-fastcgi work:
1. Definition: CGI (Common Gateway Interface) is a tool for the HTTP server to "talk" to other programs on the machine, which must be running on a network server.
For details, please visit: http://www.cnblogs.com/simpman/p/4151639.html
In fact, the above is equivalent to saying: CGI is used to parse dynamic scripts, fast-cgi is used to manage CGI programs.
In the implementation of the php-cgi used to parse the PHP script, php-fpm (full php:fastcgi process Manager) to manage php-cgi.
For a detailed explanation of the concept, see: http://www.nowamagic.net/librarys/veda/detail/1319
The PHP-FPM has been integrated into the kernel in PHP5.3.3+ . 5.3.3 Previously, PHP-FPM needed to be installed as a patch for PHP.
PHP-FPM uses XML configuration in the old version of PHP and uses the same configuration format as php.ini in the new version.
Installation: Only need to add--enable-fpm when configure.
- Installation Preparation:
The GCC (GUN Compiler Collection) compiler is required to compile the C,c++,object-c,fortran,java.
GCC is the abbreviation for gnu compiler collection, can compile C and C + + source code, etc. It is the GNU developed C and C + + and many other languages of the compiler (at the earliest time only compile C, and then quickly evolved into a compilation of multiple languages, such as Fortran, Pascal, Objective-c, Java, Ada, go and so on.
gcc in compiling C + + source code, compile C++ source files only, not automatically and c++ The library link used by the program (the compilation process is divided into two phases: compile, link, and take care not to confuse the concept with the executable, there are three important concepts relative to the executable file (compile), link, load (load).
Therefore, the g++ command is usually used to complete C++ compile and connect the program, which automatically calls gcc implementation of the compilation. g++ can also compile C source code, but will think of it as C + + source code, suffix. C, GCC treats it as a C program, and g++ as a C + + program; the suffix is. cpp, both of which are considered C + + programs, note that although C + + is a superset of C, there are differences between the two requirements for syntax.
There is also the need to install the autoconf and Automake tools, which are used to automatically create fully functional makefile, most of which are generated makefile with this tool. So is nginx.
Yum install gcc gcc-c++ autoconf automake
Module dependencies: Nginx requires support from other third-party libraries, Gzip requires zlib library, rewrite requires pcre (Perl Compatible Regular Expression) library, and SSL features require OpenSSL.
Yum-y install zlib zlib-devel OpenSSL openssl-devel pcre pcre-devel
The installation of Nginx is very simple. By default, the compiled and installed Nginx contains most of the available modules. You can use the "./configure--help" option to set the usage of each module, such as an unwanted Http_ssi module, which can be closed by "--without-http_ssi_module", and, if necessary, "Http_perl module, you can install the module by using the "--with-http_perl_module" mode. The "Http_perl" module can be used to enable Nginx's nginxstatus function to monitor the current state of Nginx. Here is the installation process:
wget http://nginx.org/download/nginx-1.7.8.tar.gztar zxvf nginx-1.7. 8 . tar.gz CD nginx-1.7. 8 yum install gcc gcc-c++-y zlib zlib-devel pcre pcre-devel OpenSSL openssl-devel. /configure--with-http_stub_status_module--prefix=/opt/nginxmakemake Install
Installation is complete.
View Help for managing Nginx.
/opt/nginx/sbin/nginx-h
Later, the shell script can be written to add nginx to the service.
As already mentioned, PHP-FPM has been added to the PHP kernel after php5.3.3. Older versions of PHP-FPM are installed in patch mode. We install the latest version of php-5.6.3.
wget http://cn2.php.net/get/php-5.6.3.tar.gz/from/this/mirrortar zxvf php-5.6. 3 . tar.gz cd PHP-5.6. 3 . /configure--enable-fpm --with-mysqlmake make install/usr/local/sbin/php-fpm-HCP php.ini- Development /usr/local/php//usr/local/etc/php-fpm.conf. Default /usr/local/etc/php-fpm.confcp sapi/fpm/php-fpm/usr/local/bin
At this point, the PHP,PHP-FPM has been installed.
If the file does not exist, block Nginx from sending the request to the backendphp-0/usr/local/php/php.inicgi.fix_pathinfo=0
Start PHP-FPM:
/usr/local/bin/php-fpm View php-FPM supported startup options /usr/local/bin/php-fpm-h
Let Nginx support PHP:
Modify Nginx.conf, vim/opt/nginx/conf/nginx.conf
Location/ { root html; Index ~* \.php$ { fastcgi_index index.php; Fastcgi_pass 127.0. 0.1:9000; Include Fastcgi_params; Fastcgi_param script_filename $document _root$fastcgi_script_name; Fastcgi_param script_name $fastcgi _script_name;}
If the modification is not correct, 404 error will be reported.
Restart Nginx:
Sudo/usr/local/nginx/sbin/nginx-/usr/local/nginx/sbin/nginx
Problems that you may encounter
- Makefile was not generated when installing PHP configure.
There may be a lack of supported libraries, NCurse,libxml2 , or anything else to install with Yum.
- When testing nginx support PHP, 404 errors are reported.
The parameters passed to PHP-FPM by Nginx are incorrect.
Fastcgi_param script_filename $document _root$fastcgi_script_name;fastcgi_param script_name $ Fastcgi_script_name;
Configure the two parameters well, note the root HTML; OK.
LNMP Environment Construction