安装 PHP5

安装 PHP5

安装方法大同小异,首先下载5.6的安装包,使用到的命令如下:
cd /usr/local/src/
wget http://cn2.php.net/distributions/php-5.6.36.tar.gz
tar -zxvf php-5.6.36.tar.gz
cd php-5.6.36/
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif

安装 PHP5
安装包 php-5.6.36.tar.gz 下载完毕,然后进行解压,输入命令 tar -zxvf php-5.6.36.tar.gz,回车,内容较多,不截图。然后进行编译,见下图,
安装 PHP5
回车,内容较多,截取最后一屏,见下图,
安装 PHP5
出现报错,configure: error: xml2-config not found. Please check your libxml2 installation. 显示需要安装 libxml2,具体操作见下图,
安装 PHP5
安装 PHP5
安装完成之后,继续输入刚才的命令 ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif ,回车,
安装 PHP5
又出现报错,configure: error: Cannot find OpenSSL's <evp.h>,显示需要安装 openssl-devel,输入命令 yum install -y openssl-devel,回车。内容较多,不截图了。安装完成之后,继续执行命令 ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif ,回车,
安装 PHP5
又出现报错,configure: error: Please reinstall the BZip2 distribution,显示需要安装 bzip2-devel 这个包,输入命令 yum install -y bzip2-devel,回车,
安装 PHP5
安装完成之后,再次执行命令,见下图,
安装 PHP5
又出现报错,configure: error: jpeglib.h not found. 显示需要安装 libjpeg-devel 这个包,输入命令 yum install -y libjpeg-devel,回车,
安装 PHP5
安装完成之后,再次执行命令,见下图,
安装 PHP5
又出现报错,configure: error: png.h not found. 显示需要安装 libpng-devel 这个包,输入命令 yum install -y libpng-devel,回车,
安装 PHP5
安装完成之后,再次执行命令,见下图,
安装 PHP5
又出现报错,configure: error: freetype-config not found. 显示需要安装 freetype-devel 这个包,输入命令 yum install -y freetype-devel,回车,
安装 PHP5
安装 PHP5
安装完成之后,再次执行命令,见下图,
安装 PHP5
又出现报错,configure: error: mcrypt.h not found. Please reinstall libmcrypt. 显示需要安装 libmcrypt-devel 这个包,安装这个包之前,需要先安装一个扩展源,输入命令 yum install -y epel-release,回车,显示已安装,接着输入命令 yum install -y libmcrypt-devel,回车,
安装 PHP5
安装 PHP5
安装完成之后,再次执行命令,见下图,
安装 PHP5
可以看到,这次就成功了,没有出现报错。使用命令 echo $? 查看,是对的。接着使用 make 命令,见下图,
安装 PHP5
make 这个命令需要执行的时间比较长,没有出现错误,就执行命令 make install ,回车,
安装 PHP5
安装 PHP5
接着来看一下 PHP 的目录,见下图,
安装 PHP5
核心的二进制文件在目录 /usr/local/php/bin/ 下面,里面的 php 文件大小是36M,很大。再查看文件 /usr/local/apache2.4/modules/libphp5.so 的大小也是36M,这个就是我们想要的扩展模块。接着来查看一下php所加载的模块有哪些,见下图,
安装 PHP5
查看所加载的模块的命令,全部都是静态的,也能够扩展模块安装。
安装 PHP5
回车,进入文件httpd.conf,可以看到很多#注释的模块,
安装 PHP5
这边比较方便的地方是,想启用模块,就把前面的#去掉并保存。想停掉模块,就在前面加上#保存。输入 :q!,回车强行退出。
接着可以输入命令 /usr/local/php/bin/php -i |less,回车查看,
安装 PHP5
可以看到一些 php 的信息。
因为目录 /usr/local/php/etc 下面没有 php.ini 文件,所以需要在php源码包的根目录下拷贝,见下图,
安装 PHP5
回车,
安装 PHP5
这时候就能看到,/usr/local/php/etc/php.ini 加载上去了,可以对前面没有加载的图片,显示的是 none 。

猜你喜欢

转载自blog.51cto.com/13503302/2115577