一、下载相关安装包
下载php
http://cn2.php.net/distributions/php-5.6.5.tar.gz
下载libmcrypt(php扩展)
http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
下载yasm(php扩展)
http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
下载t1lib(php扩展)
ftp://sunsite.unc.edu/pub/Linux/libs/graphics/t1lib-5.1.2.tar.gz
下载gd库安装包
https://bitbucket.org/libgd/gd-libgd/downloads/libgd-2.1.0.tar.gz
下载libvpx(gd库需要)
http://anduin.linuxfromscratch.org/sources/other/libvpx-v1.3.0.tar.xz
或
https://webm.googlecode.com/files/libvpx-v1.3.0.tar.bz2
下载tiff(gd库需要)
http://download.osgeo.org/libtiff/tiff-4.0.3.tar.gz
下载libpng(gd库需要)
http://downloads.sourceforge.net/libpng/libpng-1.6.16.tar.xz
下载freetype(gd库需要)
http://ring.u-toyama.ac.jp/archives/graphics/freetype/freetype2/freetype-2.5.4.tar.gz
下载jpegsrc(gd库需要)
http://www.ijg.org/files/jpegsrc.v9a.tar.gz
二、安装编译工具及库文件(使用yum命令安装)
Shell
yum install -y zlib-devel fontconfig fontconfig-devel libXpm* libtool* libxml2 libxml2-devel curl curl-devel
1
yuminstall-yzlib-develfontconfigfontconfig-devellibXpm*libtool*libxml2libxml2-develcurlcurl-devel
建议安装个全的
Shell
yum install -y apr* autoconf automake bison bzip2 bzip2* cloog-ppl compat* cpp
yum install -y curl curl-devel fontconfig fontconfig-devel freetype freetype*
yum install -y freetype-devel gcc gcc-c++ gtk+-devel gd gettext gettext-devel
yum install -y glibc kernel kernel-headers keyutils keyutils-libs-devel krb5-devel
yum install -y libcom_err-devel libpng libpng* libpng-devel libjpeg* libsepol-devel
yum install -y libselinux-devel libstdc++-devel libtool* libgomp libxml2 libxml2-devel libXpm* libX*
yum install -y libtiff libtiff* make mpfr ncurses* ntp openssl nasm nasm*
yum install -y openssl-devel patch pcre-devel perl php-common php-gd
yum install -y policycoreutils ppl telnet t1lib t1lib* wget zlib-devel
1
2
3
4
5
6
7
8
9
yuminstall-yapr*autoconfautomakebisonbzip2bzip2*cloog-pplcompat*cpp
yuminstall-ycurlcurl-develfontconfigfontconfig-develfreetypefreetype*
yuminstall-yfreetype-develgccgcc-c++gtk+-develgdgettextgettext-devel
yuminstall-yglibckernelkernel-headerskeyutilskeyutils-libs-develkrb5-devel
yuminstall-ylibcom_err-devellibpnglibpng*libpng-devellibjpeg*libsepol-devel
yuminstall-ylibselinux-devellibstdc++-devellibtool*libgomplibxml2libxml2-devellibXpm*libX*
yuminstall-ylibtifflibtiff*makempfrncurses*ntpopensslnasmnasm*
yuminstall-yopenssl-develpatchpcre-develperlphp-commonphp-gd
yuminstall-ypolicycoreutilsppltelnett1libt1lib*wgetzlib-devel
三、开始安装
1、安装yasm
Shell
cd /home
tar zxvf yasm-1.3.0.tar.gz
cd yasm-1.3.0
./configure
make && make install
1
2
3
4
5
6
7
8
9
cd/home
tarzxvfyasm-1.3.0.tar.gz
cdyasm-1.3.0
./configure
make&&makeinstall
2、安装libmcrypt
Shell
cd /home
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make && make install
1
2
3
4
5
6
7
8
9
cd/home
tarzxvflibmcrypt-2.5.8.tar.gz
cdlibmcrypt-2.5.8
./configure
make&&makeinstall
3、安装libvpx
Shell
cd /home
xz -d libvpx-v1.3.0.tar.xz
tar -xvf libvpx-v1.3.0.tar
cd libvpx-v1.3.0
./configure --prefix=/usr/local/libvpx --enable-shared --enable-vp9
make && make install
1
2
3
4
5
6
7
8
9
10
cd/home
xz-dlibvpx-v1.3.0.tar.xz
tar-xvflibvpx-v1.3.0.tar
cdlibvpx-v1.3.0
./configure--prefix=/usr/local/libvpx--enable-shared--enable-vp9
make&&makeinstall
4、安装tiff
Shell
cd /home
tar zxvf tiff-4.0.3.tar.gz
cd tiff-4.0.3
./configure --prefix=/usr/local/tiff --enable-shared
make && make install
1
2
3
4
5
6
7
8
9
cd/home
tarzxvftiff-4.0.3.tar.gz
cdtiff-4.0.3
./configure--prefix=/usr/local/tiff--enable-shared
make&&makeinstall
5、安装libpng
Shell
cd /home
xz -d libpng-1.6.16.tar.xz
tar -xvf libpng-1.6.16.tar
cd libpng-1.6.16
./configure --prefix=/usr/local/libpng --enable-shared
make && make install
1
2
3
4
5
6
7
8
9
10
11
cd/home
xz-dlibpng-1.6.16.tar.xz
tar-xvflibpng-1.6.16.tar
cdlibpng-1.6.16
./configure--prefix=/usr/local/libpng--enable-shared
make&&makeinstall
6、安装freetype
Shell
cd /home
tar zxvf freetype-2.5.4.tar.gz
cd freetype-2.5.4
./configure --prefix=/usr/local/freetype --enable-shared --without-png
make && make install
1
2
3
4
5
6
7
8
9
cd/home
tarzxvffreetype-2.5.4.tar.gz
cdfreetype-2.5.4
./configure--prefix=/usr/local/freetype--enable-shared--without-png
make&&makeinstall
7、安装jpeg
Shell
cd /home
tar zxvf jpegsrc.v9a.tar.gz
cd jpeg-9a
./configure --prefix=/usr/local/jpeg --enable-shared
make && make install
1
2
3
4
5
6
7
8
9
cd/home
tarzxvfjpegsrc.v9a.tar.gz
cdjpeg-9a
./configure--prefix=/usr/local/jpeg--enable-shared
make&&makeinstall
8、安装libgd
Shell
cd /home
tar zxvf libgd-2.1.0.tar.gz
cd libgd-2.1.0
./configure \
--prefix=/usr/local/libgd \
--enable-shared \
--with-jpeg=/usr/local/jpeg \
--with-png=/usr/local/libpng \
--with-freetype=/usr/local/freetype \
--with-fontconfig=/usr/local/freetype \
--with-xpm=/usr/ \
--with-tiff=/usr/local/tiff \
--with-vpx=/usr/local/libvpx
make && make install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
cd/home
tarzxvflibgd-2.1.0.tar.gz
cdlibgd-2.1.0
./configure\
--prefix=/usr/local/libgd\
--enable-shared\
--with-jpeg=/usr/local/jpeg\
--with-png=/usr/local/libpng\
--with-freetype=/usr/local/freetype\
--with-fontconfig=/usr/local/freetype\
--with-xpm=/usr/\
--with-tiff=/usr/local/tiff\
--with-vpx=/usr/local/libvpx
make&&makeinstall
9、安装t1lib
Shell
cd /home
tar zxvf t1lib-5.1.2.tar.gz
cd t1lib-5.1.2
./configure --prefix=/usr/local/t1lib --enable-shared
make without_doc
make install
1
2
3
4
5
6
7
8
9
10
11
cd/home
tarzxvft1lib-5.1.2.tar.gz
cdt1lib-5.1.2
./configure--prefix=/usr/local/t1lib--enable-shared
makewithout_doc
makeinstall
10、安装php
注意:如果系统是64位,请执行以下两条命令,否则安装php会出错(32位系统不需要执行)
Shell
\cp -frp /usr/lib64/libltdl.so* /usr/lib/
\cp -frp /usr/lib64/libXpm.so* /usr/lib/
cd /home
tar -zvxf php-5.6.5.tar.gz
cd php-5.6.5
export LD_LIBRARY_PATH=/usr/local/libgd/lib
1
2
3
4
5
6
7
8
9
10
11
\cp-frp/usr/lib64/libltdl.so*/usr/lib/
\cp-frp/usr/lib64/libXpm.so*/usr/lib/
cd/home
tar-zvxfphp-5.6.5.tar.gz
cdphp-5.6.5
exportLD_LIBRARY_PATH=/usr/local/libgd/lib
# 核对每一项安装的路径配置 本人这里的–with-mysql-sock=/tmp/mysqld.sock 有的为 –with-mysql-sock=/tmp/mysql.sock
Shell
./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-mysql-sock=/tmp/mysqld.sock \
--with-pdo-mysql=/usr/local/mysql \
--with-gd --with-png-dir=/usr/local/libpng \
--with-jpeg-dir=/usr/local/jpeg \
--with-freetype-dir=/usr/local/freetype \
--with-xpm-dir=/usr/ \
--with-vpx-dir=/usr/local/libvpx/ \
--with-zlib-dir=/usr/local/zlib \
--with-t1lib=/usr/local/t1lib \
--with-iconv \
--enable-libxml \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--enable-opcache \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--enable-ftp \
--enable-gd-native-ttf \
--with-openssl \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--without-pear \
--with-gettext \
--enable-session \
--with-mcrypt \
--with-curl \
--enable-ctype
make && make install
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
./configure\
--prefix=/usr/local/php\
--with-config-file-path=/usr/local/php/etc\
--with-mysql=/usr/local/mysql\
--with-mysqli=/usr/local/mysql/bin/mysql_config\
--with-mysql-sock=/tmp/mysqld.sock\
--with-pdo-mysql=/usr/local/mysql\
--with-gd--with-png-dir=/usr/local/libpng\
--with-jpeg-dir=/usr/local/jpeg\
--with-freetype-dir=/usr/local/freetype\
--with-xpm-dir=/usr/\
--with-vpx-dir=/usr/local/libvpx/\
--with-zlib-dir=/usr/local/zlib\
--with-t1lib=/usr/local/t1lib\
--with-iconv\
--enable-libxml\
--enable-xml\
--enable-bcmath\
--enable-shmop\
--enable-sysvsem\
--enable-inline-optimization\
--enable-opcache\
--enable-mbregex\
--enable-fpm\
--enable-mbstring\
--enable-ftp\
--enable-gd-native-ttf\
--with-openssl\
--enable-pcntl\
--enable-sockets\
--with-xmlrpc\
--enable-zip\
--enable-soap\
--without-pear\
--with-gettext\
--enable-session\
--with-mcrypt\
--with-curl\
--enable-ctype
make&&makeinstall
Shell
cp php.ini-production /usr/local/php/etc/php.ini #复制php配置文件到安装目录
rm -rf /etc/php.ini #删除系统自带配置文件
ln -s /usr/local/php/etc/php.ini /etc/php.ini #添加软链接到 /etc目录
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf #拷贝模板文件为php-fpm配置文件
ln -s /usr/local/php/etc/php-fpm.conf /etc/php-fpm.conf #添加软连接到 /etc目录
1
2
3
4
5
6
7
8
9
cpphp.ini-production/usr/local/php/etc/php.ini#复制php配置文件到安装目录
rm-rf/etc/php.ini#删除系统自带配置文件
ln-s/usr/local/php/etc/php.ini/etc/php.ini#添加软链接到 /etc目录
cp/usr/local/php/etc/php-fpm.conf.default/usr/local/php/etc/php-fpm.conf#拷贝模板文件为php-fpm配置文件
ln-s/usr/local/php/etc/php-fpm.conf/etc/php-fpm.conf#添加软连接到 /etc目录
Shell
vi /usr/local/php/etc/php-fpm.conf #编辑
user = www #设置php-fpm运行账号为www
group = www #设置php-fpm运行组为www
pid = run/php-fpm.pid #取消前面的分号
:wq! #保存退出
1
2
3
4
5
6
7
8
9
vi/usr/local/php/etc/php-fpm.conf#编辑
user=www#设置php-fpm运行账号为www
group=www#设置php-fpm运行组为www
pid=run/php-fpm.pid#取消前面的分号
:wq!#保存退出
设置 php-fpm开机启动
Shell
cp /home/php-5.6.5/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm #拷贝php-fpm到启动目录
chmod +x /etc/rc.d/init.d/php-fpm #添加执行权限
chkconfig php-fpm on #设置开机启动
1
2
3
4
5
cp/home/php-5.6.5/sapi/fpm/init.d.php-fpm/etc/rc.d/init.d/php-fpm#拷贝php-fpm到启动目录
chmod+x/etc/rc.d/init.d/php-fpm#添加执行权限
chkconfigphp-fpmon#设置开机启动
vi /usr/local/php/etc/php.ini #编辑配置文件
找到:disable_functions =
修改为:disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname
#列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。
找到:;date.timezone =
修改为:date.timezone = PRC #设置时区
找到:expose_php = On
修改为:expose_php = Off #禁止显示php版本的信息
找到:short_open_tag = Off
修改为:short_open_tag = ON #支持php短标签
注意:short_open_tag 必须打开.开启以后可以使用PHP的段标签:( ?>)。同时,只有开启这个才可以使用 = 以代替 echo 。有一些开源系统里会使用短标签,如果不打开的话会报错。
找到opcache.enable=0
修改为opcache.enable=1 #php支持opcode缓存
找到:;opcache.enable_cli=1 #php支持opcode缓存
修改为:opcache.enable_cli=0
在最后一行添加:zend_extension=opcache.so #开启opcode缓存功能
:wq! #保存退出
11、配置nginx支持php
vi /usr/local/nginx/conf/nginx.conf
修改/usr/local/nginx/conf/nginx.conf 配置文件,需做如下修改
user www www; #首行user去掉注释,修改Nginx运行组为www www;必须与/usr/local/php/etc/php-fpm.conf中的user,group配置相同,否则php运行出错
index index.html index.htm index.php; #添加index.php
Shell
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location~\.php${
roothtml;
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.php;
fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
includefastcgi_params;
}
#取消FastCGI server部分location的注释,注意fastcgi_param行的参数,改为$document_root$fastcgi_script_name,或者使用绝对路径
/etc/init.d/nginx restart #重启nginx
service php-fpm start #启动php-fpm