LNMP Server Environment Configuration (linux+nginx+mysql+php) _linux

Source: Internet
Author: User
Tags bz2 epoll fpm install php mysql version openssl php error openldap

I. Introduction
Nginx is a very lightweight HTTP server written by Russians. Nginx, pronounced "engine X", is a high-performance HTTP and reverse proxy server, and it is also an IMAP / POP3 / SMTP proxy server. Nginx was developed by Russian Igor Sysoev for the second most visited site in Russia, Rambler.ru, which has been running on this site for more than three years. Igor Sysoev uses a BSD-based license when building projects.
GinIn the case of high concurrent connections, Nginx is a good alternative to the Apache server. Nginx can also be used as a Layer 7 load balancing server. Nginx 0.8.46 + PHP 5.2.14 (FastCGI) can withstand more than 30,000 concurrent connections, which is equivalent to 10 times that of Apache in the same environment.

Nginx surpasses Apache's high performance and stability, making more and more websites using Nginx as a web server in China, including Sina Blog, Sina Podcast, NetEase News, Tencent, Sohu Blog and other portal channels, Video sharing sites such as 56.com, well-known forums such as Discuz! Official Forum, Shuimu Community, online game sites such as Shanda Online, Jinshan Xiaoyao.com, Douban, Renren, YUPOO Photo Album, Kingsoft Aiba, Xunlei Online and other emerging Web 2.0 sites .

Why is Nginx performance much higher than Apache? This is because Nginx uses the latest epoll (Linux 2.6 kernel) and kqueue (freebsd) network I / O models, while Apache uses the traditional select model. At present, Squid and Memcached, which can withstand high concurrent access under Linux, use the epoll network I / O model.
Handling a large number of connections to read and write, the select network I / O model used by Apache is very inefficient. The following uses an analogy to analyze the difference between the select model used by Apache and the epoll model used by Nginx:
Suppose you are studying in a university and you have a lot of rooms in your dormitory building. Your friends are coming to see you. The select version of the hostess will take your friends from room to room until they find you. The epoll version of the hostess will first write down the room number of each classmate. When your friend comes, you just need to tell your friend which room you live in. You do n’t have to bring your friends to find people in the building. If there are 10,000 people who are looking for their classmates who live in this building, the select version and the epoll version of the auntie who is more efficient are self-evident. Similarly, in a high-concurrency server, polling I / O is one of the most time-consuming operations. It is also very clear that the performance of select and epoll is higher.

   

 Nginx's official Chinese wiki: http://wiki.nginx.org/NginxChs

System environment

System platform: RHEL 5.4 (System requirements: Linux 2.6+ kernel)

Nginx version: nginx / 1.0.15

Mysql version: 5.1.35-log Source distribution

Php version: php-5.2.10

Third, installation preparation

1.Get related open source programs and install them

Other Linux distributions such as RedHat can find the RPM packages of these libraries from the installation CD. RedHat can be directly installed using the CentOS RPM package.
The following packages can be installed with rpm. If there are associated packages, install them together during installation.
gcc gcc-c ++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprog5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
If the above packages are installed, there is no need to install them again.

2.RPM package search website
http://rpm.pbone.net/
http://www.rpmfind.net/

http://code.google.com/p/zed-lnmp/

3.Nginx package preparation

The packages required by Nginx can be obtained from the following location, or you can search for it by remembering its name.
nginx-0.7.61.tar.gz
php-5.2.10.tar.gz
php-5.2.10-fpm-0.5.11.diff.gz
mysql-5.1.35.tar.gz
libiconv-1.13.tar.gz
libmcrypt-2.5.8.tar.gz
mcrypt-2.6.8.tar.gz
memcache-2.2.5.tgz
mhash-0.9.9.9.tar.gz
pcre-7.9.tar.gz
eaccelerator-0.9.5.3.tar.bz2
PDO_MYSQL-1.0.2.tgz
ImageMagick.tar.gz
imagick-2.2.2.tgz

Fourth, install PHP 5.2.10 (FastCGI mode)

Compile and install the required support libraries for PHP 5.2.10:

1. Install libiconv
Convert text between encodings and use it to handle conversions between Chinese encodings.
#tar zxvf libiconv-1.13.tar.gz
#cd libiconv-1.13 /
#. / configure --prefix = / usr / local
#make
#make install
cd ../

