1. 程式人生 > >centos6.7、centos6.5下yum方式搭建lnmp環境,php5.4/mysql5.5

centos6.7、centos6.5下yum方式搭建lnmp環境,php5.4/mysql5.5

由於電腦重灌系統,之前虛擬機器中的所有系統都打不開了,不得已又得從0開始安裝。我下載的是centos6.5的映象,在虛擬機器中安裝完以後,執行了一下yum update,系統升成了6.7的,但是對於lnmp環境的安裝時沒有影響的,6.5和6.7的安裝方法是一樣的。

一、安裝php5.4

1.配置yum源

6.7和6.5中預設是沒有php5.4版本的,所以我們需要先配置一下yum源。

執行命令: rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm

[plain] 
view plain
 copy   在CODE上檢視程式碼片 派生到我的程式碼片
  1. [[email protected] yum.repos.d]# rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm  
  2. Retrieving http://mirror.webtatic.com/yum/el6/latest.rpm  
  3. warning: /var/tmp/rpm-tmp.qxPwK1: Header V4 DSA/SHA1 Signature, key ID cf4c4ff9: NOKEY  
  4. Preparing...                ########################################### [100%]  
  5.    1:webtatic-release       ########################################### [100%]  

2.安裝php5.4

執行完以後檢視yum search php54w,可以看到php5.4相關的模組。執行命令安裝php5.4

[plain]  view plain  copy   在CODE上檢視程式碼片 派生到我的程式碼片
  1. [[email protected] ~]# yum install php54w  

安裝完後,執行命令可以看到PHP版本資訊

[html]  view plain  copy   在CODE上檢視程式碼片 派生到我的程式碼片
  1. [[email protected] ~]# php --version  
  2. PHP 5.4.45 (cli) (built: Oct 16 2015 11:24:58)   
  3. Copyright (c) 1997-2014 The PHP Group  
  4. Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies  
3.安裝php-fpm

[html]  view plain  copy   在CODE上檢視程式碼片 派生到我的程式碼片
  1. [[email protected] ~]# yum install php-fpm.x86_64  
  2. Loaded plugins: fastestmirror, refresh-packagekit, security  
  3. Setting up Install Process  
  4. Loading mirror speeds from cached hostfile  
  5. f * base: mirrors.btte.net  
  6.  * extras: mirrors.btte.net  
  7.  * updates: mirror.bit.edu.cn  
  8.  * webtatic: sp.repo.webtatic.com  
  9. Resolving Dependencies  
  10. --> Running transaction check  
  11. ---> Package php-fpm.x86_64 0:5.3.3-46.el6_7.1 will be installed  
  12. --> Processing Dependency: php-common(x86-64) = 5.3.3-46.el6_7.1 for package: php-fpm-5.3.3-46.el6_7.1.x86_64  
  13. --> Running transaction check  
  14. ---> Package php-common.x86_64 0:5.3.3-46.el6_7.1 will be installed  
  15. --> Processing Conflict: php54w-common-5.4.45-2.w6.x86_64 conflicts php-common < 5.4.0  
  16. --> Finished Dependency Resolution  
  17. Error: php54w-common conflicts with php-common-5.3.3-46.el6_7.1.x86_64  
  18.  You could try using --skip-broken to work around the problem  
  19.  You could try running: rpm -Va --nofiles --nodigest  
可以看到倒數第三行報了一個衝突,導致安裝失敗,衝突的原因是php-fpm包依賴5.3版本的php-common,但是我們安裝php5.4的時候安裝了5.4版本的php-common,所以造成php-common-5.3安裝不上,解決這個衝突只要安裝依賴php-common-5.4版本的php-fpm就OK

