Centos7 编译安装PHP7

Centos7 编译安装PHP7

编译安装的方式可以让组件等设置更加合理,但需要你对PHP的代码及各种配置非常的熟悉,以下为大致的安装流程,大家可以参考

1、下载编译工具

yum groupinstall 'Development Tools'

2、安装依赖包

yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses curl gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel expat-devel xmlrpc-c xmlrpc-c-devel libicu-devel libmcrypt-devel libmemcached-devel

3、下载包并解压(安装PHP7以上都行)

wget http://php.net/distributions/php-7.1.0.tar.gz
tar -zxvf php-7.1.0.tar.gz
cd php-7.1.0

4、编译安装(./configure --help 查看编译参数)

./configure \
--prefix=/usr/local/php7 \
--with-config-file-path=/etc \
--enable-fpm \
--with-fpm-user=www  \
--with-fpm-group=www \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared  \
--enable-soap \
--with-libxml-dir \
--with-xmlrpc \
--with-openssl \
--with-mcrypt \
--with-mhash \
--with-pcre-regex \
--with-sqlite3 \
--with-zlib \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--with-cdb \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--with-pcre-dir \
--enable-ftp \
--with-gd \
--with-openssl-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir  \
--with-freetype-dir \
--enable-gd-native-ttf \
--enable-gd-jis-conv \
--with-gettext \
--with-gmp \
--with-mhash \
--enable-json \
--enable-mbstring \
--enable-mbregex \
--enable-mbregex-backtrack \
--with-libmbfl \
--with-onig \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-zlib-dir \
--with-pdo-sqlite \
--with-readline \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets  \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--with-libxml-dir \
--with-xsl \
--enable-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-opcache

5、安装后的配置

执行完安装命令后php7就已经安装在到了/usr/local/php目录下了。

/usr/local/php7/bin/php -v

查看是否安装成功。

为了以后方便,可以编辑 /etc/profile 添加环境变量 ,添加到最后面

PATH=$PATH:/usr/local/php7/bin
export PATH

然后更新环境变量。

source /etc/profile

查看环境变量

echo $PATH

查看php版本

php -v

6、配置PHP-FPM

cp php.ini-production /etc/php.ini
cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm

启动php-fpm

/etc/init.d/php-fpm start

或者

service php-fpm start

如果报这种错误

Starting php-fpm [12-May-2018 20:09:45] ERROR: [pool www] cannot get uid for user 'www'

说明没有该用户,直接执行

groupadd www
useradd -g www www

然后在启动php-fpm

解决php编译报错configure: error: mcrypt.h not found. Please reinstall libmcrypt.

yum install -y epel-release
yum install -y libmcrypt-devel

两个不能一起安装,因为CentOs6默认的yum源没有 libmcrypt-devel这个包,只能借助epel的yum源,所以先安装epel,再安装libmcrypt。

你可能感兴趣的:(Centos7 编译安装PHP7)