2. Install libmcrypt library to implement encryption function.
# tar zxvf libmcrypt-2.5.8.tar.gz
# cd libmcrypt-2.5.8 /
# ./configure
# make
# make install
# / sbin / ldconfig
# Note: Do not exit here.
# cd libltdl /
# ./configure --enable-ltdl-install
# make
# make install
# cd http://www.cnblogs.com/

3. Install mhash (Hash function library)
# tar zxvf mhash-0.9.9.9.tar.gz
# cd mhash-0.9.9.9 /
# ./configure
# make
# make install
# cd ../

ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1

4. Install mcrypt
# tar zxvf mcrypt-2.6.8.tar.gz
# cd mcrypt-2.6.8 /
# / sbin / ldconfig
#. / configure
# make
# make install
# cd ../

Note: The DG library requires an installation package, which can be installed using the rpm package to reduce time. Because PHP has integrated the GD library, the prerequisite support package should be installed in advance, such as zlib, png, jpeg, freetype, etc. If you want to use a tar package for installation, please refer to the related content of lamp.

Five, compile and install MySQL

Create mysql group, create mysql user and join mysql group
# groupadd mysql
# useradd mysql -g mysql
[root @ linux lnmp] # tar zxvf mysql-5.1.35.tar.gz
[root @ linux lnmp] # cd mysql-5.1.35
# ./configure --prefix = / usr / local / mysql
--without-debug
--with-extra-charsets = gbk
--with-extra-charsets = all
--enable-assembler
--with-pthread
--enable-thread-safe-client
--with-mysqld-ldflags = -all-static / * Compile mysqld without shared libraries * /
--with-client-ldflags = -all-static
--with-big-tables
--with-readline / * To install ncurses or tar package using rpm * /
--with-ssl / * To install openssl using rpm * /
--with-embedded-server
--enable-local-infile
--with-plugins = innobase
# make && make install

# / usr / local / mysql / bin / mysql_install_db --user = mysql
#Initialize the database as mysql
# cp ./support-files/mysql.server /etc/init.d/mysql
#Copy Mysql startup service to the system
# cp ./support-files/my-medium.cnf /etc/my.cnf
# chmod 755 /etc/init.d/mysql

# cd / usr / local / mysql / #Switch to the cd / usr / local / mysql / directory
# chown -R mysql. #Change the owner of the current directory to the mysql user
# chown -R mysql var #Modify the permissions of the database directory
# chgrp -R mysql. #Change the file of the mysql user in the current directory to the mysql group

# / usr / local / mysql / bin / mysqld_safe --user = mysql &
# / usr / local / mysql / bin / mysqladmin -u root password 'admin' #Set administrator password

[root @ linux html] # / usr / local / mysql / bin / mysql -u root -p #Test password entry
Enter password:
Welcome to the MySQL monitor. Commands end with; or \ g.
Your MySQL connection id is 5
Server version: 5.1.35-log Source distribution
Type 'help;' or '\ h' for help. Type '\ c' to clear the current input statement.

mysql> \ q / * Quit mysql * /

# chkconfig --add mysql #Add mysqld service to the system
# chkconfig mysql on #Open myslqd service
# service mysql start #Start Mysql
# / usr / local / mysql / bin / mysqladmin shutdown #Shut down the database

#View the opening of the mysql port
# netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID / P name
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2936 /
#Check whether to start:
#ps -ef | grep mysql
Note: During the configuration process, the overall configuration ideas from top to bottom, some of these functions can be used in the actual configuration process, mainly used in the test link.
The optimization part of Mysql is not given here, you need to refer to other materials.

Six, compile and install PHP

This place is the most important, because by default there is no feeling between Nginx and PHP. I have built Apache + PHP before. Apache + PHP compiles and generates module files. However, Nginx + PHP requires PHP to generate executable files. Therefore, we need to use fastcgi technology to achieve the integration of Nginx and PHP. As long as we install Just enable FastCGI. This time we installed PHP using not only FastCGI but also PHP-FPM. PHP-FPM is plainly a manager for managing FastCGI. It exists as a plug-in for PHP. It is necessary to use it when installing PHP. PHP-FPM needs to install PHP-FPM into PHP in the form of a patch, and PHP must be consistent with the PHP-FPM version, this is necessary, remember!