[html]  view plain  copy   在CODE上檢視程式碼片 派生到我的程式碼片
  1. [[email protected]ost ~]# yum search php54w | grep fpm  
  2. php54w-fpm.x86_64 : PHP FastCGI Process Manager  
  3. [[email protected] ~]# yum install php54w-fpm.x86_64  
  4. Loaded plugins: fastestmirror, refresh-packagekit, security  
  5. Setting up Install Process  
  6. Loading mirror speeds from cached hostfile  
  7.  * base: mirrors.btte.net  
  8.  * extras: mirrors.btte.net  
  9.  * updates: mirror.bit.edu.cn  
  10.  * webtatic: sp.repo.webtatic.com  
  11. Resolving Dependencies  
  12. --> Running transaction check  
  13. ---> Package php54w-fpm.x86_64 0:5.4.45-2.w6 will be installed  
  14. --> Finished Dependency Resolution  
  15.   
  16. Dependencies Resolved  
  17.   
  18. ====================================================================================================================================================  
  19.  Package                             Arch                            Version                                Repository                         Size  
  20. ====================================================================================================================================================  
  21. Installing:  
  22.  php54w-fpm                          x86_64                          5.4.45-2.w6                            webtatic                          1.3 M  
  23.   
  24. Transaction Summary  
  25. ====================================================================================================================================================  
  26. Install       1 Package(s)  
  27.   
  28. Total download size: 1.3 M  
  29. Installed size: 3.8 M  
  30. Is this ok [y/N]: y  
  31. Downloading Packages:  
  32. php54w-fpm-5.4.45-2.w6.x86_64.rpm                                                                                            | 1.3 MB     00:13       
  33. Running rpm_check_debug  
  34. Running Transaction Test  
  35. Transaction Test Succeeded  
  36. Running Transaction  
  37.   Installing : php54w-fpm-5.4.45-2.w6.x86_64                                                                                                    1/1   
  38.   Verifying  : php54w-fpm-5.4.45-2.w6.x86_64                                                                                                    1/1   
  39.   
  40. Installed:  
  41.   php54w-fpm.x86_64 0:5.4.45-2.w6                                                                                                                     
  42.   
  43. Complete!  

測試php-fpm服務是否正常

[html]  view plain  copy   在CODE上檢視程式碼片 派生到我的程式碼片
  1. [[email protected] ~]# service php-fpm start  
  2. Starting php-fpm:                                          [  OK  ]  

一切順利!至此php環境就安裝完畢,接下來就安裝nginx

如果出現“Fatal error: Call to undefined function mb_strlen()"錯誤
還需要安裝php-mbstring

[[email protected] ~]# yum search php54w| grep mbstring
php54w-mbstring.x86_64 : A module for PHP applications which need multi-byte
[[email protected] ~]# yum install php54w-mbstring.x86_64

如果出現“ Unknown: open(/var/lib/php/session/sess_63u4vit4pii5gelmsq5inf3hd6, O_RDWR) failed: Permission denied”這樣的錯誤,需要將session目錄設定777許可權。chmod -R 777 /var/lib/php/session

以此類推,出現“Class 'DOMDocument' not found”,表示xml擴充套件沒有安裝

yum search php54w | grep xml

yum install php54w-mbstring.x86_64

二.安裝nginx
先看看我們都有哪些版本的Nginx

[html]  view plain  copy   在CODE上檢視程式碼片 派生到我的程式碼片
  1. [[email protected] ~]# yum search nginx  
  2. Loaded plugins: fastestmirror, refresh-packagekit, security  
  3. Loading mirror speeds from cached hostfile  
  4.  * base: mirrors.btte.net  
  5.  * extras: mirrors.btte.net  
  6.  * updates: mirror.bit.edu.cn  
  7.  * webtatic: uk.repo.webtatic.com  
  8. ================================================================ N/S Matched: nginx ================================================================  
  9. nginx16.x86_64 : A high performance web server and reverse proxy server  
  10. nginx18.x86_64 : A high performance web server and reverse proxy server  
  11.   
  12.   Name and summary matches only, use "search all" for everything.  
我們選擇安裝18版本的。

安裝的時候發現下載速度奇慢,最後也因為這個安裝失敗,所以我們現在先替換一下yum源。

[html]  vie