编译安装PHP-7.1.8

安装依赖包:

1、安装yasm

cd /usr/local/src

tar zxvf yasm-1.3.0.tar.gz

cd yasm-1.3.0

./configure

make

make install

2、安装libmcrypt

cd /usr/local/src

tar zxvf libmcrypt-2.5.8.tar.gz

cd libmcrypt-2.5.8

./configure

make

make install

3、安装libvpx

cd /usr/local/src

tar zxvf libvpx-1.3.0.tar.gz

cd libvpx-1.3.0

./configure --prefix=/usr/local/libvpx --enable-shared --enable-vp9

make

make install

4、安装tiff

cd /usr/local/src

tar zxvf tiff-4.0.7.tar.gz

cd tiff-4.0.7

./configure --prefix=/usr/local/tiff --enable-shared

make

make install

5、安装libpng

cd /usr/local/src

tar zxvf libpng-1.6.28.tar.gz

cd libpng-1.6.28

./configure --prefix=/usr/local/libpng --enable-shared

make

make install

6、安装freetype

cd /usr/local/src

tar zxvf freetype-2.7.1.tar.gz

cd freetype-2.7.1

./configure --prefix=/usr/local/freetype --enable-shared

make

make install

7、安装jpeg

cd /usr/local/src

tar zxvf jpegsrc.v9b.tar.gz

cd jpeg-9b

./configure --prefix=/usr/local/jpeg --enable-shared

make

make install

8、安装libgd

cd /usr/local/src

tar zxvf libgd-2.1.1.tar.gz

cd libgd-2.1.1

./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/lib64 
--with-tiff=/usr/local/tiff 

make

make install

说明:如果libgd编译失败,可以先跳过,直接使用系统默认的2.1.0版本,在编译php的时候把参数--with-gd=/usr/local/libgd修改为--with-gd即可。

9、安装t1lib

cd /usr/local/src

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

安装PHP

cp -frp /usr/lib64/libltdl.so* /usr/lib/
cp -frp /usr/lib64/libXpm.so* /usr/lib/

export LD_LIBRARY_PATH=/usr/local/libgd/lib

./configure 
--prefix=/usr/local/php71 
--with-config-file-path=/usr/local/php71/etc 
--with-mysqli=mysqlnd 
--with-mysql-sock=/tmp/mysql.sock 
--with-pdo-mysql=mysqlnd 
--with-gd=/usr/local/libgd 
--with-png-dir=/usr/local/libpng 
--with-jpeg-dir=/usr/local/jpeg 
--with-freetype-dir=/usr/local/freetype 
--with-xpm-dir=/usr/lib64 
--with-zlib-dir=/usr/local/zlib 
--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 
--enable-mysqlnd 

make && make install

启动服务
vi /usr/lib/systemd/system/php-fpm.service

[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target

[Service]
Type=simple
PIDFile=/run/php-fpm.pid
ExecStart=/usr/local/php71/sbin/php-fpm --nodaemonize --fpm-config /etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID

[Install]
WantedBy=multi-user.target

配置

cp php.ini-production /usr/local/php71/etc/php.ini #复制php配置文件到安装目录
mv /etc/php.ini /etc/php.ini.old #删除系统自带配置文件
ln -s /usr/local/php71/etc/php.ini /etc/php.ini #添加软链接到 /etc目录

cp /usr/local/php71/etc/php-fpm.conf.default /usr/local/php71/etc/php-fpm.conf #拷贝模板文件为php-fpm配置文件
ln -s /usr/local/php71/etc/php-fpm.conf /etc/php-fpm.conf #添加软连接到 /etc目录

vi /usr/local/php71/etc/php-fpm.conf

pid = run/php-fpm.pid #取消前面的分号
include=/usr/local/php71/etc/php-fpm.d/*.conf

cp /usr/local/php71/etc/php-fpm.d/www.conf.default /usr/local/php71/etc/php-fpm.d/www.conf

vi /usr/local/php71/etc/php-fpm.d/www.conf #编辑

user = www #设置php-fpm运行账号为www,此账号是nginx等web服务的账号
group = www #设置php-fpm运行组为www
listen = 127.0.0.1:9000

vi /usr/local/php71/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

修改为:date.timezone = PRC #设置时区 Asia/Shanghai
修改为:expose_php = Off #禁止显示php版本的信息
修改为:short_open_tag = ON #支持php短标签
修改为opcache.enable=1 #php支持opcode缓存
修改为:opcache.enable_cli=0
在最后一行添加:zend_extension=opcache.so #开启opcode缓存功能

配置nginx支持php

测试篇

原文地址:https://www.cnblogs.com/xkus/p/7749703.html