# tar zxvf php-5.2.10.tar.gz
# gzip -cd php-5.2.10-fpm-0.5.11.diff.gz | patch -d php-5.2.10 -p1

# Add php-5.2.10-fpm-0.5.11.diff.gz as a patch to php-5.2.10

# cd php-5.2.10 /
# ./configure --prefix = / usr / local / php
--with-config-file-path = / usr / local / php / etc
--with-mysql = / usr / local / mysql
--with-mysqli = / usr / local / mysql / bin / mysql_config
--with-iconv-dir = / usr / local
--with-freetype-dir
--with-jpeg-dir
--with-png-dir
--with-zlib
--with-gd
--enable-gd-native-ttf
--with-libxml-dir = / usr
--enable-xml
--disable-rpath
--enable-discard-path
--enable-safe-mode
--enable-bcmath
--enable-shmop
--enable-sysvsem
--enable-inline-optimization
--with-curl
--with-curlwrappers
--enable-mbregex
--enable-fastcgi
--enable-fpm
--enable-force-cgi-redirect
--enable-mbstring
--with-mcrypt
--with-openssl
--with-mhash
--enable-pcntl
--enable-sockets
--with-ldap
--with-ldap-sasl
--with-xmlrpc
--enable-zip
--enable-soap
--without-pear

Note: For Nginx + PHP integration, --enable-fastcgi and --enable-fpm must be enabled during installation. What these two options do is described above. After execution, the system will prompt --- enable-fastcgi is an unknown option, we do not need to bother.

#Note: Be sure to add the following parameters when making to succeed.
# make ZEND_EXTRA_LIBS = '-liconv'
# make install
# cp php.ini-dist /usr/local/php/etc/php.ini
# cd ../

Note: In the installation process, a tar package and rpm mixed installation are used, and there is indeed a lot of trouble in specifying the library. If you use rpm installation, you don't need to specify the location of the support package. For tar installation, you need to specify the installation location.

Seven, compile and install PHP5 extension module
1. Install memcache
# tar zxvf memcache-2.2.5.tgz
# cd memcache-2.2.5 /
# / usr / local / php / bin / phpize
# ./configure --with-php-config = / usr / local / php / bin / php-config
# make
# make install
# Description: The location of the memcache library
Installing shared extensions:
/ usr / local / php / lib / php / extensions / no-debug-non-zts-20060613 /
# cd ..

2. Install eaccelerator php acceleration
# tar jxvf eaccelerator-0.9.5.3.tar.bz2
# cd eaccelerator-0.9.5.3 /
# / usr / local / php / bin / phpize
# ./configure --enable-eaccelerator = shared --with-php-config = / usr / local / php / bin / php-config
# make
# make install
Installing shared extensions:
/ usr / local / php / lib / php / extensions / no-debug-non-zts-20060613 /
# cd ../

3. Install PDO_MYSQL (database connection support)
# tar zxvf PDO_MYSQL-1.0.2.tgz
# cd PDO_MYSQL-1.0.2 /
# / usr / local / php / bin / phpize
#. / configure --with-php-config = / usr / local / php / bin / php-config
--with-pdo-mysql = / usr / local / mysql
# make
# make install
Installing shared extensions:
/ usr / local / php / lib / php / extensions / no-debug-non-zts-20060613 /
# cd ../

4.Install ImageMagick is a very powerful image processing function similar to GD under Linux.
# tar zxvf ImageMagick.tar.gz
# cd ImageMagick-6.5.1-2 /
#. / configure
# make
# make install
# cd ../

5. Install imagick (the channel connecting PHP and ImageMagick)
# tar zxvf imagick-2.2.2.tgz
# cd imagick-2.2.2 /
# / usr / local / php / bin / phpize
# ./configure --with-php-config = / usr / local / php / bin / php-config
# make
# make install
Installing shared extensions:
/ usr / local / php / lib / php / extensions / no-debug-non-zts-20060613 /
# cd ../

6.Modify the php.ini file, so that PHP supports extended functions
vi /usr/local/php/etc/php.ini
Find
extension_dir = "./"
change into
extension_dir = "/ usr / local / php / lib / php / extensions / no-debug-non-zts-20060613 /"
Add the following lines after this line and save:
extension = "memcache.so"
extension = "pdo_mysql.so"
extension = "imagick.so"

