0%

CentOS 7 安装PHP 7.1

CentOS 7 安装PHP7.1

安装依赖

1
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

动态库

1
cp -frp /usr/lib64/libldap* /usr/lib/

下载安装包

https://www.php.net/downloads.php

编译安装

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
./configure \
--prefix=/data/servers/php71 \
--with-config-file-path=/data/servers/php71/etc \
--enable-fpm \
--enable-mysqlnd \
--enable-mbstring \
--with-gd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-iconv-dir \
--with-freetype-dir=/usr \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--with-ldap=shared \
--with-gdbm \
--with-pear \
--with-gettext \
--with-curl \
--with-xmlrpc \
--with-openssl \
--with-mhash \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--enable-mbregex \
--enable-intl \
--enable-ftp \
--enable-intl \
--enable-pcntl \
--enable-sockets \
--enable-zip \
--enable-soap \
--enable-opcache \
--enable-cli \
--disable-fileinfo \
--disable-rpath

安装

1
make && make install
1
2
3
4
5
6
Warning! a PEAR user config file already exists from a previous PEAR installation at '/root/.pearrc'. You may probably want to remove it.
Wrote PEAR system config file at: /data/servers/php71/etc/pear.conf
You may want to add: /data/servers/php71/lib/php to your php.ini include_path
/data/servers/php-7.1.33/build/shtool install -c ext/phar/phar.phar /data/servers/php71/bin
ln -s -f phar.phar /data/servers/php71/bin/phar
Installing PDO headers: /data/servers/php71/include/php/ext/pdo/

初始化配置

1
2
3
4
cp /data/servers/php-7.1.33/sapi/fpm/init.d.php-fpm.in /etc/init.d/php-fpm
cp /data/servers/php-7.1.33/php.ini-production /data/servers/php71/php.ini
cp /data/servers/php71/etc/php-fpm.conf.default /data/servers/php71/etc/php-fpm.conf
cp /data/servers/php71/etc/php-fpm.d/www.conf.default /data/servers/php71/etc/php-fpm.d/www.conf

修改启动文件

1
2
3
4
5
6
7
8
9
10
vim /etc/init.d/php-fpm

# 修改一下内容

prefix=/data/servers/php71
exec_prefix=/data/servers/php71

php_fpm_BIN=/data/servers/php71/sbin/php-fpm
php_fpm_CONF=/data/servers/php71/etc/php-fpm.conf
php_fpm_PID=/data/servers/php71/var/run/php-fpm.pid

Nginx配置

新增配置

1
2
3
4
5
6
fastcgi_pass   127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

vim /usr/share/nginx/html/test.php

1
2
3
<?php
phpinfo();
?>

验证

访问ip地址:12345/test.php