1、解决依赖关系安装依赖包:1
2
3
| # yum -y groupinstall"Desktop Platform Development"
# yum install gcc make gd-devellibjpeg-devel libjpeg-turbo-devel libpng-devel libxml2-devel bzip2-devellibcurl-devel libiconv-devel libevent libevent-devel zlib-devel -y
# yuminstall freetype-devel libxslt libxslt-devel -y
|
如果想让编译的php支持mcrypt扩展,此处还需要单独安装此依赖包,epel6源自带可以直接安装:
1
| # yum-y install libmcrypt libmcrypt-devel mhash mhash-devel mcrypt
|
注:如果你使用的epel7的源,可能会没有 mcrypt mhash mhash-devel 几个包,可以在 http://mirrors.aliyun.com/epel/6/x86_64/中下载,使用 yum localinstall xxx.rpm 或 rpm -Uvh xxx.rpm 手动安装即可。
编译安装libiconv库
2、编译安装php-5.5.34首先下载源码包至本地目录,
然后执行以下编译参数:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
| ./configure \
--prefix=/usr/local/php \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--with-bz2 \
--with-curl \
--enable-ftp \
--enable-sockets \
--disable-ipv6 \
--with-gd \
--enable-gd-native-ttf \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-iconv-dir=/usr/local/libiconv \
--enable-mbstring \
--with-mcrypt \
--with-mhash \
--with-openssl \
--enable-bcmath \
--enable-calendar \
--with-gettext \
--enable-soap \
--with-libxml-dir=/usr \
--with-zlib \
--with-pdo-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-mysql=mysqlnd \
--enable-dom \
--enable-xml \
--enable-fpm \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--with-libdir=lib64
|
1
2
3
| # make
# make test
#make intall
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
| 参数说明:
""" 安装路径 """
--prefix=/usr/local/php \
""" php.ini 配置文件路径 """
--with-config-file-path= /etc \
""" 优化选项 """
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
""" 启用 opcache,默认为 ZendOptimizer+(ZendOpcache)"""
--enable-opcache \
""" FPM """
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
""" MySQL """
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
""" 国际化与字符编码支持 """
--with-gettext \
--enable-mbstring \
--with-iconv \
""" 图片格式的支持 """
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
""" 加密扩展 """
--with-mcrypt \
--with-mhash \
--with-openssl \
""" 数学扩展 """
--enable-bcmath \
""" Web 服务,soap 依赖 libxml """
--enable-soap \
--with-libxml-dir \
""" 进程,信号及内存 """
--enable-pcntl \
--enable-shmop \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
""" socket & curl"""
--enable-sockets \
--with-curl \
""" 压缩与归档 """
--with-zlib \
--enable-zip \
--with-bz2 \
Zabbix安装需要的PHP扩展参数
--enable-bcmath
--enable-mbstring
--enable-sockets
--with-gd
--with-libxml-dir=/usr/local
xmlwriter 同上
xmlreader 同上
ctype 默认支持
session 默认支持
gettext 默认支持
|
3、为php提供配置文件:1
| [iyunv@web php-5.5.34]# cp php.ini-production/etc/php.ini
|
说明:
php.ini-development //开发环境用
php.ini-production //生产环境用
4、配置PHP-FPM4.1 简介:PHP-FPM(FastCGIProcess Manager:FastCGI进程管理器)
PHP-FPM是一个PHPFastCGI管理器,是只用于PHP的。它提供了更好的PHP进程管理方式,可以有效控制内存和进程、可以平滑重载PHP配置,比spawn-fcgi具有更多优点,所以被PHP官方收录了。在./configure的时候带–enable-fpm参数即可开启PHP-FPM。
使用PHP-FPM来控制PHP-CGI的FastCGI进程 /usr/local/php/sbin/php-fpm{start|stop|quit|restart|reload|logrotate} --start 启动php的fastcgi进程 --stop 强制终止php的fastcgi进程 --quit 平滑终止php的fastcgi进程 --restart 重启php的fastcgi进程 --reload 重新平滑加载php的php.ini --logrotate 重新启用log文件
4.2 配置php-fpm:
4.2.1为php-fpm提供SysV init脚本,并将其添加至开机启动服务列表:
1
2
3
4
5
| [iyunv@ nginx tools]# cd php-5.5.34
[iyunv@nginx php-5.5.34]# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
[iyunv@nginx php-5.5.34]# chmod +x/etc/rc.d/init.d/php-fpm
[iyunv@nginx php-5.5.34]# chkconfig --addphp-fpm
[root@nginxphp-5.5.34]# chkconfig php-fpm on
|
4.2.2为php-fpm提供配置文件:
4.2.3编辑php-fpm的配置文件:
1
2
3
4
5
6
7
| # vim /usr/local/php/etc/php-fpm.conf
配置fpm的相关选项为你所需要的值,默认会启用pid文件:
pm.max_children = 150
pm.start_servers = 8
pm.min_spare_servers = 5
pm.max_spare_servers= 10
|
5、启动php-fpm:1
2
| # service php-fpm start
说明:php-fpm 可用参数start|stop|force-quit|restart|reload|status
|
6、为了方便使用,可以将 PHP 命令添加到环境变量1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| [iyunv@nginx php-5.5.34]# vim~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startupprograms
#将PATH=$PATH:$HOME/bin 改为:PATH=$PATH:$HOME/bin:/usr/local/php/bin
PATH=$PATH:$HOME/bin:/usr/local/php/bin
export PATH
保存退出!
|
1
2
3
4
5
6
7
| 查看看 PHP 版本
[iyunv@nginx php-5.5.34]# php -v
PHP 5.5.34 (cli) (built: Apr 7 2016 11:22:13)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015Zend Technologies
with XCache v3.1.2, Copyright (c) 2005-2014, by mOo
with XCache Cacher v3.1.2, Copyright (c)2005-2014, by mOo
|
7、检验:使用如下命令来验正(如果此命令输出有中几个php-fpm进程就说明启动成功了):
1
2
3
4
5
6
7
8
| # psaux | grep php-fpm
root 54722 0.0 0.3 175728 5932 ? Ss 20:19 0:00 php-fpm: master process(/usr/local/php/etc/php-fpm.conf)
www 54723 0.0 0.2 175728 5144 ? S 20:19 0:00 php-fpm: pool www
www 54724 0.0 0.2 175728 5144 ? S 20:19 0:00 php-fpm: pool www
www 54725 0.0 0.2 175728 5144 ? S 20:19 0:00 php-fpm: pool www
www 54726 0.0 0.2 175728 5144 ? S 20:19 0:00 php-fpm: pool www
www 54727 0.0 0.2 175728 5144 ? S 20:19 0:00 php-fpm: pool www
root 54837 0.0 0.0 103308 852 pts/1 S+ 20:22 0:00 grep php-fpm
|
默认情况下,fpm监听在127.0.0.1的9000端口,也可以使用如下命令验正其是否已经监听在相应的套接字。
1
2
| # netstat -tnlp |grep php-fpm
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 54722/php-fpm
|
8、整合nginx和php58.1.编辑/etc/nginx/nginx.conf,启用如下选项:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| # 在所支持的主页面格式中添加php格式的主页
location / {
root html;
index index.php index.htmlindex.htm;
}
# 1. 启用fastcgi,去掉前面的“#”号,
# 2. 注意fastcgi下的root要与server下的其它location的root目录一致,
# 3. 将fastcgi_param 的/scripts改为$document_root
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
|
8.2.重新载入nginx的配置文件:
9、测试:php程序与mysql安装情况:
1
2
3
4
5
6
7
8
9
10
11
12
| [iyunv@nginx ~]# cd /usr/local/nginx/html/
[iyunv@nginx html]# vim index.php
<?php
$link = mysql_connect('127.0.0.1','root','test123');
if($link)
echo "Success";
else
echo "failure";
mysql_close();
phpinfo();
?>
|
然后浏览器输入ip地址:
nginx ,mysql,php安装成功!
|