1-minute installation of the latest CentOS + Nginx + PHP-FPM + MySQL

Source: Internet
Author: User
Tags apc gpg tidy epel repo

PHP 5.3.1

MySQL 5.0.89

Nginx 0.8.33 or 0.7.65 (optional)

Now, we can do this quickly and automatically.CentOS + Nginx + PHP-FPM + MySQLInstalled

This is much better than what one-click installation package is available on the Internet. It is strongly recommended that this installation method be suitable for all cainiao and experts.

It's hard to compile and install all the source code used on my server.

I have installed some common extensions including PHP, PDO, eaccelerator, memcache, and tidy.

Create a repo first

  
  
  1. # vi /etc/yum.repos.d/centos.21andy.com.repo 
 

Add the following content

 
 
  1. [21Andy.com]  
  2. name=21Andy.com Packages for Enterprise Linux 5 - $basearch  
  3. baseurl=http://www.21andy.com/centos/5/$basearch/  
  4. enabled=1 
  5. gpgcheck=0 
  6. protect=1 

Enable EPEL repo

I386

 
 
  1. rpm -ihv
  2.  http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm 

X86_64

 
 
  1. rpm -ihv   
  2. http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm  

Import key

 
 
  1. rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL  

All right, one-click Installation

 
 
  1. # yum install nginx php-fpm mysql-server  

If you want to use the latest stable version of nginx 0.7.65, replace yum-y install nginx with yum-y install nginx-stable.

More complete installation

 
 
  1. Yum-y update
  2. Yum-y mysql-server
  3. Service mysqld start
  4. Mysqladmin-u root password root
  5. Service mysqld stop
  6. Yum-y install nginx php-fpm
  7. Php-cli php-pdo php-mysql php-mcrypt php-mbstring
  8. Php-gd php-tidy php-xml php-xmlrpc
  9. Php-pear php-pecl-memcache php-eaccelerator
  10. # APC conflicts with eAccelerator. Select 2 and select 1.
  11. Yum-y install php-pecl-apc

Let's take a look at my complete installation.

Yum-y install nginx mysql-server php-fpm php-cli php-pdo php-mysql php-mcrypt php-mbstring php-gd php-tidy php-xml php-xmlrpc php- pear php-pecl-memcache php-eaccelerator

