Centos7 編譯安裝PHP7

2021-09-19 19:00:32 字數 3553 閱讀 1980

centos7 編譯安裝php7

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

wget 

tar -zxvf php-7.1.0.tar.gz

cd 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-******xml \

--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/bin

export 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 www

useradd -g www www

然後在啟動php-fpm

CentOS 7 編譯安裝 PHP 7

使用編譯的方式來安裝 php 7。輸入yum y install libxml2 libxml2 devel openssl openssl devel curl devel libjpeg devel libpng devel freetype devel libmcrypt devel mhas...

CentOS 7 編譯安裝 PHP 7

使用編譯的方式來安裝 php 7。輸入yum y install libxml2 libxml2 devel openssl openssl devel curl devel libjpeg devel libpng devel freetype devel libmcrypt devel mhas...

centos編譯安裝PHP7

在php.net中找到最新穩定版php原始碼 這裡我選擇了最新版php 7.1.9 wget php.tar gz net get php 7.1 9.tar gz from this mirror tar xzvf php.tar gzcd php 2 配置php 解壓了php原始碼之後,我們需要...