centos 5.5 安裝 lnmp

centos5.5 安裝 lnmp,必定要事先選好版本安裝,建議本身下載安裝。php

1.相關文件目錄:html

nginx: /www/nginx/下面
mysql: /usr/share/mysql /usr/bin/mysql (安裝時沒有配置路徑)
php : /usr/local/php53mysql

2nginx

A) nginx
啓動:/www/nginx/sbin/nginx -c /www/nginx/conf/nginx.conf
查看: ps -ef | grep nginx
中止:強制中止全部Nginx進程 ps -ef | grep nginx ==> pkill –9 nginx(推薦)
Nginx的平滑重啓(先啓動,而後查看主要進程號,才能重啓)
kill -HUP Nginx主進程號 或者 kill一HUP `/usr/local/webserver/nginx/logs/nginx.pid`
判斷Nginx配置文件是否正確:
/usr/local/webserver/nginx/sbin/nginx –t -c /usr/local/webserver/nginx/conf/nginx.conf web

B) 卸載 mysql 和 安裝新mysql
#rpm -qa|grep mysql 發現顯示沒有安裝mysql。先用 yum remove mysql可是mysql已經安裝了,因此,個人方法是查詢:whereis mysql
||而後分別刪除 /etc/init.d/下面的my.cnf和mysql
和目錄下面的全部mysql文件,這樣才能卸載乾淨,前提最好是 先中止運行mysql服務。
1 mysql client客戶端 | server 服務器安裝 便可。(wget http下載包)
2 啓動:找到目錄mysqld ,通常位於 /usr/bin / ====> service mysqld start(或者restart)
3 使用:mysql -u root -p
4 關閉服務器: 在此目錄下面,service mysqld stop
C)
php這個命令是刪除不乾淨的:yum remove php
必須強制刪除
#rpm -qa|grep php
  卸載Mysql
  # rpm -qa | grep mysql
  # yum remove mysql
  卸載Apache
  # rpm -qa | grep httpd
  # yum remove httpd
  卸載PHP
  # rpm -qa | grep php
  # yum remove phpsql

解決依賴包問題
咱們回過頭來解決依賴包問題。咱們的系統上缺乏哪些包呢?按我在上面的configure 選項,下面幾行命令中的包便是:
[root@fsvps feng]# yum -y install libxml2-devel
[root@fsvps feng]# yum -y install bzip2-devel
[root@fsvps feng]# yum -y install libcurl-devel
[root@fsvps feng]# yum -y install libjpeg-devel libpng-devel
這個依賴列表是怎麼知道的呢?運行configure,看提示什麼錯誤,就安裝相應包,記錄下來這些包名就知道了。或者檢查configure文檔或源碼,也是能夠的,不過這個工做量更龐大。centos

另外mcrype包centos源裏沒有的,要咱們手工編譯安裝,步驟以下:瀏覽器

cd build/
mkdir mcrypt
cd mcrypt
wget http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.bz2
tar xf libmcrypt-2.5.8.tar.bz2
cd libmcrypt-2.5.8服務器

 

./configure
make
make install
其中 sourceforge.net 上的地址,若是不能下載,請點此從本站(path8.net)下載:libmcrypt-2.5.8.tar.bz2.zip [注]本文件是再次zip壓縮的,使用時需先unzip 再tar x]curl

或者你能夠到http://mcrypt.sourceforge.net/下載,但要注意,咱們須要的是 libmcrypt而不是mcrypt,這裏很容易搞錯。


開始configure php源碼
如今應該對configure很熟悉了吧,用普通用戶執行

[feng@fsvps php-5.3.14]$ ./configure --prefix=/usr/local/php53 --with-config-file-path=/usr/local/etc --with-config-file-scan-dir=/usr/local/etc/php.d --mandir=/usr/local/man --enable-fpm --enable-calendar --with-mcrypt --enable-ftp --with-zlib --with-bz2 --with-curl --with-gd --enable-exif --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-mbstring --with-mysql --with-mysqli --with-pdo-mysql --enable-zip --enable-bcmath --with-bz2

這一步要花幾分鐘時間,不出意外將出現以下消息:

+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+

Thank you for using PHP.
按下來,make,這一步更慢,可能要二十分鐘,耐心等,或者作點其它事情。

看到以下消息,就是完成了。

Build complete.
Don't forget to run 'make test'。
能夠執行一下make test 檢測一下,不過通常沒有必要,切換到root身份運行make install安裝。

[root@fsvps php-5.3.14]# make install
最好記下來這裏的消息,它是php的幾個重要配置文件的默認路徑,下面用得着。

配置並啓動php-fpm進程
php-fpm的配置文件位於/usr/local/php53/etc/,這裏有個php-fpm.conf.default,用它複製出php-fpm.conf

[root@fsvps php-5.3.14]# ls -l /usr/local/php53/etc/

-rw-r--r-- 1 root root 1172 7月 1 07:20 pear.conf
-rw-r--r-- 1 root root 20891 7月 1 07:20 php-fpm.conf.default

[root@fsvps php-5.3.14]# cp /usr/local/php53/etc/php-fpm.conf{.default,}
修改php-fpm.conf以下幾處:

(約第25行) pid = /var/run/php-fpm.pid
(約第32行) error_log = /var/log/php-fpm.log
(約第190行) pm = static

啓動php-fpm進程

[root@fsvps php-5.3.14]# /usr/local/php53/sbin/php-fpm
執行後,沒有任何輸出。若是有錯誤請查看php-fpm的日誌文件 /var/log/php-fpm.log

整合 PHP 與 nginx
直到如今,咱們的nginx仍是隻能處理靜態文件,咱們接下來要作的是:讓nginx把對.php文件的請求,轉給php-fpm來處理。

打開nginx配置文件,在server{...}節點裏面,有這樣一行 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 ,下面的 location ...{...}節點取消註釋,改爲以下形式(修改部分使用紅字加粗):

location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/default$fastcgi_script_name;
include fastcgi_params;
}

保存,檢查配置nginx -t,無誤後從新加載nginx配置 nginx -s reload

寫一個php程序文件 /var/www/html/default/phpinfo.php 內容爲:
<?php
phpinfo();
?>

用瀏覽器經過ip地址訪問phpinfo.php,看到你親自編譯的nginx+php-fpm在工做了吧。

相關文章
相關標籤/搜索