LNMP環境搭建之編譯安裝指南(php-5.3.27.tar.gz)

測試環境:CentOS release 6.5 (Final)php

軟件安裝:nginx   mysql-5.5.32-linux2.6-x86_64.tar.gz   php-5.3.27.tar.gz html

一、mysql安裝詳見:http://www.javashuo.com/article/p-fjcvcymw-ke.htmlmysql

二、nginx安裝詳見:http://www.javashuo.com/article/p-qvjzjeik-kc.html     http://www.javashuo.com/article/p-cqggbjku-kc.htmllinux

三、PHH安裝以下:nginx

1、php安裝準備程序員

①yum安裝php所依賴的包web

[root@bqh-118 php]# yum -y install zlib libxml libjpeg freetype libpng gd curl libiconv zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel

②檢測機器是否已經安裝好算法

[root@bqh-118 php]# rpm -qa zlib libxml libjpeg freetype libpng gd curl libiconv zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel

③安裝libiconv-1.14.tar.gz  -----(https://excellmedia.dl.sourceforge.net/project/korwah/source/libiconv/libiconv-1.14.tar.gz)sql

 
 
[root@bqh-118 php]# tar zxf libiconv-1.14.tar.gz 
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
make
make install

④快速安裝libmcrypt擴展庫(epel源方法來安裝) 數據庫

[root@bqh-118 yum.repos.d]#wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
[root@bqh-118 yum.repos.d]#yum makecache
[root@bqh-118 yum.repos.d]# yum install libmcrypt-devel -y

⑤快速安裝mhash加密算法擴展庫

  Mhash是基於離散數學原理的不可逆向的php加密方式擴展庫,其在默認狀況下開啓,mhash的能夠用於場景檢驗數值,消息摘要,小小認證碼,以及無需原文的關鍵信息保存(如密碼)等。

  Mhash爲PHP提供了多種哈希算法,如MD5,SHA1,GOST等,你能夠經過MHASH_hashname()來查看支持的算法有哪些。

注意問題:該擴展不能提供 最新的哈希算法;該擴展結果原則上運算不可逆。

[root@bqh-118 php]# yum install mhash mhash-devel -y

⑥快速安裝mcrypt加密擴展庫

  php程序員們在編寫程序時,除了要保證代碼的高性能以外,還有一點是很是重要的,那就是程序的安全性保障。php除了自帶的幾種加密函數外,還有功能更全面的php加密擴展庫mcrypt和mhash。其中,mcrypt擴展能夠實現加密解密功能,就是既能將明文密碼加

密,也能夠密文還原。mcrypt是php裏面重要的加密支持擴扎庫,該庫在默認狀況下不開啓。編輯本段支持的算法和加密模式:mcrypt庫支持20多種加密算法和8中加密模式,具體能夠經過函數crypt_list_algorithms()和mcrypt_list_modes()來顯示。

[root@bqh-118 php]# yum install mcrypt -y

⑦安裝libxslt-devel

[root@bqh-118 php]# yum -y install libxslt-devel

 以上安裝php依賴包就ok了。

2、開始安裝PHP服務

 ①下載php-5.3.27.tar.gz 並解壓。 

下載php:https://www.php.net/distributions/php-5.3.27.tar.gz

[root@bqh-118 php]# tar xf php-5.3.27.tar.gz

②編譯安裝PHP

[root@bqh-118 php]# cd php-5.3.27 
[root@bqh-118 php-5.3.27]#./configure \
--prefix=/application/php-5.3.27 \
--with-mysql=/application/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-curlwrappers \
--enable-mbregex \
--enable-mbstring \
--enable-fpm \
--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=nginx \
--with-fpm-group=nginx \
--enable-ftp

注意:在make前加上這兩條命令:

[root@bqh-118 php-5.3.27]# ln -s /application/mysql/lib/libmysqlclient.so.18 /usr/lib64/
[root@bqh-118 php-5.3.27]# touch ext/phar/phar.phar
[root@bqh-118 php-5.3.27]# make && make install      #安裝php生成文件到系統
......
.........
Installing header files:          /application/php-5.3.27/include/php/
Installing helper programs:       /application/php-5.3.27/bin/
  program: phpize
  program: php-config
Installing man pages:             /application/php-5.3.27/man/man1/
  page: phpize.1
  page: php-config.1
Installing PEAR environment:      /application/php-5.3.27/lib/php/
[PEAR] Archive_Tar    - installed: 1.3.11
[PEAR] Console_Getopt - installed: 1.3.1
warning: pear/PEAR requires package "pear/Structures_Graph" (recommended version 1.0.4)
warning: pear/PEAR requires package "pear/XML_Util" (recommended version 1.2.1)
[PEAR] PEAR           - installed: 1.9.4
Wrote PEAR system config file at: /application/php-5.3.27/etc/pear.conf
You may want to add: /application/php-5.3.27/lib/php to your php.ini include_path
[PEAR] Structures_Graph- installed: 1.0.4
[PEAR] XML_Util       - installed: 1.2.1
/home/bqh/tools/php-5.3.27/build/shtool install -c ext/phar/phar.phar /application/php-5.3.27/bin
ln -s -f /application/php-5.3.27/bin/phar.phar /application/php-5.3.27/bin/phar
Installing PDO headers:          /application/php-5.3.27/include/php/ext/pdo/
[root@bqh-118 php-5.3.27]# echo $?
0

③配置php引擎配置文件php.ini

設置軟鏈接安全方便訪問:

[root@bqh-118 php-5.3.27]# ln -s /application/php-5.3.27/ /application/php
[root@bqh-118 php-5.3.27]# ls -l /application/php
lrwxrwxrwx 1 root root 24 6月  23 07:07 /application/php -> /application/php-5.3.27/

拷貝php配置文件到php默認目錄下並改名爲php.ini

[root@bqh-118 php-5.3.27]# ll ./php.ini-*
-rw-r--r-- 1 101 101 69606 7月  11 2013 ./php.ini-development   #開發
-rw-r--r-- 1 101 101 69627 7月  11 2013 ./php.ini-production    #生產
[root@bqh-118 php-5.3.27]# cp php.ini-production /application/php/lib/php.ini

④配置php服務(fastcgi模式)配置文件php-fpm.conf

[root@bqh-118 php-5.3.27]# ll /application/php/etc/
總用量 28
-rw-r--r-- 1 root root  1242 6月  23 06:32 pear.conf
-rw-r--r-- 1 root root 21690 6月  23 06:32 php-fpm.conf.default
[root@bqh-118 php-5.3.27]# cp /application/php/etc/php-fpm.conf.default /application/php/etc/php-fpm.conf
[root@bqh-118 php-5.3.27]# ll /application/php/etc/
總用量 52
-rw-r--r-- 1 root root  1242 6月  23 06:32 pear.conf
-rw-r--r-- 1 root root 21690 6月  23 07:31 php-fpm.conf
-rw-r--r-- 1 root root 21690 6月  23 06:32 php-fpm.conf.default

⑤啓動php進程

[root@bqh-118 php-5.3.27]# /application/php/sbin/php-fpm 
[root@bqh-118 php-5.3.27]# ps -ef|grep php-fpm|grep -v grep
root     128897      1  0 07:55 ?        00:00:00 php-fpm: master process (/application/php-5.3.27/etc/php-fpm.conf)
nginx    128898 128897  0 07:55 ?        00:00:00 php-fpm: pool www            
nginx    128899 128897  0 07:55 ?        00:00:00 php-fpm: pool www            
nginx    128900 128897  0 07:55 ?        00:00:00 php-fpm: pool www            
nginx    128901 128897  0 07:55 ?        00:00:00 php-fpm: pool www            
nginx    128902 128897  0 07:55 ?        00:00:00 php-fpm: pool www            
nginx    128903 128897  0 07:55 ?        00:00:00 php-fpm: pool www            
nginx    128904 128897  0 07:55 ?        00:00:00 php-fpm: pool www            
nginx    128905 128897  0 07:55 ?        00:00:00 php-fpm: pool www            
nginx    128906 128897  0 07:55 ?        00:00:00 php-fpm: pool www            
nginx    128907 128897  0 07:55 ?        00:00:00 php-fpm: pool www            
nginx    128908 128897  0 07:55 ?        00:00:00 php-fpm: pool www            
nginx    128909 128897  0 07:55 ?        00:00:00 php-fpm: pool www            
nginx    128910 128897  0 07:55 ?        00:00:00 php-fpm: pool www            
nginx    128911 128897  0 07:55 ?        00:00:00 php-fpm: pool www            
nginx    128912 128897  0 07:55 ?        00:00:00 php-fpm: pool www            
nginx    128913 128897  0 07:55 ?        00:00:00 php-fpm: pool www            
[root@bqh-118 php-5.3.27]# ss -lntup|grep php-fpm
tcp    LISTEN     0      128            127.0.0.1:9000                  *:*      users:(("php-fpm",128897,7),("php-fpm
",128898,0),("php-fpm",128899,0),("php-fpm",128900,0),("php-fpm",128901,0),("php-fpm",128902,0),("php-fpm",128903,0),("php-fpm",128904,0),("php-fpm",128905,0),("php-fpm",128906,0),("php-fpm",128907,0),("php-fpm",128908,0),("php-fpm",128909,0),("php-fpm",128910,0),("php-fpm",128911,0),("php-fpm",128912,0),("php-fpm",128913,0))

⑥測試php

在nginx站點目錄下寫一個test_phpinfo.php代碼測試php

[root@bqh-118 html]# vim test_phpinfo.php 

<?php
    phpinfo();
?>

 配置nginx.conf

[root@bqh-118 conf]# vim nginx.conf

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

 server {
        listen       80;
        server_name  www.test.com;
        root html;
     location / { index index.html index.htm; } location ~ .*\.(php|php5)?$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } error_page 500 502 503 504 /50x.html; } }

⑦ 刷新配置,打開瀏覽器輸入地址結果看是否成功。

[root@bqh-118 html]# /application/nginx/sbin/nginx -t
nginx: the configuration file /application/nginx-1.6.3/conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.6.3/conf/nginx.conf test is successful
[root@bqh-118 html]# /application/nginx/sbin/nginx -s reload

http://192.168.0.118/test_phpinfo.php 或 http://www.test.com/test_phpinfo.php

 ok,目前nginx到php已經通了,下面咱們須要測試php到mysql是否通。

⑧在nginx站點目錄下再寫一個test_mysql.php代碼測試php

[root@bqh-118 html]# vim test_mysql.php
[root@bqh-118 html]# cat test_mysql.php 
<?php
$link_id=mysql_connect('localhost','root','123456') or mysql_error();
if($link_id) {
   echo "MySQL connection succeeded!";
  }
else {
   echo mysql_error();
  }
?>

 瀏覽器輸入地址:http://192.168.0.118/test_mysql.php 或 http://www.test.com/test_mysql.php

ok測試沒有問題。

假如咱們把mysql密碼改了,咱們再來測試一下效果:

注意:通常企業會把nginx+mysql安裝到同一臺服務器,web(php)單獨一臺服務器;同時要想裝PHP服務,必須先裝nginx和mysql服務,否則白裝php了。(沒法生存mysql配置,數據庫鏈接異常等)

到此爲止,nginx→php→mysql測試一通; LNMP環境搭建ok。

相關文章
相關標籤/搜索