溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Centos 6.9 編譯安裝 LAMP + xcache

發(fā)布時間:2020-06-26 19:54:14 來源:網(wǎng)絡(luò) 閱讀:727 作者:ljpwinxp 欄目:MySQL數(shù)據(jù)庫

Centos 6.9 編譯安裝 LAMP apache 2.4 + Mysql 5.7 + php5.6.34 + Fast-cgi + xcache

實驗環(huán)境:VMware Workstation Pro 14(試用版)
系統(tǒng)平臺:
CentOS release 6.9 (Final)             內(nèi)核  2.6.32-696.el6.x86_64
Apache/2.4.29 (Unix)
PHP 5.6.34 (cli)
xcache 3.2.0

1. 編譯安裝apache 2.4

參考Centos 6.9 apahce 2.4.29編譯安裝

2. 二進制安裝Mysql 5.7

參考CentOS 6.9 自定義單實例 二進制方式 安裝mysql5.7.21

3. PHP官網(wǎng)下載Stable版本

http://php.net/downloads.php

# wget http://hk1.php.net/distributions/php-5.6.34.tar.bz2

4.安裝依賴包

有個別包需要EPEL源,可提前配置好Aliyun的Yum源

注意:以下依賴包僅僅限于下面演示的編譯參數(shù),實際按需。
#yum install bzip2-devel libxml2-devel libmcrypt-devel libmcrypt curl-devel gd-devel
如果需要后期動態(tài)添加模塊,還需要安裝autoconf

注意:php-7.0以上版本使用--enable-mysqlnd --withmysqli=mysqlnd ,原--with-mysql不再支持

5.編譯安裝

編譯參數(shù)

對于mysql的api方法,先了解一下:

PHP5.3以上版本,為了鏈接MySQL數(shù)據(jù)庫,可以指定mysqlnd,這樣在本機就不需要先安裝MySQL或MySQL開發(fā)包。
mysqlnd從php 5.3開始可用,可以編譯時綁定到它(而不用和具體的MySQL客戶端庫綁定形成依賴)。
從PHP 5.4開始,對于未明確指定--with-mysql的情形,mysql本地驅(qū)動將會被安裝。
可以參考如下配置:
比如:

--with-mysql       > 相當(dāng)于該參數(shù)值為mysqlnd
--with-mysqli      > 相當(dāng)于該參數(shù)值為mysqlnd
--with-pdo-mysql   > 相當(dāng)于該參數(shù)值為mysqlnd
因為,--with-mysqli=/usr/local/mysql/bin/mysql_config  這種才是明確指定的表示方法

Centos 6.9 編譯安裝 LAMP + xcache

# tar xvf php-5.6.34.tar.bz2
# cd php-5.6.34

./configure --prefix=/usr/local/php-5.6.34 \
--with-openssl \
--enable-mysqlnd \
--with-mysql=/usr/local/mysql \
--with-mysqli \
--with-pdo-mysql \
--enable-mbstring \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--enable-sockets \
--enable-fpm \
--with-mcrypt \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--with-bz2 \
--with-iconv \
--with-gd \
--with-curl \
--disable-debug \
--enable-calendar

編譯與安裝

# make -j 8
出現(xiàn)Build complete. 那么,恭喜編譯成功

# make install

以下這些提示,按需。
Wrote PEAR system config file at: /usr/local/php-5.6.34/etc/pear.conf
You may want to add: /usr/local/php-5.6.34/lib/php to your php.ini include_path
/app/httpd/php-5.6.34/build/shtool install -c ext/phar/phar.phar /usr/local/php-5.6.34/bin
ln -s -f phar.phar /usr/local/php-5.6.34/bin/phar
Installing PDO headers:           /usr/local/php-5.6.34/include/php/ext/pdo/

創(chuàng)建一個軟鏈接,方便管理版本

#cd /usr/local/
#ln -s php-5.6.34/ php

6.復(fù)制php配置文件

注意,這些文件是在源碼目錄里
# cp php.ini-production /etc/php.ini
# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
# chmod +x /etc/rc.d/init.d/php-fpm

創(chuàng)建一個存放其他擴展配置的目錄
# mkdir /etc/php.d

7.修改php-fpm啟動腳本

# vim /etc/rc.d/init.d/php-fpm   > 這一步不修改也行,只不過這里是為了后續(xù)切換不同版本時方便

prefix=/usr/local/php   > 把這行修改為指定的編譯路徑

8.生成php-fpm配置文件

# sed -ri.bak s#php-5.6.34#php#g /usr/local/php/etc/php-fpm.conf.default
# mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
# mv /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf    > 不用

9.添加php-fpm為啟動服務(wù)

# chkconfig --add php-fpm
# chkconfig php-fpm on

10.配置httpd支持php

# vim /etc/httpd2.4/httpd.conf
確保以下2條取消注釋
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

# 如果使用的是虛擬主機形式,把下面4行添加到主機標(biāo)簽中
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/app/www/virtualhost/$1

其中/app/www/virtualhost指的是站點文件目錄

例子:

<VirtualHost *:80>
    DocumentRoot "/app/www/virtualhost"
    ServerName www.hunk.tech
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/app/www/virtualhost/$1

        <IfModule dir_module>
                DirectoryIndex index.php index.html
        </IfModule>

        <Directory "/app/www/virtualhost">
                AllowOverride None
                Options None
                Require all granted
        </Directory>

</VirtualHost>