Look for output_buffering = Off
Modify to output_buffering = On

7. Configure eAccelerator to accelerate PHP:
mkdir -p / usr / local / eaccelerator_cache
vi /usr/local/php/etc/php.ini

To the end of the configuration file, stick the following:
[eaccelerator]
zend_extension = "/ usr / local / php / lib / php / extensions / no-debug-non-zts-20060613 / eaccelerator.so"
eaccelerator.shm_size = "64"
eaccelerator.cache_dir = "/ usr / local / eaccelerator_cache"
eaccelerator.enable = "1"
eaccelerator.optimizer = "1"
eaccelerator.check_mtime = "1"
eaccelerator.debug = "0"
eaccelerator.filter = ""
eaccelerator.shm_max = "0"
eaccelerator.shm_ttl = "3600"
eaccelerator.shm_prune_period = "3600"
eaccelerator.shm_only = "0"
eaccelerator.compress = "1"
eaccelerator.compress_level = "9"

Eight, PHP-fpm configuration
1.Create php-fpm configuration file
php-fpm is a FastCGI management patch for PHP that can smoothly change php.ini configuration without restarting php-cgi:
Create the php-fpm.conf file in the / usr / local / php / etc / directory. You can also modify it based on the original.
If you install Nginx + PHP for program debugging
Please the following
<value name = "display_errors"> 0 </ value> to
<value name = "display_errors"> 1 </ value> in order to display PHP error messages, otherwise, Nginx will report a blank error page with a status of 500.
Note: Create www users and groups. If you create them here, you don't need to create them.

# / usr / sbin / groupadd www -g 48
# / usr / sbin / useradd -u 48 -g www www

rm -f /usr/local/php/etc/php-fpm.conf
vi /usr/local/php/etc/php-fpm.conf
#################################
#Enter or modify to the following:
#################################
<? xml version = "1.0"?>
<configuration>
<section name = "global_options">
<value name = "pid_file"> / usr / local / php / logs / php-fpm.pid </ value>
<value name ="error_log"> / usr / local / php / logs / php-fpm.log </ value>
<value name = "log_level"> notice </ value>
<value name = "emergency_restart_threshold"> 10 </ value>
<value name = "emergency_restart_interval"> 1m </ value>
<value name = "process_control_timeout"> 5s </ value>
<value name = "daemonize"> yes </ value>
</ section>
<workers>
<section name = "pool">
<value name = "name"> default </ value>
<value name = "listen_address"> 127.0.0.1:9000 </ value>
<value name = "listen_options">
<value name = "backlog">-1 </ value>
<value name = "owner"> </ value>
<value name = "group"> </ value>
<value name = "mode"> 0666 </ value>
</ value>
<value name = "php_defines">
<value name = "sendmail_path"> / usr / sbin / sendmail -t -i </ value>
<value name = "display_errors"> 1 </ value>
</ value>
<value name = "user"> www </ value>
<value name = "group"> www </ value>
<value name = "pm">
<value name = "style"> static </ value>
<value name = "max_children"> 128 </ value>
<value name = "apache_like">
<value name = "StartServers"> 20 </ value>
<value name = "MinSpareServers"> 5 </ value>
<value name = "MaxSpareServers"> 35 </ value>
</ value>
</ value>
<value name = "request_terminate_timeout"> 0s </ value>
<value name = "request_slowlog_timeout"> 0s </ value>
<value name = "slowlog"> logs / slow.log </ value>
<value name = "rlimit_files"> 51200 </ value>
<value name = "rlimit_core"> 0 </ value>
<value name = "chroot"> </ value>
<value name = "chdir"> </ value>
<value name = "catch_workers_output"> yes </ value>
<value name = "max_requests"> 500 </ value>
<value name = "allowed_clients"> 127.0.0.1 </ value>
<value name = "environment">
<value name = "HOSTNAME"> $ HOSTNAME </ value>
<value name = "PATH"> / usr / local / bin: / usr / bin: / bin </ value>
<value name = "TMP"> / tmp </ value>
<value name = "TMPDIR"> / tmp </ value>
<value name = "TEMP"> / tmp </ value>
<value name = "OSTYPE"> $ OSTYPE </ value>
<value name = "MACHTYPE"> $ MACHTYPE </ value>
<value name = "MALLOC_CHECK _"> 2 </ value>
</ value>
</ section>
</ workers>
</ configuration>

