安装php5
php用c语言编写的。
1、下载:
[[email protected] 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 $?
成功如下:
3、编译安装
make
安装成功如下:
echo $?
make install
echo $?
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中也会自动添加相应配置内容。请看如下:
[[email protected] 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
报错:
解决:
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
rewrite_module (shared)
php5_module (shared)
php7_module (shared)
Syntax OK
可以看出以上有2个php模块
9、查看httpd配置文件
[[email protected] etc]# cat /usr/local/apache2.4/conf/httpd.conf| grep ‘php‘
LoadModule php5_module modules/libphp5.so
LoadModule php7_module modules/libphp7.so
10、要用哪个版本,在httpd.conf中将另外的版本注释掉即可