天天看点

安装php5、php7

安装php5

php用c语言编写的。

1、下载:

[root@centos7 package]# wget http://cn2.php.net/distributions/php-5.6.30.tar.gz 

2、安装:

tar zxvf php-5.6.30.tar.gz

cd php-5.6.30/

yum install -y libxml2-devel openssl-devel bzip2-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-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

备注:

--prefix=/usr/local/php 指定安装目录

--with-config-file-path=/usr/local/php/etc 指定配置文件所在路径

--with-mysql=/usr/local/mysql 指定mysql的路径

--with-mysqli=/usr/local/mysql/bin/mysql_config  //上面两项参数是指定相关mysql库

--with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config //上面两项参数是指定相关mysql库

其他:都是安装php模块

echo $?

成功如下:

<a href="https://s1.51cto.com/oss/201711/09/e1c625fe5a04e5a10f10aa7d7f8177f5.png-wh_500x0-wm_3-wmp_4-s_1629320768.png" target="_blank"></a>

3、编译安装

make

安装成功如下:

<a href="https://s1.51cto.com/oss/201711/09/6fe6ce2f03deb4c2c3481dd2174425a6.png-wh_500x0-wm_3-wmp_4-s_1601715490.png" target="_blank"></a>

make install

<a href="https://s1.51cto.com/oss/201711/09/ca3f973374723258bdb9b0873385acb3.png-wh_500x0-wm_3-wmp_4-s_3835460504.png" target="_blank"></a>

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

/usr/local/apache2.4/bin/apachectl -M

 alias_module (shared)

 rewrite_module (shared)

 php5_module (shared)  //这个就是安装php模板

Syntax OK

说明:安装完成PHP后会在Apache中自动添加相应模块,在Apache配置文件/usr/local/apache2.4/conf/httpd.conf中也会自动添加相应配置内容。请看如下:

[root@centos7 php-5.6.30]# cat  /usr/local/apache2.4/conf/httpd.conf| grep 'php'

LoadModule php5_module        modules/libphp5.so

安装php7

1、下载

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

2、解压

tar -jxvf php-7.1.6.tar.bz2 

报错:

<a href="https://s5.51cto.com/oss/201711/09/f03c6e79ec78d957fee9e9762e28aee2.png-wh_500x0-wm_3-wmp_4-s_4288733936.png" target="_blank"></a>

解决:

yum install bzip2

3、cd php-7.1.6

4、

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

5、make

6、make install

7、cp /data/package/php-7.1.6/php.ini-production /usr/local/php7/etc/php.ini

8、/usr/local/apache2.4/bin/apachectl -M

 php5_module (shared)

 php7_module (shared)

可以看出以上有2个php模块

9、查看httpd配置文件

[root@centos7 etc]# cat /usr/local/apache2.4/conf/httpd.conf| grep 'php'

LoadModule php7_module        modules/libphp7.so

10、要用哪个版本,在httpd.conf中将另外的版本注释掉即可

本文转自 iekegz 51CTO博客,原文链接:http://blog.51cto.com/jacksoner/1980192,如需转载请自行联系原作者