menny 发表于 2018-12-12 07:29:11

安装 PHP5

http://i2.运维网.com/images/blog/201805/12/2b1c87dfdfc39da5636302f53131f5f8.png
  安装方法大同小异,首先下载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
http://i2.运维网.com/images/blog/201805/12/82baab26ef47a77ba18ae95f8d202fe2.png
安装包 php-5.6.36.tar.gz 下载完毕,然后进行解压,输入命令 tar -zxvf php-5.6.36.tar.gz,回车,内容较多,不截图。然后进行编译,见下图,
http://i2.运维网.com/images/blog/201805/12/b275515d14d2c7e5bd0e20822b624cba.png
回车,内容较多,截取最后一屏,见下图,
http://i2.运维网.com/images/blog/201805/12/9ff2b18810103275f15fec908150e3e5.png
出现报错,configure: error: xml2-config not found. Please check your libxml2 installation.显示需要安装 libxml2,具体操作见下图,
http://i2.运维网.com/images/blog/201805/12/d4fac466a1bf85641117098edbff47fd.png
http://i2.运维网.com/images/blog/201805/12/aac1d1e6fb1010f43bc363ef787901d2.png
安装完成之后,继续输入刚才的命令 ./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 ,回车,
http://i2.运维网.com/images/blog/201805/12/3977b7818afea908abc5ec911e4d7a9d.png
又出现报错,configure: error: Cannot find OpenSSL's ,显示需要安装 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 ,回车,
http://i2.运维网.com/images/blog/201805/12/b3a5daf6613fac2e6b4e4ca1bf7476ef.png
又出现报错,configure: error: Please reinstall the BZip2 distribution,显示需要安装 bzip2-devel 这个包,输入命令 yum install -y bzip2-devel,回车,
http://i2.运维网.com/images/blog/201805/12/488e70bc1b947ba607de17c66e837086.png
安装完成之后,再次执行命令,见下图,
http://i2.运维网.com/images/blog/201805/12/38398616d2ed4384cff4e65af037511e.png
又出现报错,configure: error: jpeglib.h not found.显示需要安装 libjpeg-devel 这个包,输入命令 yum install -y libjpeg-devel,回车,
http://i2.运维网.com/images/blog/201805/12/be961b496bcd17ae3b96f367c2c3af8e.png
安装完成之后,再次执行命令,见下图,
http://i2.运维网.com/images/blog/201805/12/a3e1ed0bba004c87dc8f35e37cfa6101.png
又出现报错,configure: error: png.h not found.显示需要安装 libpng-devel 这个包,输入命令 yum install -y libpng-devel,回车,
http://i2.运维网.com/images/blog/201805/12/b011c9f3e7b7e220bbc6d8939088306e.png
安装完成之后,再次执行命令,见下图,
http://i2.运维网.com/images/blog/201805/12/3324e106a88a5c7242b65287ca2dd3b7.png
又出现报错,configure: error: freetype-config not found.显示需要安装 freetype-devel 这个包,输入命令 yum install -y freetype-devel,回车,
http://i2.运维网.com/images/blog/201805/12/2ab4cfac15ce7b0e3ef07cf3a3e6cf4e.png
http://i2.运维网.com/images/blog/201805/12/3184e0eca9897efec5dbd74d6a9a7d81.png
安装完成之后,再次执行命令,见下图,
http://i2.运维网.com/images/blog/201805/12/d0f6684599110ebf2b4a0775d251b617.png
又出现报错,configure: error: mcrypt.h not found. Please reinstall libmcrypt.显示需要安装 libmcrypt-devel 这个包,安装这个包之前,需要先安装一个扩展源,输入命令 yum install -y epel-release,回车,显示已安装,接着输入命令 yum install -y libmcrypt-devel,回车,
http://i2.运维网.com/images/blog/201805/12/278336aca8ca68bb6b2bba9b2cc3f396.png
http://i2.运维网.com/images/blog/201805/12/e68d5eda4ff5c7ce3877882f6284b49e.png
安装完成之后,再次执行命令,见下图,
http://i2.运维网.com/images/blog/201805/12/89436bad0df9f0db85e436d4df05bf9f.png
可以看到,这次就成功了,没有出现报错。使用命令 echo $? 查看,是对的。接着使用 make 命令,见下图,
http://i2.运维网.com/images/blog/201805/12/bcd0887fedfb5d29086bb0a6250e8f27.png
make 这个命令需要执行的时间比较长,没有出现错误,就执行命令 make install ,回车,
http://i2.运维网.com/images/blog/201805/12/4c15a9749ad20898c9302814b5b0a0b4.png
http://i2.运维网.com/images/blog/201805/12/00e78db405db9d86b694412ac15b9fe4.png
接着来看一下 PHP 的目录,见下图,
http://i2.运维网.com/images/blog/201805/12/6e42266dadaef043bb14f4ad29acb8ed.png
核心的二进制文件在目录 /usr/local/php/bin/ 下面,里面的 php 文件大小是36M,很大。再查看文件 /usr/local/apache2.4/modules/libphp5.so 的大小也是36M,这个就是我们想要的扩展模块。接着来查看一下php所加载的模块有哪些,见下图,
http://i2.运维网.com/images/blog/201805/12/2e975acb5b4aa8441248051b98e4b19a.png
查看所加载的模块的命令,全部都是静态的,也能够扩展模块安装。
http://i2.运维网.com/images/blog/201805/12/59587862e07295566d14f1af7907e410.png
回车,进入文件httpd.conf,可以看到很多#注释的模块,
http://i2.运维网.com/images/blog/201805/12/7ecd09345b50d6f1f842408eb00e9026.png
这边比较方便的地方是,想启用模块,就把前面的#去掉并保存。想停掉模块,就在前面加上#保存。输入 :q!,回车强行退出。
接着可以输入命令 /usr/local/php/bin/php -i |less,回车查看,
http://i2.运维网.com/images/blog/201805/12/0ee18c9e22e4c94ff84a5b4de0921676.png
可以看到一些 php 的信息。
因为目录 /usr/local/php/etc 下面没有 php.ini 文件,所以需要在php源码包的根目录下拷贝,见下图,
http://i2.运维网.com/images/blog/201805/12/16aeac22ce8cf982f9a0177f8d461594.png
回车,
http://i2.运维网.com/images/blog/201805/12/aaefeb422a8decc8cfa400adc9a1b348.png
这时候就能看到,/usr/local/php/etc/php.ini 加载上去了,可以对前面没有加载的图片,显示的是 none 。



页: [1]
查看完整版本: 安装 PHP5