11.10-11.12 安装PHP5

11.10-11.13 PHP5和PHP7安装_PHP7

PHP官网www.php.net


当前主流版本为5.6/7.1

大部分企业都是用5比较多


1 cd

cd /usr/local/src/

2 下载包

wget http://cn2.php.net/distributions/php-5.6.30.tar.bz2

3 解压

tar jxvf php-5.6.30.tar.bz2

4 进入包进行初始化、编译、安装

cd php-5.6.30


5 配置参数:(这配置参数是万金油,参数对应功能,一般无特定要求按照以下复制全部就可以)

./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

初始、编译过程中,可能会出现报错信息,大多数情况是缺少部分库包组成的。期间,可能会发生一系列的报错,具体如下:

发生报错1

configure: error: Cannot find OpenSSL's <evp.h>

解决方法

yum install -y openssl openssl-devel

发生报错2

checking for BZip2 in default path... not found

configure: error: Please reinstall the BZip2 distribution

解决方法

yum install -y bzip2 bzip2-devel


发生报错3

configure: error: jpeglib.h not found.

解决方法

yum install -y libjpeg libjpeg-devel

报错4

configure: error: freetype-config not found.

解决方法

yum install -y freetype freetype-devel

报错5

configure: error: mcrypt.h not found. Please reinstall libmcrypt.

解决方法

yum install -y epel-release
yum install -y libmcrypt-devel

初始化成功,

11.10-11.13 PHP5和PHP7安装_LAMP_02


make && make install


# ls /usr/local/php/bin/php 这个二进制php文件是整个php的核心文件

#ls /usr/local/apache2.4/modules/libphp5.so 这个是apache与php连接的模块的文件

查看php加载的模块


/usr/local/php/bin/php -m


7 复制配置文件 

cp php.ini-production  /usr/local/php/etc/php.ini


利用-i|less 去查看php的配置信息,编译参数,configure的路径

/usr/local/php/bin/php -i |less

cp文件前,加载路径是空的

11.10-11.13 PHP5和PHP7安装_LAMP_03 

cp后,是多了特定路径。

11.10-11.13 PHP5和PHP7安装_PHP7_04 



11.13 安装php7


11.10-11.13 PHP5和PHP7安装_PHP5_05

cd /usr/local/src/ 
wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2
tar zxf php-7.1.6.tar.bz2
cd php-7.1.6
./configure --prefix=/usr/local/php7 --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php7/etc  --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
make && make install

在apache2.4/modules/查看php7的libphp7.so模块文件,其中还有libphp5.so

ls /usr/local/apache2.4/modules/libphp7.so
ls /usr/local/apache2.4/modules/libphp
libphp5.so  libphp7.so


php5与php7只能同时使用一个,所以要修改apache的httpd配置文件。

如果不想用其中一个,注释即可,但是只能留一个。

11.10-11.13 PHP5和PHP7安装_PHP7_06

cp php.ini-production  /usr/local/php7/etc/php.ini