PHP

下载源代码

PHPVER=php-7.1.1
wget -c "http://cn2.php.net/distributions/${PHPVER}.tar.gz" -O ${PHPVER}.tar.gz
tar xf ${PHPVER}.tar.gz
cd ${PHPVER}

Debian

apt-get install -y libxml2-dev autoconf libmysqlclient-dev libmcrypt-dev libgd2-xpm-dev libcurl4-gnutls-dev bzip2 libvpx-dev libxpm-dev libicu-dev openssl libssl-dev
./configure --prefix=/opt/${PHPVER} \
    --enable-fpm \
    --enable-mbstring \
    --enable-calendar \
    --enable-exif \
    --enable-intl \
    --enable-soap \
    --enable-opcache \
    --enable-zip \
    --enable-bcmath \
    --enable-sockets \
    --enable-ftp \
    --with-gd \
    --with-mysql=mysqlnd \
    --with-mysqli \
    --with-pdo-mysql=mysqlnd \
    --with-mcrypt \
    --with-openssl \
    --with-curl \
    --with-iconv \
    --with-zlib \
    --with-gettext \
    --with-gd --with-jpeg-dir --with-png-dir --with-vpx-dir --with-xpm-dir --with-freetype-dir --disable-fileinfo
make
make install

CentOS

./configure --prefix=/opt/${PHPVER} \
    --enable-fpm \
    --enable-mbstring \
    --enable-calendar \
    --enable-exif \
    --enable-intl \
    --enable-soap \
    --enable-opcache \
    --enable-zip \
    --enable-bcmath \
    --enable-sockets \
    --enable-ftp \
    --with-gd \
    --with-mysql=mysqlnd \
    --with-mysqli \
    --with-pdo-mysql=mysqlnd \
    --with-mcrypt=/opt/libmcrypt/ \
    --with-openssl \
    --with-curl \
    --with-iconv \
    --with-gettext \
    --with-zlib
make
sudo make install

MacOS

./configure --prefix=/opt/${PHPVER} \
    --enable-fpm \
    --enable-mbstring \
    --enable-calendar \
    --enable-exif \
    --enable-intl \
    --enable-soap \
    --enable-opcache \
    --enable-zip \
    --enable-bcmath \
    --enable-sockets \
    --enable-ftp \
    --with-gd=/opt/local/ \
    --with-jpeg-dir=/opt/local/ \
    --with-png-dir=/opt/local/ \
    --with-vpx-dir=/opt/local/ \
    --with-xpm-dir=/opt/local/ \
    --with-freetype-dir=/opt/local/ \
    --with-mysql=mysqlnd \
    --with-mysqli \
    --with-pdo-mysql=mysqlnd \
    --with-mcrypt=/opt/local/ \
    --with-openssl=/opt/local/ \
    --with-curl=/opt/local/ \
    --with-iconv=/opt/local/ \
    --with-gettext \
    --with-zlib --with-zlib-dir=/opt/local/
make
sudo make install

配置

cp php.ini-production /opt/${PHPVER}/lib/php.ini
cp -f sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
cp sapi/fpm/php-fpm.conf /opt/${PHPVER}/etc/php-fpm.conf
echo "zend_extension=opcache.so" >> /opt/${PHPVER}/lib/php.ini
sed -i "s/;date.timezone.*/date.timezone = Asia\/Shanghai/" /opt/${PHPVER}/lib/php.ini
sed -i "s/short_open_tag = Off/short_open_tag = On/" /opt/${PHPVER}/lib/php.ini
sed -i "s/;pid = run\/php-fpm.pid/pid = run\/php-fpm.pid/" /opt/${PHPVER}/etc/php-fpm.conf
sed -i "s/user = nobody/user = www-data/" /opt/${PHPVER}/etc/php-fpm.conf
sed -i "s/group = nobody/group = www-data/" /opt/${PHPVER}/etc/php-fpm.conf
sed -i "s/;pm.min_spare_servers/pm.min_spare_servers/" /opt/${PHPVER}/etc/php-fpm.conf
sed -i "s/;pm.max_spare_servers/pm.max_spare_servers/" /opt/${PHPVER}/etc/php-fpm.conf
sed -i "s/;pm.max_requests/pm.max_requests/" /opt/${PHPVER}/etc/php-fpm.conf
ln -s /opt/${PHPVER}/bin/php /bin/php

扩展

cd ext

# memcache
MEMCACHEVER=2.2.7
wget -c "http://pecl.php.net/get/memcache-${MEMCACHEVER}.tgz"
tar xf memcache-${MEMCACHEVER}.tgz
cd memcache-${MEMCACHEVER}
/opt/${PHPVER}/bin/phpize
./configure --with-php-config=/opt/${PHPVER}/bin/php-config
make
make install
echo "extension=memcache.so" >> /opt/${PHPVER}/lib/php.ini