编译PHP

作者: b465b57553dd | 来源:发表于2019-08-27 14:04 被阅读0次

    ## 编译过程

    更新源

    ```bash

    apt-get update

    ```

    安装需要的库

    ```bash

    apt-get install make gcc wget tar libxml2-dev libssl-dev libbz2-dev curl libcurl4-openssl-dev libjpeg-dev libmcrypt-dev libfreetype6-dev libmemcached-dev autoconf pkgconf

    ```

    给 `libssl.so` 建立软连接

    ```bash

    ln -s /usr/lib/x86_64-linux-gnu/libssl.so /usr/lib/

    ```

    ```bash

    cd /tmp

    ```

    下载 `php` 安装包

    ```bash

    wget http://am1.php.net/distributions/php-7.0.28.tar.gz

    ```

    解压 `php` 安装包

    ```bash

    tar -zxvf php-7.0.28.tar.gz

    ```

    进入 `php` 安装包目录

    ```bash

    cd php-7.0.28

    ```

    编译安装 `php`

    ```bash

    ./configure --prefix=/usr/local/php --with-iconv --with-zlib --with-curl --with-openssl --with-bz2 --with-pdo-mysql=mysqlnd --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-mhash --with-mcrypt --with-fpm-user=www --with-fpm-group=www --with-libxml-dir  --enable-fpm --enable-xml --enable-mbstring --enable-sockets --enable-soap --enable-session --enable-opcache --enable-bcmath --enable-inline-optimization --enable-cli --enable-zip --enable-gd-native-ttf --enable-sockets --enable-mbregex --disable-rpath

    make && make install

    ```

    创建用户

    ```bash

    groupadd www

    useradd -g www www

    ```

    复制相关文件

    ```bash

    cp php.ini-development /usr/local/php/lib/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

    sed -i -e 's/listen = 127.0.0.1:9000/listen = \/var\/run\/php7.0-fpm.sock/' /usr/local/php/etc/php-fpm.d/www.conf

    cp sapi/fpm/init.d.php-fpm /etc/init.d/php7.0-fpm

    chmod +x /etc/init.d/php7.0-fpm

    ln -s /usr/local/php/bin/php /usr/bin/php7.0

    chmod +x /usr/bin/php7.0

    ```

    启动 `php`

    ```bash

    service php7.0-fpm start

    ```

    编译 `igbinary`

    ```bash

    wget http://pecl.php.net/get/igbinary-2.0.6.tgz

    tar -zxvf igbinary-2.0.6.tgz

    cd igbinary-2.0.6

    /usr/local/php/bin/phpize

    ./configure --with-php-config=/usr/local/php/bin/php-config

    make && make install

    sed -i '/extension\=php_xsl\.dll/a\extension\=igbinary\.so' /usr/local/php/lib/php.ini

    ```

    编译 `phpredis`

    ```bash

    wget http://pecl.php.net/get/redis-3.1.0.tgz

    tar -zxvf redis-3.1.0.tgz

    cd phpredis-3.1.0

    /usr/local/php/bin/phpize

    ./configure --with-php-config=/usr/local/php/bin/php-config

    make && make install

    sed -i '/extension\=php_xsl\.dll/a\extension\=redis\.so' /usr/local/php/lib/php.ini

    ```

    编译 `memcached`

    ```bash

    wget http://pecl.php.net/get/memcached-3.0.4.tgz

    tar -zxvf memcached-3.0.4.tgz

    cd memcached-3.0.4

    /usr/local/php/bin/phpize

    ./configure --with-php-config=/usr/local/php/bin/php-config

    make && make install

    sed -i '/extension\=php_xsl\.dll/a\extension\=memcached\.so' /usr/local/php/lib/php.ini

    ```

    删除不需要的文件

    ```bash

    rm -rf php*

    rm -rf mem*

    rm -rf igb*

    ```

    清除包

    ```bash

    apt-get autoclean

    apt-get autoremove

    ```

    启动 `PHP`

    ```bash

    service php7.0-fpm start

    ```

    至此,结束。

    -- EOF --

    本文转载自[IMJCW](http://jcwblog.com)

    原文链接:[Ubuntu编译安装PHP](http://jcwblog.com/articles/backend/php-compile.html)

    相关文章

      网友评论

          本文标题:编译PHP

          本文链接:https://www.haomeiwen.com/subject/pikeectx.html