2.php-fpm startup and management
/ usr / local / php / sbin / php-fpm start
Note: / usr / local / php / sbin / php-fpm has other parameters, including:
start | stop | quit | restart | reload | logrotate, modify php.ini without restarting php-cgi, reload the configuration file and use reload to keep the fastcgi process of php running continuously and reload php ini.

Nginx installation
1.nginx installation
Nginx is just a web server, with fastcgi implemented by php technology to improve performance.

1. Install the rewrite module support package pcre library:

pcre is the regular expression used by perl, the purpose is to make the installed software support regular expressions. By default, Nginx only handles 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 leave * .PHP to PHP for processing .

# tar zxvf pcre-7.8.tar.gz
# cd pcre-7.8 /
# ./configure
# make && make install
cd ../

2. Install Nginx
Note: Create www user group and www user. If php-fpm has not been created before, you need to create it here.
# / usr / sbin / groupadd www
# / usr / sbin / useradd -g www www

# tar zxvf nginx-1.0.15.tar.gz
# cd nginx-1.0.15 /
#. / configure --user = www --group = www --prefix = / usr / local / nginx --with-http_stub_status_module --with-http_ssl_module

  nginx path prefix: "/ usr / local / nginx"
  nginx binary file: "/ usr / local / nginx / sbin / nginx"
  nginx configuration prefix: "/ usr / local / nginx / conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"


# make && make install
# cd ../

3. After Nginx is installed, there is only one program file. It does not provide various management programs. It uses parameters and system signal mechanism to control the Nginx process itself.
Nginx parameters include the following:
-c <path_to_config>: Use the specified configuration file instead of nginx.conf in the conf directory.
-t: Tests whether the configuration file is correct. This command is very important when the configuration needs to be reloaded at runtime. It is used to detect whether the modified configuration file has a syntax error.
-v: Display nginx version number.
-V: Display the version number of nginx, compilation environment information, and compile-time parameters.
For example, if we want to test whether a configuration file is written correctly, we can use the following command
sbin / nginx -t -c conf / nginx.conf

Ten, nginx configuration
1. Create the nginx.conf file in the / usr / local / nginx / conf / directory:
rm -f /usr/local/nginx/conf/nginx.conf
vi /usr/local/nginx/conf/nginx.conf
==========================================
nginx.conf is the configuration file for nginx web server
==========================================
user www www; / * users and groups that start nginx service * /
worker_processes 1; / * Start worker processes for nginx service * /
error_log logs / nginx_error.log crit; / * error log, and level * /
pid /usr/local/nginx/nginx.pid; / * nginx service process PID * /

worker_rlimit_nofile 51200;

events
{
 use epoll; / * Working mode * /
 worker_connections 51200; / * Maximum number of simultaneous connections allowed per process * /
}

http
{
 include mime.types;
 default_type application / octet-stream;

 #charset gb2312;
 server_names_hash_bucket_size 128;
 client_header_buffer_size 32k;
 large_client_header_buffers 4 32k;
 
 sendfile on;
 tcp_nopush on;
 keepalive_timeout 60;
 tcp_nodelay on;

 fastcgi_connect_timeout 300;
 fastcgi_send_timeout 300;
 fastcgi_read_timeout 300;
 fastcgi_buffer_size 64k;
 fastcgi_buffers 4 64k;
 fastcgi_busy_buffers_size 128k;
 fastcgi_temp_file_write_size 128k;

 gzip on;
 gzip_min_length 1k;
 gzip_buffers 4 16k;
 gzip_http_version 1.0;
 gzip_comp_level 2;
 gzip_types text / plain application / x-javascript text / css application / xml;
 gzip_vary on;

 #limit_zone crawler $ binary_remote_addr 10m;

 server
 {
   listen 80; / * listen port * /
   server_name localhost; / * server name * /
   index index.html index.htm index.php; / * default homepage name * /
   root / usr / local / nginx / html; / * Web site root directory, you can also use the following content * /
Use relative path, comment part below * /
   #location / {
   # root html;
   # index index.html index.htm;
   #}

   #limit_conn crawler 20;
  
   #Support PHP through FastCGI, php pages are processed by fastcgi proxy, this is also an application of reverse proxy, here can be jsp / asp and other scripts.

   #Nginx forwards the PHP request to PHP through the local port 9000. PHP itself listens to data from the local port 9000. Nginx and PHP complete the data request through the local port 9000.

   location ~. * \. (php | php5)? $
   {
     #fastcgi_pass unix: /tmp/php-cgi.sock;
     fastcgi_pass 127.0.0.1:9000; / * fastcgi listening port * /
     fastcgi_index index.php;
     include fcgi.conf; / * fastcgi configuration file, modify to the following * /
   }
  
   #For a certain type of file, set the expiration time. Static pages are usually set a bit longer.
   #Static file, nginx handles it by itself
   location ~. * \. (gif | jpg | jpeg | png | bmp | swf | js | css) $
   {
     expires 30d;
   }

#Log format
   log_format access '$ remote_addr-$ remote_user [$ time_local] "$ request"'
             '$ status $ body_bytes_sent "$ http_referer"'
             '"$ http_user_agent" $ http_x_forwarded_for';
   access_log logs / access.log access;
     }
}
Note: The above configuration files are only basic configuration files. To implement other functions, you need to modify them.

