HHvm Apache 2.4 Nginx建站環境搭建方法安裝運行WordPress部落格

來源:互聯網
上載者:User

標籤:

HHvm Apache 2.4 Nginx建站環境搭建方法安裝運行WordPress部落格VPS主機   2014年06月02日 17:20  評論»    文章目錄

 

  • Debian上安裝
  • CentOS上安裝
  • Ubuntu上安裝
  • 裝Wordpress
  • HHvm安裝小結
 

HHVM是一個強大的可以用於替代PHP的建站環境,出自Facebook團隊,它是一個PHP的JIT(Just-In- Time)編譯器,同時具有產生快速代碼和即時編譯的優點。實踐證明HHVM可以明顯地提升PHP執行速度,節省大量的伺服器資源。

HHVM單獨安裝的話比較簡單,官方也針對各種個作業系統推出了詳細的說明文檔,一般按照文檔的說明就可以安裝成功,HHVM主要是用於替換PHP,平常的LNMP即Linux、Nginx、MysqL、PHP架構被替換為LNMH(H即為HHVM)。

本篇文章就來分享一下Debian7 x64、CentOS 6.5 (64-bit)、 Ubuntu 12.04 上搭建HHvmApache 2.4 Nginx建站環境,同時安裝和運行Wordpress部落格程式,HHvm強大的效能提升能力可以最大限度地提升Wordpress運行效率,節省伺服器費用。

對伺服器最佳化提速和網站集合群有興趣的朋友,可以來看看:

  • 1、記憶體加速:用Varnish和Memcached緩衝給WordPress網站提速-記憶體級加速
  • 2、前台緩衝:用Redis緩衝來給WordPress網站加速-適用於Apache和Nginx
  • 3、負載平衡:免費空間+便宜VPS和OpenResty,Ngx_lua,Redis搭建系統負載平衡環境

HHvm Apache 2.4 Nginx建站環境搭建方法安裝運行Wordpress部落格

一、Debian安裝HHvm、Nginx搭建LNMH環境

1、 在 Debian 7 64位的Linux上安裝HHvm、Nginx、MysqL,並搭建LHMH建站環境,可以參考這篇文章:HHVM安裝使用教程-高效的PHP運行環境提升PHP效能9倍以上。

二、在CentOS上安裝HHvm、Apache 2.4

1、實際上Apache 2.2也可以與HHvm搭配使用,但是Apache 2.2因為沒有mod_proxy_fcgi 還需要安裝libapache2-mod-fastcgi,配置起來比較麻煩。安裝Apache 2.4可以直接和HHvm整合使用。況且Apache 2.4在效能有很大提升,支援更大流量、更好地支援雲計、利用更少的記憶體處理更多的並發等。

2、CentOS上安裝HHvm、Apache 2.4 ,執行以下命令:

cd /etc/yum.repos.dsudo wget http://repos.fedorapeople.org/repos/jkaluza/httpd24/epel-httpd24.reposudo wget http://www.hop5.in/yum/el6/hop5.reposudo yum install httpd24-httpd httpd24-httpd-devel httpd24-mod_sslsudo yum install hhvm

 

