1、安装依赖
sudo apt update
sudo apt install gcc
sudo apt install make
sudo apt install openssl
sudo apt install curl
sudo apt install libbz2-dev
sudo apt install libxml2-dev
sudo apt install libjpeg-dev
sudo apt install libpng-dev
sudo apt install libfreetype6-dev
sudo apt install libzip-dev
2、下载PHP源码,生成configure
git clone https://github.com/php/php-src.git
# 或者git clone http://git.php.net/repository/php-src.git
cd php-src
./buildconf
./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
配置成功后会出现如下字样
+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+
Thank you for using PHP.
3、编译安装PHP
make -j4
# 测试php源码
make TEST_PHP_ARGS=-j4 test
make test
# 安装php
make install
4、验证PHP
usr/local/php/bin/php -v
# 编译安装后的目录并不会有现成的php.ini,需要从源码目录手动复制过去。
sudo cp php.ini-development /usr/local/php/etc/php.ini
5、安装PHP扩展库
方法一:
#从PECL官网下载需要的扩展:https://pecl.php.net/package-stats.php
#1、使用pecl安装扩展(redis为例)
[root@localhost]# wget http://pecl.php.net/get/redis-4.0.0.tgz
[root@localhost]# tar -xzvf redis-4.0.0.tgz && cd redis-4.0.0
#2、执行phpize
[root@localhost redis-4.0.0]# phpize
#3、./configure
[root@localhost redis-4.0.0]# ./configure --with-php-config=/usr/bin/php-config
#4、 make && make install
#5、配置php.ini
# 通过运行 php --ini查找php.ini文件位置,然后在文件中添加extension=memcached.so
方法二:
#1、使用pecl安装扩展(memcached为例)
~# pecl install memcached
#2、配置php.ini
# 通过运行 php --ini查找php.ini文件位置,然后在文件中添加extension=memcached.so