源码安装php(支持jpeg,freetype,png,mcrypt)

1,安装系统需要的库文件
yum install *libxml* bzip* libcurl* -y
2,进入php安装包目录,按顺序安装模块及php
cd /opt/php
tar xf jpegsrc.v9.tar.gz
cd jpeg-9
./configure --prefix=/usr/local/jepg
make && make install

cd /opt/php
tar xf freetype-2.4.12.tar.gz 
cd freetype-2.4.12
./configure --prefix=/usr/local/freetype
make && make install

cd /opt/php
tar xf libpng-1.6.2.tar.gz
cd libpng-1.6.2
./configure --prefix=/usr/local/libpng
make && make install

cd /opt/php
tar xf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8 
./configure
make && make install

cd /opt/php
tar xf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure --prefix=/usr/local/mhash
make && make install

cd /opt/php
tar xf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure 
make && make install

cd /opt/php
tar xf mcrypt-2.6.8.tar.gz 
cd mcrypt-2.6.8
LD_LIBRARY_PATH=/usr/local/lib ./configure
make && make install

cd /opt/php
tar xf php-5.5.29.tar.gz 
cd php-5.5.29
./configure --prefix=/usr/local/php-5.5.29 --with-mysql=/usr/local/mysql --enable-bcmath --enable-ftp --with-gettext --with-curl --with-openssl --enable-pcntl --enable-soap --enable-shmop --enable-sysvsem --with-xmlrpc --enable-zip --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mhash=/usr/local/mhash --enable-mbstring --with-mcrypt=/usr/local/include --with-freetype-dir=/usr/local/freetype --enable-mysqlnd --with-jpeg-dir=/usr/local/jepg --with-png-dir=/usr/local/libpng --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts --enable-fpm
make && make install
3,配置文件优化
cp php.ini-production /etc/php.ini
mkdir -p /etc/php.d

sed -i 's/expose_php = On/expose_php = Off/g' /etc/php.ini
sed -i 's/;date.timezone =/date.timezone = PRC/g' /etc/php.ini

cd /usr/local
ln -s php-5.5.29 php


#编写php-fpm启动文件
cat << EOF > /usr/local/php/etc/php-fpm.conf
[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
log_level = notice

[www]
#listen = /tmp/php-cgi.sock
listen = /dev/shm/php-cgi.sock
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
#emergency_restart_threshold = 60
#emergency_restart_interval = 60s
pm = dynamic
pm.max_children = 100
pm.start_servers = 2
pm.min_spare_servers = 2
pm.max_spare_servers = 16
pm.max_requests = 1000
pm.status_path = /php-fpm_status
request_terminate_timeout = 0
request_slowlog_timeout = 0
slowlog = var/log/slow.log
#rlimit_files = 65535
EOF
4,编辑启动脚本
vi /etc/init.d/php-fpm
#!/bin/sh 
# DateTime: 2015-03-20
# Author: midas
# mail : 416557132@qq.com
# chkconfig: 2345 10 90 
# description: myservice "php-fpm"
# Source function library. 
. /etc/rc.d/init.d/functions 

# Source networking configuration. 
. /etc/sysconfig/network 

# Check that networking is up. 
[ "$NETWORKING" = "no" ] && exit 0

BINFILE="/usr/local/php/sbin/php-fpm"
CFGFILE="/usr/local/php/etc/php-fpm.conf"
PIDFILE="/usr/local/php/var/run/php-fpm.pid"
prog=$(basename $BINFILE) 
LOCKFILE="/usr/local/php/var/php-fpm.lock"


start() {
[[ -x $BINFILE ]] || exit 5
[[ -f $CFGFILE ]] || exit 6

if [[ `ps aux | grep php-fpm: | grep -v grep | wc -l` -gt 0 ]]; then
echo "The php-fpm is already running."
return 1
fi

$BINFILE -t >/dev/null 2>&1

if [[ $? -ne 0 ]]; then
echo "The php-fpm configure has error."
return 1
fi

echo -n $"Starting $prog: " 
daemon ${BINFILE} -c /etc/php.ini -y $CFGFILE
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch $LOCKFILE
return $RETVAL
}

stop() {
if [[ `ps aux | grep php-fpm: | grep -v grep | wc -l` -eq 0 ]]; then
echo "The php-fpm is not running."
return 1
fi

echo -n $"Stopping $prog: " 
killproc $prog -QUIT 
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f $LOCKFILE $PIDFILE
return $RETVAL
}

restart() {
stop
sleep 1

while true
do
if [[ `ps aux | grep php-fpm: | grep -v grep | wc -l` -eq 0 ]]; then
start
break
fi
sleep 1
done

RETVAL=$?
echo

return $RETVAL
}

reload() {
if [[ `ps aux | grep php-fpm: | grep -v grep | wc -l` -eq 0 ]]; then
echo "The php-fpm is not running."
return 1
fi

echo -n $"Reloading $prog: "
killproc $BINFILE -USR2 
RETVAL=$?
echo

return $RETVAL
}

force_reload() { 
restart 
} 

configtest() { 
${BINFILE} -t
} 

rh_status() { 
status $prog 
} 

rh_status_q() { 
rh_status >/dev/null 2>&1 
} 

case "$1" in 
start) 
rh_status_q && exit 0 
$1 
;; 
stop) 
rh_status_q || exit 0 
$1 
;; 
restart|configtest) 
$1 
;; 
reload) 
rh_status_q || exit 7 
$1 
;; 
status) 
rh_status 
;; 
*) 
echo $"Usage: $0 {start|stop|status|restart|reload|configtest}" 
exit 2 
esac
5,加入开机启动,并启动
chkconfig add php-fpm
chkconfig on php-fpm
service php-fpm start答复
此条目发表在php分类目录。将固定链接加入收藏夹。

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注