在 Ubuntu 下编译安装 PHP 7.2

更新及安装基础工具

apt update 
apt upgrade -y 
apt install -y git zip unzip autoconf lrzsz

PHP安装

下载

下载页面 http://php.net/get/php-7.2.11.tar.bz2/from/a/mirror 可选择一个最快的下载镜像地址

wget -c http://cn.php.net/distributions/php-7.2.11.tar.bz2

解压

tar -xcf php-7.2.11.tar.bz2

编译安装

进入到解压目录 php-7.2.11

./configure \
    --prefix=/usr/local/php7.3/
    --enable-zip \
    --enable-bcmath \
    --enable-exif \
    --enable-fpm \
    --enable-intl \
    --enable-mbstring \
    --enable-pcntl \
    --enable-soap \
    --enable-sysvmsg \
    --enable-sysvsem \
    --enable-sysvshm \
    --enable-mysqlnd \
    --enable-sockets \
    --disable-opcache \
    --with-openssl \
    --with-zlib \
    --with-curl \
    --with-bz2 \
    --with-openssl \
    --with-gd \
    --with-mysqli \
    --with-xsl \
    --with-pdo-mysql \
    && make \
    && make install

修复依赖错误

错误:configure: error: libxml2 not found. Please check your libxml2 installation.
修复:apt install -y libxml2 libxml2-dev

错误:configure: error: Cannot find OpenSSL's <evp.h>
修复:apt install -y libssl-dev libsslcommon2-dev

错误:configure: error: Cannot find OpenSSL's libraries
修复:ln -s /usr/lib/x86_64-linux-gnu/libssl.so /usr/lib

错误:configure: error: Please reinstall the BZip2 distribution
修复:apt install -y libbz2-dev

错误:configure: error: png.h not found.
修复:apt install -y libpng-dev

错误:configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
修复:apt install -y libxslt1-dev

apt install -y libxml2-dev libssl-dev libbz2-dev libpng-dev libxslt1-dev
ln -s /usr/lib/x86_64-linux-gnu/libssl.so /usr/lib

配置

cp php.ini-production /usr/local/lib/php.ini
cp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf
cp /usr/local/etc/php-fpm.d/www.conf.default /usr/local/etc/php-fpm.d/www.conf

打开 /usr/local/etc/php-fpm.conf
修改

include=NONE/etc/php-fpm.d/*.conf

include=/usr/local/etc/php-fpm.d/*.conf

打开 vim /usr/local/etc/php-fpm.d/www.conf
修改

user = nobody
group = nobody

user = www-data
group = www-data

安装扩展

Redis

pecl install redis

错误: checking for igbinary includes... configure: error: Cannot find igbinary.h
修复pecl install igbinary && echo "extension=igbinary.so" >> /usr/local/lib/php.ini
更新 ini 文件

echo "extension=redis.so" >> /usr/local/lib/php.ini

Swoole

pecl install swoole

错误fatal error: hiredis/hiredis.h: No such file or directory
修复apt install -y libhiredis-dev

更新 ini 文件

echo "extension=swoole.so" >> /usr/local/lib/php.ini

其他安装配置

生成密钥对: ssh-keygen

install composer

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '93b54496392c062774670ac18b134c3b3a95e5a5e5c8f1a9f115f203b75bf9a129d5daa8ba6a13e2cc8a1da0806388a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php --filename=composer --install-dir=/usr/bin 
php -r "unlink('composer-setup.php');"

install nginx

apt install -y nginx
Comments
Write a Comment