Linux Nginx installation configuration file supports PHP

Source: Internet
Author: User

Before giving you a detailed introduction to Linux Nginx, let's first get to know about Linux Nginx and then give a full introduction to Linux Nginx. Using Linux Nginx to build a high-performance Web Environment Linux Nginx ("engine x") is a high-performance HTTP and reverse proxy server and an IMAP/POP3/SMTP proxy server. Linux Nginx is developed by the Rambler.ru site with the highest access volume in Russia as Igor Sysoev. It has been running on this site for more than two and a half years. Igor publishes source code in the form of a class BSD license.

As Linux Nginx outperforms Apache's high performance and stability, more and more websites are using Linux Nginx as Web servers in China, including Sina Blog, Sina podcast, Netease news and other portal website channels, discuz! Well-known forums such as official forums and the Shui Mu community, and emerging Web 2.0 websites such as Douban, YUPOO album, domestic SNS, and thunder online.

Lab environment Centos4.5

 
 
  1. Pcre-7.8.tar.gz Regular Expression: ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/
  2. Nginx-0.7.26.tar: http://www.nginx.net/
  3. Php-5.2.6.tar.bz2: http://www.php.net/releases/
  4. Php-5.2.6-fpm-0.5.9.diff.gz
  5. Php-fpm is a FastCGI management patch for PHP to smoothly change the php. ini configuration without restarting php-cgi: http://php-fpm.anight.org/
  6. Note: For PHP scripts and fpmscripts, mysql-5.0.67.tar.gz
  7. Discuz! _6.0.0_ SC _UTF8.zip

1. Install pcre

 
 
  1. # tar -zxvf pcre-7.8.tar.gz  
  2. # cd pcre-7.8  
  3. # ./configure  
  4. # make && make install 

2. install Linux Nginx

 
 
  1. # tar -zxvf nginx-0.7.26.tar.gz  
  2. # cd nginx-0.7.26  
  3. # ./configure --prefix=/usr/local/nginx  
  4. # make && make install 
 
 
  1. Start nginx #/usr/local/nginx/sbin/nginx
  2. Stop nginx # kill-QUIT 'cat/usr/local/nginx/logs/nginx. pid'
  3. Restart nginxkill-HUP 'cat/usr/local/nginx/logs/nginx. pid'
  4. Add to auto start # echo "/usr/local/nginx/sbin/nginx">>/Etc/rc. local

3. Install mysql

 
 
  1. # tar -zxvf mysql-5.0.67.tar.gz  
  2. # cd mysql-5.0.67  
  3. # groupadd mysql  
  4. # useradd -g mysql -s /sbin/nologin -M mysql  
  5. # ./configure --prefix=/usr/local/mysql --with-charset=gbk --with-extra-charset=all --enable-hread-safe-client 
    --enable-local-infile --with-low-memory  
  6. # make && make install  
  7. # cp support-files/my-medium.cnf  /etc/my.cnf  
  8. # chown -R mysql.mysql /usr/local/mysql/  
  9. # /usr/local/mysql/bin/mysql_install_db --user=mysql 
  10. # chown -R root.root /usr/local/mysql/  
  11. # chown -R mysql.mysql /usr/local/mysql/var/ 

Start the Database Service and add it to auto-start

 
 
  1. # /usr/local/mysql/bin/mysqld_safe --user=mysql &  
  2. #cp  support-files/mysql.server  /etc/rc.d/init.d/mysqld  
  3. #chmod  755  /etc/rc.d/init.d/mysqld 

Add to auto start service queue:

 
 
  1. # Chkconfig -- add mysqld
  2. # Chkconfig -- level 345 mysqld on add root Password
  3. #/Usr/local/mysql/bin/mysqladmin-u root password "123456"
  4. Test: #/usr/local/mysql/bin/mysql-u root-p enter password: 123456 to check whether the database can be accessed.

Configure the library file search path

 
 
  1. # Echo "/usr/local/mysql/lib/mysql">>/Etc/ld. so. conf
  2. # Ldconfig
  3. # Ldconfig-v
  4. Add/usr/local/mysql/bin to the environment variable PATH.
  5. # Echo "exportPATH= $ PATH:/usr/local/mysql/bin">>/Etc/profile
  6. # Source/etc/profile

4. install PHP

