Centos 6.9 Build Install LAMP Apache 2.4 + Mysql 5.7 + php5.6.34 + fast-cgi + xcache
实验环境:VMware Workstation Pro 14(试用版)系统平台:CentOS release 6.9 (Final) 内核 2.6.32-696.el6.x86_64Apache/2.4.29 (Unix)PHP 5.6.34 (cli)xcache 3.2.0
1. Compile and install Apache 2.4
Refer to the CentOS 6.9 apahce 2.4.29 compiled installation
2. Binary installation MySQL 5.7
Refer to CentOS 6.9 Custom single-instance binary installation mysql5.7.21
3. Download stable version on PHP website
http://php.net/downloads.php
# wget http://hk1.php.net/distributions/php-5.6.34.tar.bz2
4. Installing dependent Packages
有个别包需要EPEL源,可提前配置好Aliyun的Yum源注意:以下依赖包仅仅限于下面演示的编译参数,实际按需。#yum install bzip2-devel libxml2-devel libmcrypt-devel libmcrypt curl-devel gd-devel如果需要后期动态添加模块,还需要安装autoconf
Note: php-7.0 above version uses--enable-mysqlnd--withmysqli=mysqlnd, the original--with-mysql no longer support
5. Compiling the installation
Compile parameters
For the MySQL API approach, let's look at:
PHP5.3以上版本,为了链接MySQL数据库,可以指定mysqlnd,这样在本机就不需要先安装MySQL或MySQL开发包。mysqlnd从php 5.3开始可用,可以编译时绑定到它(而不用和具体的MySQL客户端库绑定形成依赖)。从PHP 5.4开始,对于未明确指定--with-mysql的情形,mysql本地驱动将会被安装。可以参考如下配置:比如:--with-mysql > 相当于该参数值为mysqlnd--with-mysqli > 相当于该参数值为mysqlnd--with-pdo-mysql > 相当于该参数值为mysqlnd因为,--with-mysqli=/usr/local/mysql/bin/mysql_config 这种才是明确指定的表示方法
# 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
Compiling and installing
# make -j 8出现Build complete. 那么,恭喜编译成功# make install以下这些提示,按需。Wrote PEAR system config file at: /usr/local/php-5.6.34/etc/pear.confYou 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/binln -s -f phar.phar /usr/local/php-5.6.34/bin/pharInstalling PDO headers: /usr/local/php-5.6.34/include/php/ext/pdo/
Create a soft link to easily manage the version
#cd /usr/local/#ln -s php-5.6.34/ php
6. Copy the PHP configuration file
注意,这些文件是在源码目录里# 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创建一个存放其他扩展配置的目录# mkdir /etc/php.d
7. Modify the PHP-FPM startup script
# vim /etc/rc.d/init.d/php-fpm > 这一步不修改也行,只不过这里是为了后续切换不同版本时方便prefix=/usr/local/php > 把这行修改为指定的编译路径
8. Generate the PHP-FPM configuration file
# 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. Add PHP-FPM to start the service
# chkconfig --add php-fpm# chkconfig php-fpm on
10. Configure HTTPD support PHP
# vim/etc/httpd2.4/httpd.conf Make sure the following 2 uncomment LoadModule proxy_module modules/mod_proxy.soloadmodule proxy_fcgi_module modules/mod_proxy_fcgi.so# If you are using a virtual host form, add the following 4 lines to the host label AddType application/x-httpd-php. Phpaddtype application/ X-httpd-php-source. Phpsproxyrequests offproxypassmatch ^/(. *\.php) $ fcgi://127.0.0.1:9000/app/www/virtualhost/$ 1 where/app/www/virtualhost refers to the site file directory example: <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 Prox Ypassmatch ^/(. *\.php) $ fcgi://127.0.0.1:9000/app/www/virtualhost/$1 <ifmodule dir_module> dir Ectoryindex index.php index.html </IfModule> <directory "/app/www/virtualhost" > A Llowoverride None Options none Require all granted </directory></virtualhost ># Service httpd restart# service php-fpm start
10. Test PHP
#ss -nltfcgi正在监听端口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();?>
11. Connect to the database test
Create an account to connect to in MySQL
mysql> create user [email protected]‘192.168.5.102‘ identified by ‘password‘;mysql5.7数据库下已经没有password这个字段了,password字段改成了authentication_string并且密码策略控制着密码相关以下为修改默认的密码策略,0=LOW,至少8个字符mysql> set global validate_password_policy=0
The test code is as follows:
# 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连接成功
The following code determines whether the MySQL and mysqli extensions are installed
<?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. Testing for performance before the accelerator is enabled
#ab-C 1000-n 192.168.5.102/check.phpserver software:apache/2.4.29server Hostname:192.168.5.102serve R port:80document Path:/check.phpdocument length:12 bytesconcurrency level:1000time ta Ken for tests:6.751 secondscomplete requests:5000failed requests:0write errors:0total Transfer red:915000 byteshtml transferred:60000 bytesrequests 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:1 32.35 [Kbytes/sec] receivedconnection times (ms) min MEAN[+/-SD] Median maxconnect:0 210 625.4 1 3019processing:1 436 954.0 6676waiting:1 435 954.0 189 6675total:63 645 1 295.6 194 6734Percentage 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. Compile and install XCache to download the source package
Http://xcache.lighttpd.net
Http://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz
Install the dependency packages required by phpize
#yum install m4 autoconf
Decompression xcache-3.2.0.tar.bz2
#tar xvf xcache-3.2.0.tar.gz
Generate Xcanche compiled files
# cd xcache-3.2.0#/usr/local/php/bin/phpize > 注意,这里指向的是php目录Configuring for:PHP Api Version: 20131106Zend Module Api No: 20131226Zend Extension Api No: 220131226
Compiling and installing XCache
# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config注意,--sysconfdir指向的是Php存放配置文件的目录# make && make installInstalling shared extensions: /usr/local/php-5.6.34/lib/php/extensions/no-debug-non-zts-20131226/
Copying XCache configuration Files
#cp xcache.ini /etc/php.d/
Restart the PHP service and verify
# service php-fpm restart# /usr/local/php/bin/php -m|grep -i xcacheXCacheXCache Cacher
You can also see through phpinfo
14. Test performance after enabling the accelerator
#vim/etc/php.d/xcache.inixcache.optimizer = onxcache.size = 1024m#ab-c 1000-n 5000 192.168.5.1 02/check.phpserver software:apache/2.4.29server hostname:192.168.5.102server port:80document P Ath:/check.phpdocument length:12 bytesconcurrency level:1000time taken for tests:6.541 SECONDSC Omplete requests:5000failed requests:0write errors:0total transferred:915000 byteshtml Tran sferred:60000 bytesrequests per second:764.46 [#/sec] (mean) time per request:1308.116 [MS] (mean) time PE R request:1.308 [MS] (mean, across all concurrent requests) Transfer rate:136.62 [kbytes/sec] Receivedconn Ection times (ms) min MEAN[+/-SD] Median maxconnect:0 277 612.3 2 3017processing:1 425 835.1 156 4186waiting:1 424 835.1 155 4185total:61 702 1187.2 167 5262Percentage 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)
The seemingly simple test didn't find any advantage.
Centos 6.9 Compile and install LAMP + XCache