1,到php官网下载合适的版本,这里选择5.6
2,tar -xzvf php-5.6.33.tar.gz #解压
3,cd php-5.6.33
4,./configure --prefix=/usr/local/php56 --with-config-file-path=/usr/local/php56/etc --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-opcache --enable-fpm --with-mysql --with-mysqli --with-pdo-mysql --with-gettext --enable-mbstring --with-iconv --with-mcrypt --with-mhash --with-openssl --enable-bcmath --enable-soap --with-libxml-dir --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --with-curl --with-zlib --enable-zip --with-bz2 --with-readline
#配置编译环境,当中可能会出错,但别担心,报错的基本是告诉你哪些依赖没安装,根据错误信息去安装相应的依赖包就可以了,如果一切顺利,出现"thanks use php",就可以开始第5步了。
5,make && make install #编译并安装php,如果成功你就可以看到目录/usr/local/下多了php56,如果没看到说明安装失败了,输入make clean && make clean all,重新从第4步安装。
6,根据使用的服务器nginx/apache作相应配置即可。