PHP安裝 (結合之前的nginx安裝與mysql安裝組合為lnmp)

來源:互聯網
上載者:User

標籤:php5   管理   col   提示   run   fast   install   wan   rpm包   

檢查安裝PHP所需的lib庫
yum -y install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-develyum -y install freetype-devel libpng-devel gd libcurl-devel libxslt-develyum -y install openssl openssl-devel        #PHP所需的依賴包

安裝yum無法安裝的libiconv庫  #以下4個包可以下載後打包為rpm包以供下次使用

yum -y install wget  wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gztar xf libiconv-1.14.tar.gz -C /usr/src/cd /usr/src/libiconv-1.14/./configure --prefix=/usr/local/libiconv && make && make install

安裝libmcrypt庫  mhash加密擴充庫  mcrvpt加密擴充庫

用 epel  yum源 進行安裝

yum -y install mhash mcrypt  libmcrypt-devel

解壓PHP的源碼包

tar xf php-5.3.28.tar.gz -C /usr/src/cd /usr/src/php-5.3.28/

編譯

./configure --prefix=/usr/local/php5.3.28 --with-mysql=/usr/local/mysql --with-iconv-dir=/usr/local/libiconv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-short-tags --enable-zend-multibyte --enable-static --with-xsl --with-fpm-user=www --with-fpm-group=www --enable-ftp

編譯後這樣顯示表示編譯成功

#部分參數解釋

:--prefix=/usr/local/php5.2.28

表示指定PHP的安裝路徑為/usr/local/php5.3.28

:--with-mysql=/usr/local/mysql

表示需要指定MySQL的安裝路徑,安裝PHP需要的MySQL相關內容。當然,如果沒有MySQL軟體包,也可以不單獨安裝,這樣的情況可使用--with-mysql=mysqlnd替代--with-mysql=/usr/local/mysql,因為PHP軟體裡已經內建了串連MySQL的用戶端工具。

:--with-fpm-user=www

nginx表示指定PHP-FPM進程管理的使用者為www,此處最好和Nginx服務使用者統一

: --with-fpm-group=www

表示指定PHP-FPM進程管理的組為www,此處最好與Nginx服務使用者組統一。

:--enable-fpm

表示啟用PHP-FPM方式服務,即以FastCGIF方式運行PHP服務。

正確執行前文配置PHP軟體的./configure系列命令後,就可以編譯PHP軟體了,具體操作過程如下:

ln -s /usr/local/mysql/lib/libmysqlclient.so.18ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/touch ext/phar/phar.pharmake#make最後的正確提示Build complete.Don‘t forget to run ‘make test‘.make install

設定檔

ln -s /usr/local/php5.3.28/ /usr/local/php      #拷貝PHP設定檔到PHP預設目錄,並變更檔名稱為php.incd /usr/src/php-5.3.28/cp php.ini-production /usr/local/php/lib/php.ini    #配置PHP(FastCGI方式)的設定檔php-fpm.confcd /usr/local/php/etc/cp php-fpm.conf.default php-fpm.conf           
#啟動PHP服務php-fpm,命令如下/usr/local/php/sbin/php-fpm            ps -ef | grep php-fpmroot 126611 1 0 13:36 ? 00:00:00 php-fpm: master process (/usr/local/php5.3.28/etc/php-fpm.conf)nginx 126612 126611 0 13:36 ? 00:00:00 php-fpm: pool www nginx 126613 126611 0 13:36 ? 00:00:00 php-fpm: pool www root 126619 126548 0 13:39 pts/1 00:00:00 grep php-fpm
配置Nginx支援PHP程式請求訪問

 

修改/usr/local/nginx/conf/extra下的www.conf 虛擬使用者設定檔server {        listen       80;        server_name  www.wk.com;        location / {            root   /var/www/html/wwwcom;            index  index.html index.htm;        }        error_page   500 502 503 504  /50x.html;        location = /50x.html {            root   /var/www/html;        }        location ~.*\.(php|php5)?$ {                               #新增支援php            root    /var/www/html/wwwcom;            fastcgi_pass    127.0.0.1:9000;            fastcgi_index   index.php;            include     fastcgi.conf;        }    }nginx -t            #檢測文法nginx -s reload        #重新啟動
測試lnmp                     

 

cd /var/www/html/wwwcom/echo "<?php phpinfo(); ?>" >test_info.php

用戶端web服務:i服務端p地址/test_info.php

 

針對Nginx請求訪問PHP,然後對PHP串連MySQL的情況進行測試

vim test_mysql.php<?php//$link_id=mysql_connect(‘主機名稱‘,‘使用者‘,‘密碼‘);$link_id=mysql_connect(‘localhost‘,‘root‘,‘123456‘);if($link_id){echo "mysql successful by Mr.wang!";}else{echo mysql_error();}?>

 

 

PHP安裝 (結合之前的nginx安裝與mysql安裝組合為lnmp)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.