環境:CentOS6.7,minimal安裝。
前提條件:安裝了編譯環境,安裝了Apache/Nginx,安裝了MySQL/MariaDB。具體安裝見:http://www.www58058.com/16583 http://www.www58058.com/17497
1、解決依賴關系:
請配置好yum源(系統安裝源及epel源)后執行如下命令:
# yum -y groupinstall "Desktop Platform Development" # yum -y install bzip2-devel libmcrypt-devel libxml2-devel
[root@localhost php-5.4.45]# yum -y install bzip2-devel libmcrypt-devel libxml2-devel Loaded plugins: fastestmirror Setting up Install Process Loading mirror speeds from cached hostfile * base: centos.ustc.edu.cn * extras: mirrors.tuna.tsinghua.edu.cn * updates: mirrors.tuna.tsinghua.edu.cn Package bzip2-devel-1.0.5-7.el6_0.x86_64 already installed and latest version No package libmcrypt-devel available. Package libxml2-devel-2.7.6-21.el6.x86_64 already installed and latest version Nothing to do
如果提示說 libmcrypt-devel無法安裝,請安裝epel源
解決方法:
yum install epel-release //擴展包更新包
yum update //更新yum源
yum install libmcrypt libmcrypt-devel mcrypt mhash 就ok了
2、編譯安裝php-5.4.26
首先下載源碼包至本地目錄,下載位置ftp://172.16.0.1/pub/Sources/new_lamp,或者用wget方法下載,具體下載用法見我前面博客。
# tar xf php-5.4.26.tar.bz2 # cd php-5.4.26 # ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/apache24/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts
說明:
1、這里為了支持apache的worker或event這兩個MPM,編譯時使用了–enable-maintainer-zts選項。
2、如果使用PHP5.3以上版本,為了鏈接MySQL數據庫,可以指定mysqlnd,這樣在本機就不需要先安裝MySQL或MySQL開發包了。mysqlnd從php 5.3開始可用,可以編譯時綁定到它(而不用和具體的MySQL客戶端庫綁定形成依賴),但從PHP 5.4開始它就是默認設置了。
# ./configure --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd # make -j 10 # make test # make intall
3、為php提供配置文件
# cp php.ini-production /etc/php.ini
編輯apache配置文件httpd.conf,以apache支持php
# vim /usr/local/apache24/conf/httpd.conf
1)添加如下二行
AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps
2)定位至DirectoryIndex index.html
修改為:
DirectoryIndex index.php index.html
而后重新啟動httpd,或讓其重新載入配置文件即可測試php是否已經可以正常使用。
測試頁面index.php示例如下:
<?php $link = mysql_connect('127.0.0.1','root','mageedu'); if ($link) echo "Success..."; else echo "Failure..."; mysql_close(); phpinfo(); ?>
4、安裝phpMyadmin
# unzipphpMyAdmin-4.6.2-all-languages # mv phpMyAdmin-4.6.2-all-languages /usr/local/apache24/htdocs/pmc # cd/usr/local/apache24/htdocs/pmc # cp config.sample.inc.php config.inc.php # vim /usr/local/apache24/htdocs/pmc/config.inc.php
填充以下參數(這里的參數隨便填寫):
$cfg['blowfish_secret'] = 'sdaf32gretg435yerfwr<F>saadf';
測試訪問phpMyadmin。訪問phpMyadmin時,mysql需要密碼,空密碼不允許訪問。
給mysql用戶添加密碼,刪除空密碼帳號。
訪問測試:http://192.168.163.13/pmc
5、安裝xcache,為php加速
1)壓力測試:
ab -c 10 -n 100 http://192.168.163.13/pmc/index.php ab -c 100 -n 10000 http://192.168.163.13/pmc/index.php
多測試幾次。然后安裝xcache后再壓力測試,對比。
2)安裝xcache:
# tar xf xcache-3.2.0.tar.gz # cd xcache-3.2.0 # /usr/local/php/bin/phpize # ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config # make && make install
3)編輯php.ini,整合php和xcache
安裝結束時,會出現類似如下行:
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20131226/
首先將xcache提供的樣例配置導入php.ini?;蛘邉摻╬hp配置文件的分段目錄
[root@localhost xcache-3.2.0]# mkdir /etc/php.d [root@localhost xcache-3.2.0]# cp xcache.ini /etc/php.d [root@localhost xcache-3.2.0]# vim /etc/php.d/xcache.ini [root@localhost xcache-3.2.0]# service httpd24 reload
說明:xcache.ini文件在xcache的源碼目錄中。
接下來編輯/etc/php.d/xcache.ini,找到zend_extension開頭的行,修改為如下行:
zend_extension = /usr/local/php/lib/php/extensions/no-debug-zts-20131226/ xcache.so
注意:如果php.ini文件中有多條zend_extension指令行,要確保此新增的行排在第一位。
再測試對比。
原創文章,作者:Net17-卓格,如若轉載,請注明出處:http://www.www58058.com/17513