Linux / php · 2020-03-17

ubuntu编译安装php7

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

下载php7源码解压

下载 https://github.com/kkos/oniguruma 源码编译安装或者不使用mbstring的正则功能,即在“–enable-mbstring”后再添加“–disable-mbregex”参数。这样的配置将不再需要oniguruma库

./configure \ –prefix=/usr/local/php7 \ –exec-prefix=/usr/local/php7 \ –bindir=/usr/local/php7/bin \ –sbindir=/usr/local/php7/sbin \ –includedir=/usr/local/php7/include \ –libdir=/usr/local/php7/lib/php \ –mandir=/usr/local/php7/php/man \ –with-zip \ –enable-pdo \ –enable-inline-optimization \ –enable-shared \ –enable-xml \ –enable-bcmath \ –enable-shmop \ –enable-sysvsem \ –enable-mbregex \ –enable-mbstring \ –enable-ftp \ –enable-pcntl \ –enable-sockets \ –enable-fileinfo \ –enable-filter \ –enable-soap \ –enable-session \ –enable-opcache \ –enable-fpm \ –disable-debug \ –disable-rpath \ –with-config-file-path=/usr/local/php7/etc \ –with-mysql-sock=/var/run/mysql/mysql.sock \ –with-mhash \ –with-openssl \ –with-mysqli=mysqlnd \ –with-pdo-mysql=mysqlnd \ –enable-gd \ –with-iconv \ –with-zlib \ –with-xmlrpc \ –with-gettext \ –with-curl \ –with-fpm-user=php \ –with-fpm-group=php \ –with-pear=/usr/local/php7/bin

<span class="token function">sudo</span> <span class="token function">make</span> <span class="token operator">&&</span> <span class="token function">make</span> <span class="token function">install

</span>
将/usr/local/php7加入环境变量

    增加php-fpm命令:
    sudo cp sapi/fpm/init.d.php-fpm /usr/local/php7/bin/php-fpm
    sudo chmod +x /usr/local/php7/bin/php-fpm

    初始化 PHP 和 PHP-FPM 的配置
    sudo cp php.ini-production /usr/local/php7/etc/php.ini
    sudo cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf

    将PHP-FPM加入系统服务
    cp sapi/fpm/php-fpm.service   /etc/systemd/system/
    chmod +x /etc/systemd/system/php-fpm.service

    设置开机自启以及开启服务:
    systemctl enable php-fpm.service
    systemctl start php-fpm.service