An executable file is generated here, which is different from apache. When combined with apache, a dynamic library is generated.

 
 
  1. # tar -jxvf php-5.2.6.tar.bz2  
  2. # gzip -cd php-5.2.6-fpm-0.5.9.diff.gz |patch -d php-5.2.6 -p1  
  3. # cd php-5.2.6  
  4. # ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --enable-fastcgi --enable-fpm   
  5. --with-config-file-path=/usr/local/php/etc --enable-force-cgi-redirect  
  6. # make && make install  
  7. # cp php.ini-recommended /usr/local/php/etc/php.ini  
  8. # vi /usr/local/php/php-fpm.conf 
 
 
  1. (1)<Value Name="Listen_address">127.0.0.1: 9000</Value>Change<Value Name="Listen_address">IP: 9000</Value>
    // Use the default 127.0.0.1 on the local machine
  2. (2) Remove comments and modify the following two lines.
  3. <Value Name="Sendmail_path">/Usr/sbin/sendmail-t-I</Value> 
  4. <Value Name="Display_errors">1</Value> 
  5. (3)<Value Name="User">Nobody</Value>// Comment out
  6. (4)<Value Name="Group">Nobody</Value>// Comment out
  7. (5)<Value Name="Allowed_clients">127.0.0.1</Value>// For a PC that can be connected, 127.0.0.1 is used on the local machine.

Start php-fpm #/usr/local/php/sbin/php-fpm start and add it to self-start # echo "/usr/local/php/sbin/php-fpm start"> /etc/rc. local

5. modify the configuration file of Linux Nginx and support PHP

 
 
  1. # vi /usr/local/nginx/conf/nginx.conf  
  2. user  nobody;  
  3. worker_processes  8;  
  4. pid  /usr/local/nginx/logs/nginx.pid;  
  5. worker_rlimit_nofile 1024;  
  6. events  
  7. {use epoll;  
  8. worker_connections 1024;}  
  9. http{  
  10. include       mime.types;  
  11. default_type  application/octet-stream;  
  12. server_names_hash_bucket_size 128;  
  13. client_header_buffer_size 32k;  
  14. large_client_header_buffers 4 32k;  
  15. client_max_body_size 8m; 
 
 
  1. sendfile on;  
  2. tcp_nopush     on;  
  3. keepalive_timeout 60;  
  4. tcp_nodelay on;  
  5. fastcgi_connect_timeout 300;  
  6. fastcgi_send_timeout 300;  
  7. fastcgi_read_timeout 300;  
  8. fastcgi_buffer_size 64k;  
  9. fastcgi_buffers 4 64k;  
  10. fastcgi_busy_buffers_size 128k;  
  11. fastcgi_temp_file_write_size 128k;  
  12. gzip on;  
  13. gzip_min_length  1k;  
  14. gzip_buffers     4 16k;  
  15. gzip_http_version 1.0;  
  16. gzip_comp_level 2;  
  17. gzip_types       text/plain application/x-javascript text/css application/xml;  
  18. gzip_vary on;  
  19.  
  20. server {  
  21. listen       80;  
  22. server_name  www.bbb.com;  
  23. root   /var/www/blog;  
  24. index  index.html index.htm index.php;  
  25. location ~ .*\.(php|php5)?$ {  
  26. root           html;  
  27. fastcgi_pass   127.0.0.1:9000;      
  28. fastcgi_index  index.php;  
  29. fastcgi_param  SCRIPT_FILENAME  /var/www/blog$fastcgi_script_name;  
  30. include        fastcgi_params;}  
  31. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$  
  32. {expires      30d;}  
  33. location ~ .*\.(js|css)?$  
  34. {expires      1h;}     
  35. log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '  
  36. '$status $body_bytes_sent "$http_referer" '  
  37. '"$http_user_agent" $http_x_forwarded_for';  
  38. access_log  /var/logs/access.log  access;}} 

Note: The server part is the PHP virtual host 127.0.0.1: 9000 is the fastcgi PC. Here I use the local/var/www/blog $ fastcgi_script_name; the directory test configuration file saved on the PHP web page:
#/Usr/local/nginx/sbin/nginx-t

6. Optimize Linux Kernel Parameters

 
 
  1. # Vi/etc/sysctl. conf
  2. Add the following content at the end:
  3. Net. ipv4.tcp _ fin_timeout=30 
  4. Net. ipv4.tcp _ keepalive_time=300 
  5. Net. ipv4.tcp _ syncookies=1 
  6. Net. ipv4.tcp _ tw_reuse=1 
  7. Net. ipv4.tcp _ tw_recycle=1 
  8. Net. ipv4.ip _ local_port_range=500065000

Make the configuration take effect immediately: #/sbin/sysctl-p.

  1. Nginx. conf configuration in Linux is highly efficient
  2. Install and compile MySQL 5.1.34 extension library and Php Web server in Linux Nginx
  3. View the default Linux samba version.
  4. Linux mounting Windows partition Disk
  5. Linux YUM is built on an ftp server as the source

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.