2. Create the fcgi.conf file in the / usr / local / nginx / conf / directory:
Note: You can paste the following directly.
vi /usr/local/nginx/conf/fcgi.conf
fastcgi_param GATEWAY_INTERFACE CGI / 1.1;
fastcgi_param SERVER_SOFTWARE nginx;

fastcgi_param QUERY_STRING $ query_string;
fastcgi_param REQUEST_METHOD $ request_method;
fastcgi_param CONTENT_TYPE $ content_type;
fastcgi_param CONTENT_LENGTH $ content_length;

fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
fastcgi_param SCRIPT_NAME $ fastcgi_script_name;
fastcgi_param REQUEST_URI $ request_uri;
fastcgi_param DOCUMENT_URI $ document_uri;
fastcgi_param DOCUMENT_ROOT $ document_root;
fastcgi_param SERVER_PROTOCOL $ server_protocol;

fastcgi_param REMOTE_ADDR $ remote_addr;
fastcgi_param REMOTE_PORT $ remote_port;
fastcgi_param SERVER_ADDR $ server_addr;
fastcgi_param SERVER_PORT $ server_port;
fastcgi_param SERVER_NAME $ server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;

Eleven, nginx startup and management
1. Start nginx
/ usr / local / nginx / sbin / nginx

2. Test nginx configuration file
After modifying the /usr/local/nginx/conf/nginx.conf configuration file, run the following command to check whether the configuration file is correct:
# / usr / local / nginx / sbin / nginx -t
If the following two lines of information appear on the screen, the configuration file is correct:
the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
the configuration file /usr/local/nginx/conf/nginx.conf was tested successfully

3. View Nginx main process number
ps -ef | grep "nginx: master process" | grep -v "grep" | awk -F '' '{print $ 2}'
The screen displays the Nginx main process number, for example:
6302
At this time, execute the following command to make the modified Nginx configuration file take effect:
kill -HUP 6302
Or don't need to bother to find Nginx's Pid file:
kill -HUP `cat / usr / local / nginx / logs / nginx.pid`

4. Configure Nginx + PHP to start automatically at boot
vi /etc/rc.local
Add the following:
ulimit -SHn 51200
/ usr / local / php / sbin / php-fpm start
/ usr / local / nginx / sbin / nginx

5. Test nginx
vi /usr/local/nginx/html/phpinfo.php
<?
phpinfo ();

?>

6. Test results



phpinfo ()



 

Install LAMP (Linux + Apache + Mysql + Php) environment under source code under CentOS 6.3 http://www.jb51.net/article/52418.htm

Large-Scale Price Reduction
  • 59% Max. and 23% Avg.
  • Price Reduction for Core Products
  • Price Reduction in Multiple Regions
undefined. /
Connect with us on Discord
  • Secure, anonymous group chat without disturbance
  • Stay updated on campaigns, new products, and more
  • Support for all your questions
undefined. /
Free Tier
  • Start free from ECS to Big Data
  • Get Started in 3 Simple Steps
  • Try ECS t5 1C1G
undefined. /

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.