How to install Nginx php environment configuration

Source: Internet
Author: User
Tags chmod fpm install php ini mysql tutorial php tutorial port number

Nginx 0.7.x + php Tutorial 5.2.10 (fastcgi) build a web server that is 10 times better than apache (version 5th)
Original article address
Http://blog.s135.com/nginx_php_v5/
Because the compilation process and wait time are cumbersome, I wrote a fully automated shell script. This script can be modified at will. For reprinting, please indicate the source.
This article is the second version of this series.
1. Log cutting
2. Install yum or rpm intelligently
Download address
Note: If the yum source cannot be used, place it on the system disc and a single dvd. If multiple discs are used, find all the rpm packages to be installed on the disc and copy them to a directory, and modify
Umount/dev/cdrom
Mkdir/mnt/cdrom _ $
Mount/dev/cdrom/mnt/cdrom _ $
Cd/mnt/cdrom _ $/
Rpmpath = $ (find $ (pwd)-name 'Kernel-2 *')
Rpmpath =$ {rpmpath % /*}
Cd $ {rpmpath}
Is
Cd yourdir
Yourdir stores the root path of all your packages
After download
# Unzip install.zip
# Chmod + x install. sh
#./Install. sh
Run the command as root.
Note: many parameters of this script are configured based on the large load server. If a virtual machine is used for experiments, some services may fail to be started. For example, the parameters in the mysql tutorial require large memory support, modify the configuration parameters manually.

This is what I found from my website.

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.
Experimental environment ubuntu
1. Install linux nginx
 
  1. # Tar-zxvf nginx-0.8.5.tar.gz
  2. # Cd nginx-0.8.5
  3. #./Configure -- prefix =/usr/local/nginx-with-http_stub_status_module-with-http_ssl_module-with-http_gzip_static_module-with-http_ssl_module (installation path and
  4. Required dependency package) -- prefix (installation path)
  5. # 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
Or start nginx with/usr/local/nginx/sbin/nginx
/Usr/local/nginx/sbin/nginx-s quit exit nginx
/Usr/local/nginx/sbin/nginx-s reload
You also need to installApt-get install spawn-fcgi
Run the following command every time: tell php that the corresponding port number is the same as that of java.
Spawn-fcgi-a 127.0.0.1-p 9000-c 5-u www-data-g www-data-f
/Usr/bin/php-cgi (must be dropped)
2,Spawn-fcgi, used to start the fastcgi mode of php
(The wget method is used for linux download packages, or you can directly install the apt-get install spawn-fcgi method)
Wget http://www.lighttpd.net/download/spawn-fcgi-1.6.3.tar.gz
Tar-zxf spawn-fcgi-1.6.3.tar.gz
Cd spawn-fcgi-1.6.3
./Configure-bindir =/usr/bin-libdir =/usr/lib-prefix =/etc
Make & make install
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 tutorial 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. # Vim/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 32 k;
  14. Large_client_header_buffers 4 32 k;
  15. Client_max_body_size 8 m;
 
  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 64 k;
  9. Fastcgi_buffers 4 64 k;
  10. Fastcgi_busy_buffers_size 128 k;
  11. Fastcgi_temp_file_write_size 128 k;
  12. Gzip on;
  13. Gzip_min_length 1 k;
  14. Gzip_buffers 4 16 k;
  15. Gzip_http_version 1.0;
  16. Gzip_comp_level 2;
  17. Gzip_types text/plain application/x-webpage effects text/css tutorial application/xml;
  18. Gzip_vary on;
  19.  
  20. Server {
  21. Listen 80;
  22. Server_name www.bbb.com;
  23. Root/www/uuweb;
  24. Index index.html index.htm index. php;
  25. Location ~ . *. (Php | php5 )? $ {Or location /{
  26. I don't know what's going on. I can only use the last css.
  27. Root/www/uuweb;
  28. Fastcgi_pass 127.0.0.1: 9000;
  29. Fastcgi_index index. php;
  30. Fastcgi_param script_filename/www/uuweb $ fastcgi_script_name;
  31. Include fastcgi_params ;}
  32. # Location ~ . *. (Gif | jpg | jpeg | png | bmp | swf) $
  33. # {Expires 30d ;}
  34. # Location ~ . *. (Js | css )? $
  35. # {Expires 1 h ;}
  36. Log_format access' $ remote_addr-$ remote_user [$ time_local] "$ request "'
  37. '$ Status $ body_bytes_sent "$ http_referer "'
  38. '"$ Http_user_agent" $ http_x_forwarded_for ';
  39. 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/www/uuweb $ fastcgi_script_name; the directory test configuration file saved on the php web page:
#/Usr/local/nginx/sbin/nginx-t

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.