3、 配置Apache 2.4,啟用HHvm。進入配置目錄:cd /opt/rh/httpd24/root/etc/httpd/conf,編輯:vim httpd.conf,在最後查看這句不要被注釋了:IncludeOptional conf.d/*.conf

4、接著進入配置目錄:cd /opt/rh/httpd24/root/etc/httpd/conf.d,編輯設定檔:vim httpd24-vhosts.conf(沒有的話直接建立一個),加入以下代碼,儲存。

<virtualhost   *:80>  ServerName hhvmtest.dev  DocumentRoot /var/www/html/hhvmtest  ErrorLog logs/hhvmtest.dev-error_log  CustomLog logs/hhvmtest.dev-access_log common  # where HHVM is running  # use either Proxy Pass or ProxyPassMatch  # ProxyPass routes all traffic to FastCGI  ProxyPass / fcgi://127.0.0.1:9000/var/www/html/hhvmtest  # ProxyPassMatch regular expression routes only PHP files  ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/html/hhvmtest/$1  <directory hhvmtest html www var> # relaxed permissions for testing    AllowOverride all    Options -MultiViews    Require all granted  </directory></virtualhost>

 

5、 執行命令開啟HHvm:/usr/bin/hhvm --mode server -vServer.Port=9000 -vServer.Type=fastcgi &

6、執行命令:ps aux | grep hhvm,可以看到HHvm已經運行。 (點擊放大)

7、啟動Apache命令:sudo service httpd24-httpd start

8、在網站根目錄:cd /opt/rh/httpd24/root/var/www/html,建立一個檔案目錄:mkdir hhvmtest。這個hhvmtest就是網站的根目錄。至此CentOS上安裝HHvm、Apache 2.4 完成,

三、Ubuntu 上安裝HHvm、Nginx、MysqL

1、Ubuntu 上安裝HHvm、Nginx、Laravel過程也比較簡單,首先是安裝Nginx,執行:

sudo apt-get updatesudo apt-get install -y unzip vim git-core curl wget build-essential python-software-propertiessudo add-apt-repository -y ppa:nginx/stablesudo apt-get updatesudo apt-get install -y nginx

 

2、 接著是安裝HHvm了。

#Ubuntu 12.04:sudo add-apt-repository -y ppa:mapnik/boostwget -O - http://dl.hhvm.com/conf/hhvm.gpg.key | sudo apt-key add -echo deb http://dl.hhvm.com/ubuntu precise main | sudo tee /etc/apt/sources.list.d/hhvm.listsudo apt-get updatesudo apt-get install -y hhvm#Ubuntu 14.04:wget -O - http://dl.hhvm.com/conf/hhvm.gpg.key | sudo apt-key add -echo deb http://dl.hhvm.com/ubuntu trusty main | sudo tee /etc/apt/sources.list.d/hhvm.listsudo apt-get updatesudo apt-get install -y hhvm

 

3、 安裝完了HHvm會提示如下:(點擊放大)

4、這裡給出了FastCGI配置的指令碼,執行以下命令:

sudo /usr/share/hhvm/install_fastcgi.sh sudo /etc/init.d/nginx restart #重啟Nginxsudo update-rc.d hhvm defaults #開機啟動sudo service hhvm restart #重啟hhvm

 

5、 如果你想像執行PHP命令那樣使用HHvm,可以執行:sudo /usr/bin/update-alternatives --install /usr/bin/php php /usr/bin/hhvm 60,這樣就可以使用:php -v這樣的命令了。

6、hhvm的設定檔是放在/etc/nginx/hhvm.conf,開啟設定檔,可以看到Nginx已經配置完成。

7、而在/etc/nginx/sites-available/default中也可以看到Nginx包含了hhvm.conf設定檔。

8、網站的根目錄是在/usr/share/nginx/html,你可以上傳PHP檔案到這個目錄,查看phpinfo()可以看到是HipHop。

9、安裝MysqL資料庫。執行一句命令:apt-get install mysql-server,安裝過程中會要求你設定好MysqL資料庫密碼。

10、然後將MysqL添加到開機啟動,命令:chkconfig add mysqld 和 chkconfig mysql on

11、如果有提示說:/sbin/insserv: No such file or directory,執行:ln -s  /usr/lib/insserv/insserv /sbin/insserv,再執行:chkconfig --levels 235 mysql on

12、執行:chkconfig --list,可以看到所有開機啟動項,有三個on以上的就是開機啟動項目。重啟MysqL:service mysqld start(點擊放大)

13、在S-S-H中登入MysqL用命令:mysql -u root -p,然後輸入密碼。建立freehao123wp資料庫:create database freehao123wp;   ,建立使用者名稱和密碼:create user [email protected]‘localhost‘ identified by ‘123456789‘;  。

14、授於部分讀寫權限:grant select on freehao123wp.* to [email protected]‘localhost‘;   ,授於全部許可權給使用者:grant select on freehao123wp.* to [email protected]‘localhost‘;  。show databases;   是查看資料庫(注意:每條命令後面都是以“;”結束) 。

15、如果是修改MysqL使用者名稱和密碼,則執行以下命令:

use mysql;update user set password=PASSWORD(‘新密碼‘) where user=‘使用者名稱‘;flush privileges;

 

四、 Ubuntu 上安裝HHvm、Nginx、MariaDB、Wordpress 、PhpMyAdmin

1、Ubuntu 用的是Ubuntu 12.04,先來安裝MariaDB。參考:rosehosting。(註:MariaDB是MysqL一個分支,完全相容MysqL,但有多項改進,效能提升,新版的LNMP也增加了MariaDB)

apt-get update && apt-get upgradeapt-get install python-software-properties curlapt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943dbadd-apt-repository ‘deb http://ftp.osuosl.org/pub/mariadb/repo/5.5/ubuntu precise main‘apt-get updateecho -e "Package: *\nPin: origin ftp.osuosl.org\nPin-Priority: 1000" | tee /etc/apt/preferences.d/mariadbapt-get install mariadb-server

 

2、 執行以下命令建立資料庫、資料庫使用者名稱,方法同上。

mysql -uroot -pCREATE DATABASE wpdb;GRANT ALL PRIVILEGES ON wpdb.* TO ‘freehao123‘@‘localhost‘ IDENTIFIED BY ‘123456789‘;FLUSH PRIVILEGES;\q

 

3、 安裝Nginx 1.4.x。

add-apt-repository ppa:nginx/stableapt-get install nginx

 

4、 如果VPS有多核CPU的話,可以在nginx.conf中配置以最大限度地利用好多線程,提升效能。執行以下命令:

sed -i "0,/^worker_processes/ s/^worker_processes .*$/worker_processes `grep -c processor /proc/cpuinfo`;/"  /etc/nginx/nginx.conf

 

5、安裝hhvm and hhvm-fastcgi。執行以下命令:

apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 5A16E7281BE7A449echo deb http://dl.hhvm.com/ubuntu precise main | tee /etc/apt/sources.list.d/hhvm.listapt-get updateapt-get install hhvm-fastcgi

 

6、 安裝完成後,會提示如下:

********************************************************************* HHVM is installed. Here are some more things you might want to do:* * Configure your webserver to use HHVM:* $ sudo /usr/share/hhvm/install_fastcgi.sh* $ sudo /etc/init.d/nginx restart* $ sudo /etc/init.d/apache restart* $ sudo /etc/init.d/hhvm restart* * Start HHVM at boot:* $ sudo update-rc.d hhvm defaults* * Run command line scripts with HHVM:* $ hhvm whatever.php* * Use HHVM for /usr/bin/php even if you have php-cli installed:* $ sudo /usr/bin/update-alternatives --install /usr/bin/php php /usr/bin/hhvm 60********************************************************************

 

7、如果你想像使用PHP那樣使用HHvm,執行:ln -s $(which hhvm) /usr/local/bin/php

8、為網域名稱freehao123.info在www根目錄下建立一個網站根目錄和日誌存放目錄。同時下載Wordpress放在該目錄。

mkdir -p /var/www/freehao123.info/{public_html,logs}wget -q -O - http://wordpress.org/latest.tar.gz | tar -xzf - --strip 1 -C /var/www/freehao123.info/public_htmlchown www-data: -R /var/www/freehao123.info/public_html

 

9、 上面下載的是最新版本的Wordpress,英文(不用擔心,安裝好了Wordpress可以直接到後台設定為中文),大家也可以到Wordpress中文網站上下載有中文包的Wordpress。

10、在Nginx中添加虛擬機器主機。執行:cat <<‘EOF‘ > /etc/nginx/sites-available/freehao123.info,將以下命令放在裡面(注意:替換為自己的網域名稱和路徑):

server {  server_name hhvm.freehao123.info;  listen 80;  root /var/www/freehao123.info/public_html;  access_log /var/www/freehao123.info/logs/access.log;  error_log /var/www/freehao123.info/logs/error.log;  index index.php;  location / {    try_files $uri $uri/ /index.php?q=$uri&$args;  }  location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {    access_log off;    expires max;  }  location ~ /\.ht {    deny  all;  }  location ~ \.php$ {    fastcgi_index index.php;    fastcgi_keep_conn on;    include /etc/nginx/fastcgi_params;    fastcgi_pass 127.0.0.1:9000;    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;  }}

 

11、 最後輸入:EOF 儲存退出。再執行以下命令:

ln -s /etc/nginx/sites-available/freehao123.info /etc/nginx/sites-enabled/freehao123.info/etc/init.d/nginx restart

 

12、 將Nginx、hhvm、mysql設定為開機啟動,執行命令:

update-rc.d nginx defaultsupdate-rc.d hhvm defaultsupdate-rc.d mysql defaults

 

13、 HHvm安裝運行Wordpress。將你的網域名稱DNS解析到HHvm這個伺服器上(剛剛在添加Nginx配置時加入的網域名稱),開啟網域名稱就會進入到Wordpress安裝頁面,沒有跳轉到Wordpress安裝頁面的前檢查一下你的Wordpress有沒有放在該網域名稱的根目錄中。

14、HHvm運行Wordpress沒有任何問題,外掛程式安裝、主題升級、許可權、固定連結等都OK。

15、安裝PhpMyAdmin來管理MysqL。追求極簡的朋友或者喜歡在S-S-H中管理MysqL資料庫,但是不少人還是喜歡用PhpMyAdmin來管理MysqL。

16、進入你的Web可訪問的目錄,建立目錄用來存放PhpMyAdmin,然後直接下載和解壓

wget http://jaist.dl.sourceforge.net/project/phpmyadmin/phpMyAdmin/4.2.2/phpMyAdmin-4.2.2-all-languages.zipunzip phpMyAdmin-4.2.2-all-languages.zip

 

17、 解壓後的PhpMyAdmin建立將目錄重新命名,以方便訪問。用命令建立一個檔案夾:mkdir config  ,設定可寫:chmod o+rw config

18、然後開啟安裝頁面,類似於:http://hhvm.freehao123.info/db/phpmyadmin/setup/,建立一個伺服器。

19、這裡可以伺服器的連接埠、名稱、SSL、串連方式等進行設定。(點擊放大)

20、認證方式一般選擇Cookie。

21、PhpMyAdmin安裝還提供了進階功能,有需要調整MysqL的朋友可以直接在這裡設定。(點擊放大)

22、所以的設定好後點擊應用。然後返回到PhpMyAdmin安裝頁面,在“設定檔”中選擇剛剛建立好的設定檔,點擊儲存,至此MysqL伺服器配置完成。

23、接著將config檔案夾產生的config.inc.php移動到PhpMyAdmin根目錄當中,同時刪除整個config檔案夾,將config.inc.php設定為全部不可寫:chmod o-rw config.inc.php

24、現在開啟PhpMyAdmin訪問頁面,就會看到登入頁面了。輸入你的Root帳號和密碼

25、登入完成後,就可以開始線上管理SQL了。

五、 HHvm Apache 2.4 Nginx運行Wordpress部落格小結

1、HHvm完全可以替換PHP來跑Wordpress,鑒於Wordpress在處理大資料庫和大流量壓力時表現不如人意,使用HHvm 來跑Wordpress實在是一個不錯的選擇。

2、HHvm與Nginx是最佳搭檔,Nginx與Apache在很多方面還需要完善,安裝了MysqL資料庫後可以直接使用命令來管理,當然Wordpress內建的資料庫管理外掛程式足夠了。

文章出自:免費資源部落 http://www.freehao123.com/ 著作權。本站文章除註明出處外,皆為作者原創文章,可自由引用,但請註明來源。

HHvm Apache 2.4 Nginx建站環境搭建方法安裝運行WordPress部落格

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.