Installation result, fully automated

 
 
  1. Dependencies Resolved 
  2. ==========================================================  
  3. Package Arch Version Repository Size 
  4. ==========================================================  
  5. Installing:  
  6. mysql x86_64 5.0.89-1.el5 21Andy.com 3.5 M  
  7. mysql-server x86_64 5.0.89-1.el5 21Andy.com 10 M  
  8. nginx x86_64 0.8.33-3.el5 21Andy.com 422 k  
  9. php-cli x86_64 5.3.1-2.el5 21Andy.com 2.4 M  
  10. php-eaccelerator x86_64 2:0.9.6-1.el5 21Andy.com 118 k  
  11. php-fpm x86_64 5.3.1-2.el5 21Andy.com 1.2 M  
  12. php-gd x86_64 5.3.1-2.el5 21Andy.com 110 k  
  13. php-mbstring x86_64 5.3.1-2.el5 21Andy.com 1.1 M  
  14. php-mcrypt x86_64 5.3.1-2.el5 21Andy.com 27 k  
  15. php-mysql x86_64 5.3.1-2.el5 21Andy.com 84 k  
  16. php-pdo x86_64 5.3.1-2.el5 21Andy.com 91 k  
  17. php-pear noarch 1:1.9.0-1.el5 21Andy.com 420 k  
  18. php-pecl-memcache x86_64 2.2.5-3.el5 21Andy.com 44 k  
  19. php-tidy x86_64 5.3.1-2.el5 21Andy.com 31 k  
  20. php-xml x86_64 5.3.1-2.el5 21Andy.com 115 k  
  21. php-xmlrpc x86_64 5.3.1-2.el5 21Andy.com 48 k  
  22. Installing for dependencies:  
  23. gmp x86_64 4.1.4-10.el5 base 201 k  
  24. libXaw x86_64 1.0.2-8.1 base 329 k  
  25. libXmu x86_64 1.0.2-5 base 63 k  
  26. libXpm x86_64 3.5.5-3 base 44 k  
  27. libedit x86_64 2.11-2.20080712cvs.el5 epel 80 k  
  28. libmcrypt x86_64 2.5.8-4.el5.centos extras 105 k  
  29. libtidy x86_64 0.99.0-14.20070615.el5 epel 140 k  
  30. php-common x86_64 5.3.1-2.el5 21Andy.com 554 k  
  31. sqlite2 x86_64 2.8.17-5.el5 21Andy.com 165 k  
  32. t1lib x86_64 5.1.1-7.el5 epel 208 k  
  33. Updating for dependencies:  
  34. libevent x86_64 1.4.12-1.el5 21Andy.com 129 k  
  35. Transaction Summary 
  36. ==========================================================  
  37. Install 26 Package(s)  
  38. Update 1 Package(s)  
  39. Remove 0 Package(s  

Last as longYum-y updateIt's all the latest

Don't forget to start

 
 
  1. chkconfig --level 345 mysqld on  
  2. chkconfig --level 345 php-fpm on  
  3. chkconfig --level 345 nginx on  

Let's take a look at the strong results of my virtual machine testing.

Http://www.21andy.com/blog/20100219/1703.html

Supplement: All the configuration files are under the/etc directory, including the nginx, php-fpm, and mysql configuration files. Please find your own settings. The following is an example of my nginx configuration.

Create a new/WwwDirectories, websites, and logs are all stored here.

Do not forget to create a log storage directory, which is used by access_log in the configuration file./Www/logs

Note: fastcgi_params must be added to this line.

# Vim/etc/nginx/fastcgi_params

  
 
  1. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;  

# Vi/etc/nginx. conf

 
 
  1. User nobody;
  2.  
  3. Worker_processes 8; # Here, based on your CPU and memory configuration, set both 2 and 10 OK
  4.  
  5. Error_log/Www/logs/nginx_error.log crit;
  6.  
  7. Pid/usr/local/nginx/logs/nginx. pid;
  8.  
  9. # Specifies the valueForMaximum file descriptors that can be opened by this process.
  10. Worker_rlimit_nofile 51200;
  11.  
  12. Events {
  13. UseEpoll;
  14. Worker_connections 51200;
  15. }
  16.  
  17. Http {
  18. IncludeMime. types;
  19. Default_type application/octet-stream;
  20.  
  21. # Charse gb2312; # default encoding, which can be left unspecified
  22.  
  23. Server_names_hash_bucket_size 128;
  24. Client_header_buffer_size 16 k;
  25. Large_client_header_buffers 4 16 k;
  26. Client_max_body_size 8 m;
  27.  
  28. Sendfile on;
  29. Tcp_nopush on;
  30.  
  31. Keepalive_timeout 60;
  32.  
  33. Tcp_nodelay on;
  34.  
  35. Fastcgi_connect_timeout 300;
  36. Fastcgi_send_timeout 300;
  37. Fastcgi_read_timeout 300;
  38. Fastcgi_buffer_size 64 k;
  39. Fastcgi_buffers 4 64 k;
  40. Fastcgi_busy_buffers_size 128 k;
  41. Fastcgi_temp_file_write_size 128 k;
  42.  
  43. Gzip on;
  44. Gzip_min_length 1 k;
  45. Gzip_buffers 4 16 k;
  46. Gzip_http_version 1.0;
  47. Gzip_comp_level 5;
  48. Gzip_types text/plain text/javascript application/x-javascript text/css application/xml;
  49. Gzip_vary on;
  50.  
  51. # Limit_zone crawler$ Binary_remote_addr10 m;
  52. Server {
  53. Listen 80;
  54. Server_name localhost;
  55. Root/www;
  56. Location/status {
  57. Stub_status on;
  58. Access_log off;
  59. }
  60. Location /{
  61. # Here we will convert all non-existing files and directories to index. php for processing.
  62. Try_files$ Uri $ Uri// Index. php? Q =$ Uri&$ Args;
  63. }
  64. # Put it here separately to the server. conf for convenience during server activation and unified calling. Put it in the/etc/nginx/directory.
  65. IncludeServer. conf;
  66.  
  67. Log_format access'$ Remote_addr-$ remote_user [$ time_local] "$ request "' 
  68. '$ Status $ body_bytes_sent "$ http_referer "' 
  69. '"$ Http_user_agent" $ http_x_forwarded_for';
  70. Access_log/www/logs/access. log access;
  71. }
  72.  
  73. Server {
  74. Listen 80;
  75. Server_name www.21andy.com 21andy.com * .21andy.com;
  76. Root/www/21andy.com;
  77. If($ Host!~ * 21andy.com $ ){
  78. Return444;
  79. }
  80. Location /{
  81. Try_files$ Uri $ Uri// Index. php? Q =$ Uri&$ Args;
  82. }
  83. IncludeServer. conf; # reuse here, which saves time
  84. Access_log/www/logs/21andy.com _ access. log access;
  85. }
  86. }

# Vi/etc/nginx/server. conf

 
 
  1. index index.html index.htm index.php;  
  2.  
  3. #limit_conn   crawler  20;  
  4.  
  5. location ~ /.ht {  
  6.     deny all;  
  7. }  
  8.  
  9. location ~ .*.(sqlite|sq3)$ {  
  10.     deny all;  
  11. }  
  12.  
  13. location ~ .*.php$ {  
  14.     fastcgi_pass  unix:/tmp/php-cgi.sock;  
  15.     #fastcgi_pass  127.0.0.1:9000;  
  16.     fastcgi_index index.php;  
  17.     include fastcgi_params;  
  18. }  
  19.  
  20. location ~ .*.(gif|jpg|jpeg|png|bmp|swf|ico)$ {  
  21.     expires      30d;  
  22.     access_log   off;  
  23. }  
  24.  
  25. location ~ .*.(js|css)?$ {  
  26.     expires      30d;  
  27.     access_log   off;  

The following content can be skipped

You can also use the following settings for php-fpm, but we recommend that you use the settings above, which is relatively stable.

 
 
  1. Location ~ . Php $ {
  2. Root/www;
  3. Fastcgi_pass 127.0.0.1: 9000;
  4. Fastcgi_index index. php;
  5. # Add the following line to/etc/nginx/fastcgi_params.
  6. # Fastcgi_param SCRIPT_FILENAME$ Document_root$ Fastcgi_script_name;
  7. IncludeFastcgi_params;
  8. }

Both nginx and php-fpm must be set to the same either by using the php-cgi.sock or port 9000 Method

Nginx settings have been mentioned above, remember to modify the php-fpm.conf at the same time the corresponding place

# Vi/etc/php-fpm.conf

 
  127.0.0.1:9000
 

Or

 
  unix:/tmp/php-cgi.sock
 

Original article address:Http://www.21andy.com/blog/20100219/1701.html


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.