Trong bài này, xTraffic.pep.vn sẽ hướng dẫn bạn cách cài đặt WordPress với HHVM + Nginx + MySQL để tăng tốc WordPress tốt nhất.
Bài hướng dẫn này, xTraffic.pep.vn sẽ cài đặt website WordPress tại thư mục “/home/websites/wordpress/” với domain là “wordpress-test.pep.vn“, hhvm sẽ chạy trên port 9001, các bạn chỉ cần lưu ý và thay thế tương ứng với website của mình.
Đầu tiên, các bạn cần cài đặt các gói thông tin lưu trữ (Repository) cho YUM theo hướng dẫn tại đây. Sau đó cài đặt HHVM theo hướng dẫn tại đây.
Cấu hình HHVM
Bạn mở file “/etc/hhvm/server.hdf” tìm và xoá block “Server {…}“, sau đó thêm vào nội dung sau :
Server { IP = 127.0.0.1 Port = 9001 Type = fastcgi ThreadCount = 1 DefaultDocument = index.php APC { EnableApc = true } }
Sau đó chạy lệnh sau để khởi động HHVM :
sudo service hhvm restart
Kiểm tra bằng lệnh :
netstat -plunt | grep hhvm
Nếu bạn thấy tương tự như sau là ok :
[root@xtraffic ~]# netstat -plunt | grep hhvm tcp 0 0 127.0.0.1:9001 0.0.0.0:* LISTEN 6669/hhvm [root@xtraffic ~]#
Cài đặt MySQL
Để cài đặt MySQL trên CentOS, bạn thực hiện lệnh sau :
sudo yum install -y mysql mysql-server
Khởi động MySQL :
sudo service mysqld start
Thiết lập lần đầu cho MySQL bằng lệnh sau :
/usr/bin/mysql_secure_installation
Để an toàn thì tất cả tuỳ chọn bạn nên chọn “Y”
Tải và cài đặt WordPress
Bạn thực hiện lần lượt những lệnh sau :
sudo mkdir -p /home/websites/ cd /home/websites/ wget --no-check-certificate -O ./latest.tar.gz https://wordpress.org/latest.tar.gz tar -zxf ./latest.tar.gz rm -f ./latest.tar.gz
Cài đặt và cấu hình Nginx
Để cài đặt Nginx trên CentOS, bạn thực hiện lệnh sau :
sudo yum install -y nginx
Bạn tạo file “/etc/nginx/conf.d/websites.conf” có nội dung như sau :
server { listen *:80; ## Your website name goes here. server_name wordpress-test.pep.vn; ## Your only path reference. root /home/websites/wordpress; ## This should be in your http block and if it is, it's not needed here. index index.php index.html index.htm; # Global restrictions configuration file. # Designed to be included in any server {} block. location = /favicon.ico { log_not_found off; access_log off; } location = /robots.txt { allow all; log_not_found off; access_log off; } # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac). # Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban) location ~ /\. { deny all; } # Deny access to any files with a .php extension in the uploads directory # Works in sub-directory installs and also in multisite network # Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban) location ~* /(?:uploads|files)/.*\.php$ { deny all; } # WordPress single blog rules. # Designed to be included in any server {} block. # This order might seem weird - this is attempted to match last if rules below fail. # http://wiki.nginx.org/HttpCoreModule location / { try_files $uri $uri/ /index.php?$args; } # Add trailing slash to */wp-admin requests. rewrite /wp-admin$ $scheme://$host$uri/ permanent; # Directives to send expires headers and turn off 404 error logging. location ~* ^.+\.(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 max; } # Pass all .php files onto a php-fpm/php-fcgi server. location ~ [^/]\.php(/|$) { fastcgi_split_path_info ^(.+?\.php)(/.*)$; if (!-f $document_root$fastcgi_script_name) { return 404; } # This is a robust solution for path info security issue and works with "cgi.fix_pathinfo = 1" in /etc/php.ini (default) fastcgi_index index.php; fastcgi_pass 127.0.0.1:9001; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; fastcgi_buffer_size 128k; fastcgi_buffers 256 4k; fastcgi_busy_buffers_size 256k; fastcgi_temp_file_write_size 256k; } }
Khởi động Nginx :
sudo service nginx start
Chạy lệnh sau để các service tự khởi động mỗi khi VPS/Server khởi động :
sudo chkconfig --levels 235 nginx on sudo chkconfig --levels 235 mysqld on sudo chkconfig --levels 235 hhvm on
Sau đó, bạn chỉ việc mở trình duyệt và truy cập vào http://wordpress-test.pep.vn/ để chạy & cài đặt website WordPress.