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.gztar -zxvf php-7.1.0.tar.gzcd php-7.1.0
4、编译安装(./configure --help 查看编译参数)
./configure \--prefix=/usr/local/php \--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
完成后,再进行编译及安装,执行 make && make install 即可安装完毕。
5、安装后的配置
执行完安装命令后php7就已经安装在到了/usr/local/php目录下了。
/usr/local/php/bin/php -v
查看是否安装成功。
为了以后方便,可以编辑 /etc/profile 添加环境变量 ,添加到最后面
PATH=$PATH:/usr/local/php/binexport PATH
然后更新环境变量。
source /etc/profile
查看环境变量
echo $PATH
查看php版本
php -v
6、配置PHP-FPM
cp php.ini-production /etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/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 wwwuseradd -g www www
然后在启动php-fpm