二、编译安装PHP
编译之前都是需要检查开发环境;需要安装的包是否都已安装
[Linux87]#rpm -qa bzip2-devel libmcrypt-devel libxml2-devel
libxml2-devel-2.7.6-14.el6.x86_64
bzip2-devel-1.0.5-7.el6_0.x86_64
libmcrypt-devel-2.5.8-9.el6.x86_64
[Linux87]#
#如未安装;需要先用yum安装上
1、这边是每个服务单独作为一个服务器;所以编译时与放在一台机器上是有分别的;而且也不需要先安装MySQL;下面来直接编译PHP
[Linux87]#ls
php-5.4.26.tar.bz2 xcache-3.1.0.tar.bz2
[Linux87]#tar xf php-5.4.26.tar.bz2
[Linux87]#./configure --prefix=/usr/local/php --enable-fpm --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-libxml-dir=/usr --with-openssl --with-zlib --with-bz2 --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-mbstring --with-mcrypt --enable-sockets --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd
#注意:--with-mysql几个选项都要为mysqlnd;因为mysql服务器单独为另一台机器
+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+
Thank you for using PHP.
出现上述字符就说明可以继续安装了;
[Linux87]#make && make install
Installing PEAR environment: /usr/local/php/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: /usr/local/php/etc/pear.conf
You may want to add: /usr/local/php/lib/php to your php.ini include_path
[PEAR] Structures_Graph- installed: 1.0.4
[PEAR] XML_Util - installed: 1.2.1
/root/program/php-5.4.26/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin
ln -s -f /usr/local/php/bin/phar.phar /usr/local/php/bin/phar
Installing PDO headers: /usr/local/php/include/php/ext/pdo/
[Linux87]#
#到这里说明安装成功了;可能会有些报错说某些软件版本太低
2、下面配置PHP
配置php的配置文件
[Linux87]#cp php.ini-production /etc/php.ini
配置一个启动脚本
[Linux87]#cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
给执行权限
[Linux87]#chmod +x /etc/rc.d/init.d/php-fpm
加入chkconfig
[Linux87]#chkconfig --add php-fpm
[Linux87]#chkconfig php-fpm on
[Linux87]#chkconfig --list php-fpm
php-fpm 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[Linux87]#cd /usr/local/php/etc/
配置php-fpm配置文件
[Linux87]#cp php-fpm.conf.default php-fpm.conf
更改配置文件
[Linux87]#vi php-fpm.conf
[global]
; Pid file
; Note: the default prefix is /usr/local/php/var
; Default Value: none
pid = run/php-fpm.pid #这项启用;下面几项对应的改为相应的值即可
;
pm.max_children = 50
; The number of child processes created on startup.
; Note: Used only when pm is set to 'dynamic'
; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
pm.start_servers = 5
; The desired minimum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.min_spare_servers = 3
; The desired maximum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.max_spare_servers = 8
#更改完成后启动:
[Linux87]#service php-fpm start
Starting php-fpm done
[Linux87]#ss -tunl | grep 9000
tcp LISTEN 0 128 127.0.0.1:9000 *:*
#由于php-rpm是监听在9000端口,查看启动正常
3、与Apache整合到一起
[Linux87]#vi /usr/local/php/etc/php-fpm.conf
定位到listen;IP地址更改为别人可用访问进来的IP地址
; '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = 172.16.251.87:9000
[Linux87]#service php-fpm restart
[Linux87]#ss -tnul | grep 9000
tcp LISTEN 0 128 172.16.251.87:9000 *:*
[Linux87]#
[Linux87]#cd /var/www/
[Linux87]#mkdir linuxidc Androidj dark mydamin
#建立几个目录作为虚拟主机目录
4、配置Apache虚拟主机来使用PHP
到Apache主机上;找一个目录下面建立几个不同的目录作为虚拟主机目录;
[Linux86]#cd /usr/local/apache/
[Linux86]#mkdir -pv www/{linuxidc,androidj,dark,myadmin}
编辑主配置文件;开启虚拟主机;关闭中心主机
[Linux86]#vi /etc/httpd24/httpd.conf
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
#DocumentRoot "/usr/local/apache/htdocs" 注释掉
# Virtual hosts
Include /etc/httpd24/extra/httpd-vhosts.conf #开启这项
#定位AddType;添加下面两行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
定位至DirectoryIndex
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
DirectoryIndex index.php index.html #添加index.php
</IfModule>
定位到LoadModule
LoadModule proxy_module modules/mod_proxy.so #开启
#LoadModule proxy_connect_module modules/mod_proxy_connect.so
#LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
#LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so #开启
#
[Linux86]#vi /etc/httpd24/extra/httpd-vhosts.conf 编辑虚拟主机
<VirtualHost *:80>
ServerAdmin admin@linuxidc.com
DocumentRoot "/usr/local/apache/www/linuxidc" #指定Apache主机的站点目录
ServerName #指定主机名
ServerAlias linuxidc.com #主机别名
ErrorLog "/usr/local/apache/logs/linuxidc.error_log" #错误日志路径及名称
CustomLog "/usr/local/apache/logs/linuxidc.access_log" combined #访问日志路径及名称
ProxyRequests Off #关闭正向代理
ProxyPassMatch ^/(.*\.php)$ fcgi://172.16.251.87:9000/var/www/linuxidc/$1 #反向代理到PHP主机的站点目录
<Directory "/usr/local/apache/www/linuxidc"> #目录的访问权限配置
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin admin@androidj.com
DocumentRoot "/usr/local/apache/www/androidj"
ServerName
ServerAlias androidj.com
ErrorLog "/usr/local/apache/logs/androidj.error_log"
CustomLog "/usr/local/apache/logs/androidj.access_log" combined
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://172.16.251.87:9000/var/www/androidj/$1
<Directory "/usr/local/apache/www/androidj">
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
5、测试
[Linux87]#cd /var/www/linuxidc/
[Linux87]#vi index.php
<?php
phpinfo();
?>
#保存退出;
在浏览器输入虚拟主机中的主机名;
如上显示;就说明Apache和PHP已成功整合在一起了;在为PHP安装xcache加速器以提高性能
[Linux87]#ls
php-5.4.26 php-5.4.26.tar.bz2 xcache-3.1.0.tar.bz2
[Linux87]#tar xf xcache-3.1.0.tar.bz2
[Linux87]#cd xcache-3.1.0
[Linux87]#/usr/local/php/bin/phpize
Configuring for:
PHP Api Version: 20100412
Zend Module Api No: 20100525
Zend Extension Api No: 220100525
[Linux87]#
[Linux87]#./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
[Linux87]#make && make install
#要复制/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/这行内容
如之前没有/etc/php.d目录需先创建
[Linux87]#cp xcache.ini /etc/php.d/
[xcache-common]
;; non-Windows example:
extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/xcache.so 把前面路径加上
重启下php-fpmzaic
在此访问之前的测试页面
可以看到红色区域内已出现xcache和版本信息了。