Tags

,

Như bà trước mình đã hướng dẫn chúng ta đã hoàn tất việc tăng tốc độ trang web bằng việc kết hợp giữa HHVM và web server Apache, hôm nay mình sẽ hướng dẫn các bạn tối ưu truy xuất website của mình nhanh hơn nữa thì mình sẽ hướng dẫn các bạn kết hợp giữa HHVM và web server Nginx.

1. Tạo máy ảo Ubuntu 15.10:
Quá trình tạo máy ảo cũng đơn giản như những lần trước.

Sau khi tạo xong máy ảo ta tiến hành cập nhật:

# sudo apt-get -y update

2. Cài đặt LAMP:

Như bài hướng dẫn trước đã làm chi tiết, lần này mình chỉ tóm tắt lại những câu lệnh chính sử dụng thôi:

Cập nhật phần mềm:

# sudo apt-get update

Cài đặt nginx:

# sudo apt-get install nginx

Kiểm tra dịch vụ apache2 có khởi động chưa:

# sudo service nginx status

Cài đặt MySql:

# sudo apt-get install php5-fpm php5-mysql mysql-server

Cấu hình cơ bản MySql ở đây có thể thay đổi lại mật khẩu root MySql ngoài ra những phần cấu hình khác có thể chọn “y” hết:

# sudo mysql_secure_installation

Cài đặt PHP 5:

# sudo apt-get install php5

Cài thêm một số phần mở rộng php5 khác:

# sudo apt-get -y install php5-mysqlnd php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl

Cấu hình processor PHP:

# vi /etc/php5/fpm/php.ini

Thay đổi giá trị cgi.fix_pathinfo=0 sang 1

Khởi động lại dịch vụ:

# service php5-fpm restart

Cấu hình nginx sử dụng PHP Processor:

# vi /etc/nginx/sites-available/default

Thêm vào file cấu hình những phần màu vàng sau đó restart lại nginx:

server {

    listen 80 default_server;

    listen [::]:80 default_server ipv6only=on;

    root /usr/share/nginx/html;

    index index.php index.html index.htm;

    server_nameserver_domain_name_or_IP;

    location / {

        try_files $uri $uri/ =404;

    }

    error_page 404 /404.html;

    error_page 500 502 503 504 /50x.html;

    location = /50x.html {

        root /usr/share/nginx/html;

    }

    location ~ \.php$ {

        try_files $uri =404;

        fastcgi_split_path_info ^(.+\.php)(/.+)$;

        fastcgi_pass unix:/var/run/php5-fpm.sock;

        fastcgi_index index.php;

        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

        include fastcgi_params;

    }

}

Tạo file info để test:

# sudo vi /usr/share/nginx/html/info.php

Thêm vào những nội dung sau:

<?php

phpinfo();

?>Khởi động lại dịch vụ nginx:

# sudo service nginx restart

Cài đặt phpMyAdmin để quản lý MySql bằng giao diện:

# cd /usr/share

# wget https://files.phpmyadmin.net/phpMyAdmin/4.6.5.2/phpMyAdmin-4.6.5.2-english.zip

# apt-get –y install zip unzip

# unzip phpMyAdmin-4.6.5.2-english.zip

# mv phpMyAdmin-4.6.5.2-english.zip phpMyAdmin

# cp /usr/share/phpMyAdmin/config.sample.inc.php /usr/share/phpMyAdmin/config.inc.php

# ln -s /usr/share/phpMyAdmin/ /usr/share/nginx/html/

image25

3. Cài đặt HHVM

Cài đặt thêm một số phần mở rộng:

# sudo apt-get install software-properties-common

# sudo apt-key adv –recv-keys –keyserver hkp://keyserver.ubuntu.com:80 0x5a16e7281be7a449

# sudo add-apt-repository “deb http://dl.hhvm.com/ubuntu $(lsb_release -sc) main”

# sudo apt-get update

# sudo apt-get install hhvm

Sau khi cài đặt xong sẽ có hướng dẫn để nâng cấp web server cũ:

update-alternatives: using /usr/bin/hhvm to provide /usr/bin/php (php) in auto mode

********************************************************************

* HHVM is installed.

*

* Running PHP web scripts with HHVM is done by having your

* webserver talk to HHVM over FastCGI. Install nginx or Apache,

