1. 程式人生 > >企業級LNMP環境應用實踐之PHP配置安裝

企業級LNMP環境應用實踐之PHP配置安裝

PHP配置安裝 Centos6

查看Nginx跟MySQL是否已經啟動! -E擴展的正則表達式

[root@web01 ~]# netstat -tunlp | grep -E "nginx|mysql"
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      1476/mysqld         
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      1585/nginx   

安裝PHP所需要的lib庫以及加密擴展庫

[root@web01 ~]# yum install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel -y
[root@web01 ~]# yum install freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libxslt-devel -y
[root@web01 ~]# cd /home/oldboy/tools
[root@web01 tools]# wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
[root@web01 tools]# tar zxf libiconv-1.14.tar.gz
[root@web01 tools]# cd libiconv-1.14
[root@web01 libiconv-1.14]# ./configure --prefix=/usr/local/libiconv
[root@web01 libiconv-1.14]# make
[root@web01 libiconv-1.14]# make install
[root@web01 libiconv-1.14]# wget -O /etc/yum.repos.d/epel.repo http://mirrirs.aliyun.com/repo/epel-6.repo
[root@web01 libiconv-1.14]# yum install -y libmcrypt-devel
[root@web01 libiconv-1.14]# yum install -y mhash
[root@web01 libiconv-1.14]# yum install -y mcrypt

下載PHP軟件包,並配置PHP軟件
特別註意!
(1)每個配置中的 “\”反斜線表示換行,後面不能有空白!
(2)最後一行沒有反斜線!
(3)--prefix=/application/php5.5.32 是指定PHP安裝的路徑
(4)--with-mysql=/application/mysql/ 是指定MySQL的安裝路徑。若沒有安裝MySQL可以用--with-mysql=mysqlnd替代!
(5)--with-fpm-user 跟--with-fpm-group是PHP-FPM的進程管理的組和用戶,盡量跟Nginx用戶和組一致!
(6)--enable-fpm 是啟動PFP-FPM服務,以FastCGIF方式運行PHP服務。

cd /home/oldboy/tools/
wget http://mirrors.sohu.com/php/php-5.5.32.tar.gz
tar zxf php-5.5.32.tar.gz
cd /home/oldboy/tools/php-5.5.32

./configure --prefix=/application/php5.5.32 --with-mysql=/application/mysql/ --with-pdo-mysql=mysqlnd --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-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --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-soap --enable-short-tags --enable-static --with-xsl --with-fpm-user=www --with-fpm-group=www --enable-ftp --enable-opcache=no

在make之前,要先做這兩步!

[root@web01 tools]# ln -s /application/mysql/lib/libmysqlclient.so.18 /usr/lib64/
[root@web01 tools]# cd php-5.5.32
[root@web01 php-5.5.32]# touch ext/phar/phar.phar
[root@web01 php-5.5.32]# make

結果出現這樣,表示編譯成功了!

Generating phar.php
Generating phar.phar
PEAR package PHP_Archive not installed: generated phar will require PHP‘s phar extension be enabled.
directorytreeiterator.inc
clicommand.inc
directorygraphiterator.inc
pharcommand.inc
invertedregexiterator.inc
phar.inc

Build complete.
Don‘t forget to run ‘make test‘.

[root@web01 php-5.5.32]# echo $?
0

[root@web01 php-5.5.32]# make install

make install 成功結束後,最後兩行內容如下:

ln -s -f phar.phar /application/php5.5.32/bin/phar
Installing PDO headers:          /application/php5.5.32/include/php/ext/pdo/
[root@web01 php-5.5.32]# ln -s /application/php5.5.32/ /application/php
[root@web01 php-5.5.32]# ls /application/php
bin  etc  include  lib  php  sbin  var
[root@web01 php-5.5.32]# cp php.ini-production /application/php/lib/php.ini
[root@web01 php-5.5.32]# ls -l /application/php/lib/php.ini 
-rw-r--r-- 1 root root 69266 Mar 10 11:45 /application/php/lib/php.ini
[root@web01 php-5.5.32]# cd /application/php/etc/
[root@web01 etc]# ls
pear.conf  php-fpm.conf.default
[root@web01 etc]# cp php-fpm.conf.default php-fpm.conf
[root@web01 etc]# /application/php/sbin/php-fpm 
[root@web01 etc]# lsof -i :9000
COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
php-fpm 4347 root    7u  IPv4 117912      0t0  TCP localhost:cslistener (LISTEN)
php-fpm 4348  www    0u  IPv4 117912      0t0  TCP localhost:cslistener (LISTEN)
php-fpm 4349  www    0u  IPv4 117912      0t0  TCP localhost:cslistener (LISTEN)
[root@web01 etc]# ps -ef | grep php-fpm
root       4347      1  0 11:50 ?        00:00:00 php-fpm: master process (/application/php5.5.32/etc/php-fpm.conf)
www        4348   4347  0 11:50 ?        00:00:00 php-fpm: pool www            
www        4349   4347  0 11:50 ?        00:00:00 php-fpm: pool www            
root       4352   1555  0 11:50 pts/1    00:00:00 grep php-fpm

企業級LNMP環境應用實踐之PHP配置安裝