第一步本地下载官网下载php安装包:网页进入php.net进入官网,点击downloads进入下载页面,点击最新版php.版本号.tar.gz
第二步:移动到服务器或虚拟机内。
第三步:解压php压缩包,tar -xzvf php.版本号.tar.gz
第四步:源码编译安装。必须要有gcc和autoconf,libxml2-devel,c++
yum install gcc
yum install gcc-c++
yum install autoconf
yum install libxml2-devel
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php
(配置文件如果不设置会默认在prefix/lib。通常我们设置在prefix/etc)
或者先安装如下依赖包(包括上面两个依赖包)
yum install -y gcc gcc-c++ make zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
或者
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php --enable-mbstring --enable-ftp --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pear --enable-sockets --with-freetype-dir=/usr --with-zlib --with-libxml-dir=/usr --with-xmlrpc --enable-zip --enable-fpm --enable-xml --enable-sockets --with-gd --with-zlib --with-iconv --enable-zip --with-freetype-dir=/usr/lib/ --enable-soap --enable-pcntl --enable-cli --with-curl
prefix=安装路径 ,--with-config-file-path为配置文件目录(详见http://php.net/manual/zh/configure.about.php)
其他的为php常用扩展
第五步:make
第六步:make install
第七步:简化php执行命令。将php环境变量加入全局配置文件中~/.bash_profile
vi ~/.bash_profile
加入内容 alisa php=/usr/local/php/bin
最后需要source ~/.bash_profile
或者在/etc/profile中修改
第八步:移动php.ini文件(默认放在profix/lib,可通过命令php -i | grep php.ini来查看)
进入编译后的php解压包中
cp php.ini-development /usr/local/php/lib
进入/usr/local/php/lib
mv php.ini-development php.ini