* and then:

* $ sudo /usr/share/hhvm/install_fastcgi.sh

* $ sudo /etc/init.d/hhvm restart

* (if using nginx)  $ sudo /etc/init.d/nginx restart

* (if using apache) $ sudo /etc/init.d/apache restart

…….

Với web server nginx ta sẽ cài đặt theo những lệnh sau:

# sudo /usr/share/hhvm/install_fastcgi.sh

# sudo /etc/init.d/hhvm restart

# sudo /etc/init.d/nginx restart

# sudo update-rc.d hhvm defaults

# sudo /usr/bin/update-alternatives \

–install /usr/bin/php php /usr/bin/hhvm 60

Sau khi cài đặt kiểm tra với lệnh:

# php –v

Nếu thấy thông báo như sau là thành công:

root@hhvm:~# php -v

HipHop VM 3.12.0 (rel)

Compiler: tags/HHVM-3.12.0-0-g440e6a096b2db8a449b9690a72f2f1792530e86a

Repo schema: 033b8dedf4af99b892f2488b103a8d67a58ff816

4. Cấu hình HHVM trong nginx

Lấy file cấu hình HHVM trong /etc/nginx/hhvm.conf:

location ~ \.(hh|php)$ {

fastcgi_keep_conn on;

fastcgi_pass   127.0.0.1:9000;

fastcgi_index  index.php;

fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;

include        fastcgi_params;

}

Thêm nội dung trên vào trong file cấu hình:

 /etc/nginx/sites-enabled/default

# sudo service nginx restart

Kích hoạt chết độ rewrite cho nginx:

# vi /etc/nginx/sites-enabled/default

location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$args;
}

Restart lại dịch vụ:

# service nginx restart

Cấu hình giới hạn RAM trong HHVM:

# vi /etc/hhvm/php.ini

memory_limit = 1200M

#service hhvm restart

Đổi port trong file cấu hình HHVM:

# vi /etc/hhvm/server.ini

; php options

pid = /var/run/hhvm/pid

; hhvm specific

hhvm.server.port = 9000

hhvm.server.type = fastcgi

hhvm.server.default_document = index.php

hhvm.log.use_log_file = true

hhvm.log.file = /var/log/hhvm/error.log

hhvm.repo.central.path = /var/run/hhvm/hhvm.hhbc

 

Để HHVM chịu tải cao hơn thì thể thay thế port bằng

hhvm.server.file_socket=/var/run/hhvm/hhvm.sock

# vi /etc/nginx/hhvm.conf

fastcgi_pass unix:/var/run/hhvm/hhvm.sock;

image26

5. Cài đặt CMS Drupal

 

Lên trang chủ Drupal và lấy link tải https://www.drupal.org/ :

# cd /usr/share/nginx/html

# wget http://ftp.drupal.org/files/projects/drupal-x.x.tar.gz

Giải nén:

# tar -xvzf drupal-x.x.tar.gz

# rm drupal-x.x.tar.gz

Copy toàn bộ source web ra thư mục /usr/share/nginx/html

# mv drupal-x.x/* drupal-x.x/.htaccess ./

For Drupal 7, also add:

mv drupal-x.x/.gitignore ./

For Drupal 8:

tar –strip-components=1 –xvzf drupal-x.x.tar.gz

Một số lỗi trong quá trình cài đặt:

PHP OPcode caching not enable

# /etc/php5/cli/php.ini

Sửa giá trị:

  opcache.enable=1

#service nginx restart

Giải nén:

# tar -xvzf drupal-x.x.tar.gz

# rm drupal-x.x.tar.gz

Copy toàn bộ source web ra thư mục /usr/share/nginx/html

# mv drupal-x.x/* drupal-x.x/.htaccess ./

For Drupal 7, also add:

mv drupal-x.x/.gitignore ./

For Drupal 8:

tar –strip-components=1 –xvzf drupal-x.x.tar.gz

Missing files directory

# cd /usr/share/nginx/html

# mkdir sites/default/files

# chmod a+w sites/default/files

Missing settings file

# cd /usr/share/nginx/html

# cp sites/default/default.settings.php sites/default/settings.php

# chmod 777 sites/default/settings.php

Kết quả:

image30

 

Me at: https://www.facebook.com/phamhoainam1215.info