logo

  • Hỏi Đáp
  • Kiến Thức
  • Sức Khỏe
  • Tử Vi
  • Công Nghệ
No Result
View All Result
logo
No Result
View All Result
Trang chủ install nginx with php and mysql in centos 6

Install nginx with php and mysql in centos 6

by Admin _ April 28, 2022

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 VPS

1. 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 :

vps-08 ~># yum --enablerepo=remi install php php-mysql php-fpm mysql mysql-server -y3. Setup repository for nginx :

vps-08 ~># vi /etc/yum.repos.d/nginx.repoAdd the following and save :

name=nginx repobaseurl=http://nginx.org/packages/centos/$releasever/$basearch/gpgcheck=0enabled=14. Install and setup NGINX :Run the following command to install NGINX.

Xem thêm: Code Thống Kê Truy Cập Php, Cách Tạo Bộ Đếm Lượt Truy Cập Trong Php

vps-08 ~># vi /etc/nginx/nginx.confAdd the following and save:

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 :

vps-08 ~># vi /etc/nginx/sites-available/example.com.confAdd the following and save :

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 :

vps-08 ~># vi /etc/nginx/conf.d/common.confAdd the following and save.

# 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 :

vps-08 ~># vi /etc/nginx/conf.d/wordpress.confAdd the following and save :

# 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(-+(+))?\.xml$ "/index.php?xml_sitemap=params=$2" last;rewrite ^/sitemap(-+(+))?\.xml\.gz$ "/index.php?xml_sitemap=params=$2;zip=true" last;rewrite ^/sitemap(-+(+))?\.html$ "/index.php?xml_sitemap=params=$2;html=true" last;rewrite ^/sitemap(-+(+))?\.html.gz$ "/index.php?xml_sitemap=params=$2;html=true;zip=true" last;Create w3tc.conf file :

vps ~># vi /etc/nginx/conf.d/w3tc.confAdd the following and save :

# 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 :

vps-08 ~># vi /etc/nginx/conf.d/default.confserver { listen 80; server_name localhost; location / { root /usr/share/nginx/html; index index.html index.htm; }# redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; }}5. Secure Mysql :

vps-08 ~># /usr/bin/mysql_secure_installationNOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!In order to log into MySQL to secure it, we"ll need the currentpassword for the root user. If you"ve just installed MySQL, andyou haven"t set the root password yet, the password will be blank,so you should just press enter here.Enter current password for root (enter for none):OK, successfully used password, moving on...Setting the root password ensures that nobody can log into the MySQLroot user without the proper authorisation.Set root password? yNew password:Re-enter new password:Password updated successfully!Reloading privilege tables.. ... Success!By default, a MySQL installation has an anonymous user, allowing anyoneto log into MySQL without having to have a user account created forthem. This is intended only for testing, and to make the installationgo a bit smoother. You should remove them before moving into aproduction environment.Remove anonymous users? y ... Success!Normally, root should only be allowed to connect from "localhost". Thisensures that someone cannot guess at the root password from the network.Disallow root login remotely? n ... skipping.By default, MySQL comes with a database named "test" that anyone canaccess. This is also intended only for testing, and should be removedbefore moving into a production environment.Remove test database and access to it? y - Dropping test database... ... Success! - Removing privileges on test database... ... Success!Reloading the privilege tables will ensure that all changes made so farwill take effect immediately.Reload privilege tables now? y ... Success!Cleaning up...All done! If you"ve completed all of the above steps, your MySQLinstallation should now be secure.Thanks for using MySQL!6. Configure php-fpm :

vps-08 ~># vi /etc/php-fpm.d/www.confUpdate and uncomment the following :

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 = /var/log/php-fpm/www-error.logphp_admin_flag = on..php_value = filesphp_value = /var/lib/php/session7. Restart the NGINX and php-fpm :Restart the NGINX and php-fpm service to apply the changes on the configuration files.

vps-08 ~># service nginx restart; service php-fpm restartStopping nginx: < OK >Starting nginx: < OK >Stopping php-fpm: < OK >Starting php-fpm: < OK >Check the service listened on your VPS :

vps-08 ~># netstat -plunt | grep LISTENtcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1097/rpcbindtcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 18070/nginxtcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1130/sshdtcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 18358/mysqldtcp 0 0 :::111 :::* LISTEN 1097/rpcbindtcp 0 0 :::22 :::* LISTEN 1130/sshdNow you can start to setup WordPress blog into your VPS server.


*

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.

ShareTweet Linkedin Pinterest
Previous Post

Lập trình hướng đối tượng php freetuts

Next Post

Custom post types

CÙNG CHUYÊN MỤC

form register php

Form register php

09/04/2021
fantastic blog (cms) in php with source code

Fantastic blog (cms) in php with source code

28/04/2021
validate form php javascript

Validate form php javascript

28/04/2021
http diendanlequydon com viewtopic php style 6

Http diendanlequydon com viewtopic php style 6

28/04/2021
bai tap php về mảng

Bai tap php về mảng

17/05/2022
hướng dẫn thao tác với database bằng các hàm mysqli

Hướng dẫn thao tác với database bằng các hàm mysqli

17/05/2022
20 best php ide and code editor software in 2022

20 best php ide and code editor software in 2022

17/05/2022
how to set multiple cookies by using php header

How to set multiple cookies by using php header

16/05/2022

Newsletter

The most important automotive news and events of the day

We won't spam you. Pinky swear.

Chuyên Mục

  • Hỏi Đáp
  • Kiến Thức
  • Sức Khỏe
  • Tử Vi
  • Công Nghệ

News Post

  • Trung tâm dạy lập trình php

About

Chúng tôi tạo ra trang web nhằm mục đích mang lại kiến thức bổ ích cho cộng đồng, các bài viết được sưu tầm từ nhiều nguồn trên internet giúp mang lại kiến thức khách quan dành cho bạn

©2022 darkedeneurope.com - Website WordPress vì mục đích cộng đồng

Liên Hệ - Giới Thiệu - Nội Quy - Bảo Mật

No Result
View All Result
  • Trang chủ
  • Chuyên mục
    • Hỏi Đáp
    • Kiến Thức
    • Sức Khỏe
    • Tử Vi
    • Công Nghệ
  • Lưu trữ
  • Liên hệ

© 2022 darkedeneurope.com - Website WordPress vì mục đích cộng đồng.