# service httpd restart
# service php-fpm start

10.測試php

#ss -nlt
fcgi正在監(jiān)聽端口
State      Recv-Q Send-Q                                           Local Address:Port 
LISTEN     0      128                                                  127.0.0.1:9000 

編輯一個php的測試文件
#vim /app/www/virtualhost/index.php

<?php
  phpinfo();
?>

Centos 6.9 編譯安裝 LAMP + xcache

11.連接數(shù)據(jù)庫測試

在mysql中創(chuàng)建一個用于連接的賬戶

mysql> create user test@'192.168.5.102' identified by 'password';

mysql5.7數(shù)據(jù)庫下已經(jīng)沒有password這個字段了,password字段改成了authentication_string
并且密碼策略控制著密碼相關(guān)

以下為修改默認(rèn)的密碼策略,0=LOW,至少8個字符
mysql> set global validate_password_policy=0

測試代碼如下:

# vim /app/www/virtualhost/check.php

<?php
$mysqli = new mysqli("localhost", "test", "12345678");

/* check connection */
if ($mysqli->connect_errno) {
    echo "連接失敗";
    exit();
}
echo "連接成功";

/* close connection */
$mysqli->close();
?>

# curl www.hunk.tech/check.php
連接成功

以下代碼為判斷mysql和mysqli擴展是否安裝

<?php
 function mysqlinstalled (){
  if (function_exists ("mysql_connect")){
   return true;
  } else {
   return false;
  }
 }
 function mysqliinstalled (){
  if (function_exists ("mysqli_connect")){
   return true;
  } else {
   return false;
  }
 }

 if (mysqlinstalled()){
  echo "<p>The mysql extension is installed.</p>";
 } else {
  echo "<p>The mysql extension is not installed..</p>";
 }
 if (mysqliinstalled()){
  echo "<p>The mysqli extension is installed.</p>";
 } else {
  echo "<p>The mysqli extension is not installed..</p>";
 }
?>

12.測試未啟用加速器前的性能

#ab -c 1000 -n 5000 192.168.5.102/check.php

Server Software:        Apache/2.4.29
Server Hostname:        192.168.5.102
Server Port:            80

Document Path:          /check.php
Document Length:        12 bytes

Concurrency Level:      1000
Time taken for tests:   6.751 seconds
Complete requests:      5000
Failed requests:        0
Write errors:           0
Total transferred:      915000 bytes
HTML transferred:       60000 bytes
Requests per second:    740.59 [#/sec] (mean)
Time per request:       1350.282 [ms] (mean)
Time per request:       1.350 [ms] (mean, across all concurrent requests)
Transfer rate:          132.35 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0  210 625.4      1    3019
Processing:     1  436 954.0    190    6676
Waiting:        1  435 954.0    189    6675
Total:         63  645 1295.6    194    6734

Percentage of the requests served within a certain time (ms)
  50%    194
  66%    215
  75%    335
  80%    405
  90%   1341
  95%   3439
  98%   6299
  99%   6697
 100%   6734 (longest request)

13.編譯安裝 xcache

去官網(wǎng)下載源碼包

http://xcache.lighttpd.net

http://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz

安裝phpize需要的依賴包

#yum install m4 autoconf

解壓縮xcache-3.2.0.tar.bz2

#tar xvf xcache-3.2.0.tar.gz

生成xcanche編譯文件

# cd xcache-3.2.0
#/usr/local/php/bin/phpize  > 注意,這里指向的是php目錄

Configuring for:
PHP Api Version:         20131106
Zend Module Api No:      20131226
Zend Extension Api No:   220131226

編譯安裝xcache

# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
注意,--sysconfdir指向的是Php存放配置文件的目錄

# make && make install

Installing shared extensions:     /usr/local/php-5.6.34/lib/php/extensions/no-debug-non-zts-20131226/

復(fù)制xcache配置文件

#cp xcache.ini /etc/php.d/

重啟php服務(wù)并驗證

# service php-fpm restart

# /usr/local/php/bin/php -m|grep -i xcache
XCache
XCache Cacher

通過phpinfo也可以看到

Centos 6.9 編譯安裝 LAMP + xcache

14.測試啟用加速器后的性能

#vim /etc/php.d/xcache.ini
xcache.optimizer =           On
xcache.size  =               1024M

#ab -c 1000 -n 5000 192.168.5.102/check.php

Server Software:        Apache/2.4.29
Server Hostname:        192.168.5.102
Server Port:            80

Document Path:          /check.php
Document Length:        12 bytes

Concurrency Level:      1000
Time taken for tests:   6.541 seconds
Complete requests:      5000
Failed requests:        0
Write errors:           0
Total transferred:      915000 bytes
HTML transferred:       60000 bytes
Requests per second:    764.46 [#/sec] (mean)
Time per request:       1308.116 [ms] (mean)
Time per request:       1.308 [ms] (mean, across all concurrent requests)
Transfer rate:          136.62 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0  277 612.3      2    3017
Processing:     1  425 835.1    156    4186
Waiting:        1  424 835.1    155    4185
Total:         61  702 1187.2    167    5262

Percentage of the requests served within a certain time (ms)
  50%    167
  66%    235
  75%    436
  80%   1021
  90%   2137
  95%   3817
  98%   5138
  99%   5197
 100%   5262 (longest request)

貌似簡單的測試并沒有發(fā)現(xiàn)什么優(yōu)勢呢

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI