Ubuntu14.04 源码安装 PHP7.2

1.下载PHP源码

首先需要从PHP官网下载PHP7.2.31的源代码,保存为php-7.2.31.tar.xz。

wget https://www.php.net/distributions/php-7.2.31.tar.xz
tar -xvJf ./php-7.2.31.tar.xz
cd php-7.2.31

2.安装依赖

sudo apt-get update && apt-get install -y gcc make openssl \
curl libbz2-dev libxml2-dev libjpeg-dev libpng-dev \
libfreetype6-dev libzip-dev  libcurl3-openssl-dev \
libmysql++-dev

3.PHP进行配置

./configure --prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--enable-fpm --with-fpm-user=www --with-fpm-group=www \
--with-mysqli --with-pdo-mysql --with-iconv-dir \
--with-freetype-dir --with-jpeg-dir --with-png-dir \
--with-zlib --with-libxml-dir=/usr --enable-xml \
--disable-rpath --enable-bcmath --enable-shmop \
--enable-sysvsem --enable-inline-optimization \
--with-curl --enable-mbregex --enable-mbstring \
--enable-ftp --with-gd --with-openssl --with-mhash \
--enable-pcntl --enable-sockets --with-xmlrpc \
--enable-zip --enable-soap --without-pear \
--with-gettext --disable-fileinfo \
--enable-maintainer-zts

4.编译安装

make && make install

5.验证并添加PHP环境变量

/usr/local/php/bin/php -v
**成功后**
echo "export PATH=$PATH:/usr/local/php/bin" >>  /etc/profile
source /etc/profile
php -v 
php -m

6安装phpunit

wget https://phar.phpunit.de/phpunit-6.0.0.phar
chmod +x phpunit.phar
mv phpunit-6.0.0.phar /usr/local/bin/phpunit
phpunit -V

7.新增redis、rdkafka、xdebug扩展

redis扩展

apt-get install m4 autoconf
wget http://pecl.php.net/get/redis-3.1.3.tgz
tar zxvf redis-3.1.3.tgz
cd redis-3.1.3
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
echo "extension="redis.so"" >> /usr/local/php/etc/php.ini
/etc/init.d/apache2 restart
php -m | grep redis

rdkafka扩展

git clone https://github.com/edenhill/librdkafka.git
cd librdkafka/
./configure
make && make install
git clone https://github.com/arnaud-lb/php-rdkafka.git
cd php-rdkafka/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install 
echo "extension="rdkafka.so"" >> /usr/local/php/etc/php.ini
/etc/init.d/apache2 restart
php -m | grep rdkafka

xdebug扩展

wget https://xdebug.org/files/xdebug-2.9.6.tgz
tar -xf xdebug-2.9.6.tgz
cd xdebug-2.9.6
/usr/local/php/bin/phpize
./configure --enable-xdebug --with-php-config=/usr/local/php/bin/php-config
make && make install
vim /usr/local/php/etc/php.ini
	添加
	zend_extension=xdebug.so
	xdebug.remote_enable = 1
	xdebug.remote_connect_back = 1
	xdebug.remote_port = 9005
	xdebug.max_nesting_level = 512
php -m | grep xdebug

你可能感兴趣的:(ubuntu,php,源码,php,ubuntu)