This post will show you the procedure to setup Nginx, PHP5.4, PHP-FPM and MySQL 5.5 On CentOS 6.5 Virtual private server(VPS). You need to setup the required repo such as EPEL, Remi and also the NGINX repo.
Bạn đang xem: Install nginx with php and mysql in centos 6
What is NGINX ?NGINX is an alternate web server for Apache. Nginx is an open source web server and a reverse proxy server for HTTP, SMTP, POP3 and IMAP protocols. Many websites and the web developer have moved to NGINX because it’s scalable, low resources, can handle many users concurrency and good website performance. Now it still third most popular web server in the world and it serve just over 14% of all hostnames.
What is PHP(PHP-FPM) ?PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language. PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features useful for sites of any size, especially busier sites.
What is MySQL ?MySQL Database server is one of the most popular used database in the internet especially for content management and blogging site.
Steps to setup Nginx,PHP5.4, PHP-FPM, MySQL 5.5 On CentOS 6.5 VPS1. Setup EPEL and Remi repository.How to prepared EPEL and how to configure Remi repository in to CentOS.
2. Install php 5.4, php-fpm and MySQL 5.5 Server :
Xem thêm: Code Thống Kê Truy Cập Php, Cách Tạo Bộ Đếm Lượt Truy Cập Trong Php
user nginx;worker_processes 2;error_log /var/log/nginx/error.log warn;pid /var/run/nginx.pid;events { worker_connections 1024;}http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main "$remote_addr - $remote_user <$time_local> "$request" " "$status $body_bytes_sent "$http_referer" " ""$http_user_agent" "$http_x_forwarded_for""; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; gzip on; gzip_types text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon; include /etc/nginx/sites-available/*.conf;}b. Create sites-available directory and create nginx virtual host for example.com domain :
server {listen 80; server_name example.com; rewrite ^/(.*)$ http://www.example.com/$1 permanent;}server { server_name www.example.com; root /var/www/html/example; access_log /var/log/nginx/example.com.access.log; error_log /var/log/nginx/example.com.error.log; include conf.d/common.conf; include conf.d/wordpress.conf; include conf.d/w3tc.conf;}c. Create these three configuration files. It was optimized for WordPress site.
/etc/nginx/conf.d/common.conf/etc/nginx/conf.d/wordpress.conf/etc/nginx/conf.d/w3tc.confCreate common.conf :
# Global configuration file.# ESSENTIAL : Configure Nginx Listening Portlisten 80;# ESSENTIAL : Default file to serve. If the first file isn"t found,index index.php index.html index.htm;# ESSENTIAL : no favicon logslocation = /favicon.ico { log_not_found off; access_log off;}# ESSENTIAL : robots.txtlocation = /robots.txt { allow all; log_not_found off; access_log off;}# ESSENTIAL : Configure 404 Pageserror_page 404 /404.html;# ESSENTIAL : Configure 50x Pageserror_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; }# SECURITY : Deny all attempts to access hidden files .abcdelocation ~ /\. { deny all;}# PERFORMANCE : Set expires headers for static files and turn off logging.location ~* ^.+\.(js|css|swf|xml|txt|ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ { access_log off; log_not_found off; expires 30d;}Configure wordpress.conf :
# WORDPRESS : Rewrite rules, sends everything through index.php and keeps the appended query string intactlocation / { try_files $uri $uri/ /index.php?q=$uri&$args;}# SECURITY : Deny all attempts to access PHP Files in the uploads directorylocation ~* /(?:uploads|files)/.*\.php$ { deny all;}# REQUIREMENTS : Enable PHP Supportlocation ~ \.php$ { # SECURITY : Zero day Exploit Protection try_files $uri =404; # ENABLE : Enable PHP, listen fpm sock fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php-fpm.sock; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;}# PLUGINS : Enable Rewrite Rules for SiteMaprewrite ^/sitemap(-+(
# BEGIN W3TC Page Cache coreset $w3tc_rewrite 1;if ($request_method = POST) { set $w3tc_rewrite 0;}if ($query_string != "") { set $w3tc_rewrite 0;}if ($http_cookie ~* "(comment_author|wp\-postpass|w3tc_logged_out|wordpress_logged_in|wptouch_switch_toggle)") { set $w3tc_rewrite 0;}if ($http_cookie ~* "(w3tc_preview)") { set $w3tc_rewrite _preview;}set $w3tc_enc "";if ($http_accept_encoding ~ gzip) { set $w3tc_enc _gzip;}set $w3tc_ext "";if (-f "$document_root/wp-content/cache/page_enhanced/$http_host/$request_uri/_index$w3tc_rewrite.html$w3tc_enc") { set $w3tc_ext .html;}if (-f "$document_root/wp-content/cache/page_enhanced/$http_host/$request_uri/_index$w3tc_rewrite.xml$w3tc_enc") { set $w3tc_ext .xml;}if ($w3tc_ext = "") { set $w3tc_rewrite 0;}if ($w3tc_rewrite = 1) { rewrite .* "/wp-content/cache/page_enhanced/$http_host/$request_uri/_index$w3tc_rewrite$w3tc_ext$w3tc_enc" last;}# END W3TC Page Cache cored. Modify default.conf file :
listen = /var/run/php-fpm.sock..listen.mode = 0666..user = nginxgroup = nginx..pm = dynamic..pm.max_children = 50pm.start_servers = 10pm.min_spare_servers = 10pm.max_spare_servers = 10pm.max_requests = 200..slowlog = /var/log/php-fpm/www-slow.log..php_admin_value

Thanks for checking in!
Here you won"t find biased "expert" reviews, forged speed and uptime ratings, deceptive "actual testing" analyses etc. Just plain data backed by real customer reviews, both positive and negative. We"ve been collecting them since 2004.
Nevertheless, some content may include ads and sponsored links. Yeah, passion alone does not pay the rent. This helps us pay for the servers and parsers. Thank you for understanding.