环境:centos 6.4 X64 最小化安装
php版本:
PHP 5.5.3 (cli) (built: Sep 3 2013 14:05:33)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
yum 安装
rpm -Uvh http://mirror.bjtu.edu.cn/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
yum --enablerepo=remi install php php-*
yum --enablerepo=remi install mysql*
http://mirror.bjtu.edu.cn/fedora-epel/6/x86_64/
http://rpms.famillecollet.com/enterprise/
编译安装
安装前.先安装些软件和库文件
yum install -y gcc gcc-c++ make zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
下载PHP 源码包
cd /app/download
wget http://219.239.26.20/download/50550151/73687443/3/gz/48/187/1377323886384_955/php-5.5.3.tar.gz
tar zxf php-5.5.3.tar.gz
编译安装PHP
cd /app/download/php-5.5.3
./configure --prefix=/apps/php --enable-fpm --with-mcrypt=/usr/libmcrypt --with-zlib --enable-mbstring --with-openssl --with-mysql --with-mysqli --with-mysql-sock --with-gd --with-jpeg-dir=/usr/lib --enable-gd-native-ttf --enable-pdo --with-pdo-mysql --with-gettext --with-curl --with-pdo-mysql --enable-sockets --enable-bcmath --enable-xml --with-bz2 --enable-zip --with-freetype-dir=/usr/include/freetype2/freetype
运行之后遇到的问题:
error 1
checking for xml2-config path...
configure: error: xml2-config not found. Please check your libxml2 installation.
(看提示就明白 是一个lib库没装 先用 yum search 名字 看是否能搜到名字 ,找到名字后 把软件包 开发包装上)
解决办法
yum install libxml2-devel.x86_64
error 2
checking for pkg-config... /usr/bin/pkg-config
configure: error: Cannot find OpenSSL's <evp.h>
这是ssl没装
解决办法
yum install openssl.x86_64 openssl-devel.x86_64 -y
error 3
checking for BZip2 in default path... not found
configure: error: Please reinstall the BZip2 distribution
这是bzip2软件包没有安装
解决办法
yum install bzip2-devel.x86_64 -y
error 4
configure: error: Please reinstall the libcurl distribution -
easy.h should be in <curl-dir>/include/curl/
curl和curl库文件没有安装
解决办法
yum install libcurl.x86_64 libcurl-devel.x86_64 -y
error 5
checking whether to enable JIS-mapped Japanese font support in GD... no
checking for fabsf... yes
checking for floorf... yes
configure: error: jpeglib.h not found
GD库没有安装
解决办法
yum install libjpeg.x86_64 libpng.x86_64 freetype.x86_64 libjpeg-devel.x86_64 libpng-devel.x86_64 freetype-devel.x86_64 -y
error 6
checking for stdarg.h... (cached) yes
checking for mcrypt support... yes
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
libmcrypt库没有安装 ,要是不能用yun安装的话 使用下面方法
rpm -ivh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
yum clean all
yum install libmcrypt libmcrypt-devel mcrypt mhash
(编译安装 ./configure --piefix=/usr/local/libmcrypt make && make install)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
要是错误里面含有mysql的 那是mysql-devel 没有安装
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
出现
Generating files configure: creating ./config.status creating main/internal_functions.c creating main/internal_functions_cli.c
+--------------------------------------------------------------------+
| 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.
config.status: creating php5.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/fpm/php-fpm.conf
config.status: creating sapi/fpm/init.d.php-fpm
config.status: creating sapi/fpm/php-fpm.8
config.status: creating sapi/fpm/status.html
config.status: creating main/php_config.h
config.status: executing default commands
表示编译成功
安装PHP
make && make install
到php的解压目录 找出php.ini-production 复制到 /app/php/lib/ 下 文件名改成php.ini
cp /root/php-5.5.3/php.ini-production /app/php/bin/php.ini
[创建并修改php-fpm的配置文件]
cp /app/php/etc/php-fpm.conf.default /app/php/etc/php-fpm.conf
修改内容:
1 |
pid = run/php-fpm.pid |
2 |
error_log = log/php-fpm.log |
3 |
log_level = error |
4 |
emergency_restart_interval = 3d |
5 |
user = www |
6 |
group = www |
7 |
listen = 127.0.0.1:9000 |
[创建并添加php-fpm开机启动服务脚本]
vim /etc/init.d/php-fpm
#!/bin/sh
#chkconfig: - 85 15
#description: php-fpm is PHP FastCGI Process Manage.
#processname:php-fpm
### BEGIN INIT INFO
# Provides: php-fpm
# Required-Start: $remote_fs $network
# Required-Stop: $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts php-fpm
# Description: starts the PHP FastCGI Process Manager daemon
### END INIT INFO
prefix=/app/php
exec_prefix=${prefix}
php_fpm_BIN=${exec_prefix}/sbin/php-fpm
php_fpm_CONF=${prefix}/etc/php-fpm.conf
php_fpm_PID=${prefix}/var/log/php-fpm.pid
php_opts="--fpm-config $php_fpm_CONF"
wait_for_pid () {
try=0
while test $try -lt 35 ; do
case "$1" in
'created')
if [ -f "$2" ] ; then
try=''
break
fi
;;
'removed')
if [ ! -f "$2" ] ; then
try=''
break
fi
;;
esac
echo -n .
try=`expr $try + 1`
sleep 1
done
}
case "$1" in
start)
echo -n "Starting php-fpm "
$php_fpm_BIN $php_opts
if [ "$?" != 0 ] ; then
echo " failed"
exit 1
fi
wait_for_pid created $php_fpm_PID
if [ -n "$try" ] ; then
echo " failed"
exit 1
else
echo " done"
fi
;;
stop)
echo -n "Gracefully shutting down php-fpm "
if [ ! -r $php_fpm_PID ] ; then
exit 1
fi
kill -QUIT `cat $php_fpm_PID`
wait_for_pid removed $php_fpm_PID
if [ -n "$try" ] ; then
echo " failed. Use force-quit"
exit 1
else
echo " done"
fi
;;
force-quit)
echo -n "Terminating php-fpm "
if [ ! -r $php_fpm_PID ] ; then
echo "warning, no pid file found - php-fpm is not running ?"
exit 1
fi
kill -TERM `cat $php_fpm_PID`
wait_for_pid removed $php_fpm_PID
if [ -n "$try" ] ; then
echo " failed"
exit 1
else
echo " done"
fi
;;
restart)
$0 stop
$0 start
;;
reload)
echo -n "Reload service php-fpm "
if [ ! -r $php_fpm_PID ] ; then
echo "warning, no pid file found - php-fpm is not running ?"
exit 1
fi
kill -USR2 `cat $php_fpm_PID`
echo " done"
;;
*)
echo "Usage: $0 {start|stop|force-quit|restart|reload}"
exit 1
;;
esac
# chmod 755 /etc/init.d/php-fpm
# chkconfig --add php-fpm 添加 PHP 为系统服务,并设置为开机自动启动
# chkconfig php-fpm on
# chown -R www:www /usr/local/php 给PHP相关文件目录设置权限
[手动启动 PHP 命令]
# service php-fpm start
完成..