安装 PHP5
PHP(Hypertext Preprocessor)英文超级文本预处理语言。PHP是一种HTML内嵌式的语言,是一种在服务端执行的嵌入HTML文档的脚本语言。官网:www.php.net
-
下载并解压安装包
切换目录至/usr/local/src/:
[root@localhost ~]# cd /usr/local/src/
下载源码包:
[root@localhost src]# wget http://cn2.php.net/distributions/php-5.6.30.tar.bz2
解压包:
[root@localhost src]#tar jxv -f php-5.6.30.tar.bz2 -
配置源码包
[root@localhost src]# cd php-5.6.30/
[root@localhost php-5.6.30]# ./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-apxs2=/usr/local/apache2.4/bin/apxs #该文件是Apache的一个工具,可以将扩展模块添加到Apache的module文件。
--with-config-file-path=/usr/local/php/etc #指定配置文件所在路径
--with-mysql=/usr/local/mysql #指定mysql的路径
--with-pdo-mysql=/usr/local/mysql
--with-mysqli=/usr/local/mysql/bin/mysql_config
#上面两行定义mysql相关函数和驱动#下面的这些为php配置常用的模块
--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: xml2-config not found. Please check your libxml2 installation.
说明:缺少xml2库。
解决办法,安装 libxm12-devel
查找相关的库安装包:
[root@localhost php-5.6.30]# yum list |grep libxml2
安装库文件:
[root@localhost php-5.6.30]# yum install -y libxml2-devel
报错2:
configure: error: Cannot find OpenSSL's <evp.h>
说明:缺少OpenSSL's。
解决办法,安装openssl-devel
[root@localhost php-5.6.30]# yum install -y openssl-devel
报错3:
configure: error: Please reinstall the BZip2 distribution
说明:重新安装bZip2。
解决办法,安装bzip2-devel
[root@localhost php-5.6.30]# yum install -y bzip2-devel
报错4:
configure: error: jpeglib.h not found.
说明:缺少jpeg库。
解决办法,安装libjpeg-devel
[root@localhost php-5.6.30]# yum install -y libjpeg-devel
报错5:
configure: error: png.h not found.
说明:缺少png库。
解决办法,安装libpng-devel
[root@localhost php-5.6.30]# yum install -y libpng-devel
报错6:
configure: error: freetype-config not found.
说明:缺少freetype库。
解决办法,安装freetype-devel
[root@localhost php-5.6.30]# yum install -y freetype-devel
报错7:
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
说明:缺少mcrypt库。
解决办法,安装libmcrypt-devel。安装libmcrypt-devel时,需先按装epl-release。因为yum源没有libmcrypt-devel包,所以只能借助epel yum扩展安装。
[root@localhost php-5.6.30]# yum install -y libtomcrypt-devel
-
配置时,如果使用的不是mysql,而是mariadb则需要将其中的路径改成mariadb的路径。(将所有的mysql改成mariadb)
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mariadb=/usr/local/mariadb --with-pdo-mariadb=/usr/local/mariadb --with-mariadbi=/usr/local/mariadb/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
-
编译和安装
[root@localhost php-5.6.30]# make
...
Build complete.
Don't forget to run 'make test'.
编译的时间有点长
[root@localhost php-5.6.30]# make install
- php和apache结合是通过/usr/local/apache2.4/modules/libphp5.so 这个文件。
-
查看php加载了哪些模块
[root@localhost php-5.6.30]# /usr/local/php/bin/php -m
模块都是静态的
-
将配置文件放到/usr/local/php/etc/php.ini
[root@localhost php-5.6.30]# cp php.ini-production /usr/local/php/etc/php.ini
安装PHP7
-
下载并解压
[root@localhost src]# wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2
[root@localhost src]# tar jxv -f php-7.1.6.tar.bz2 -
环境配置
[root@localhost src]# cd ./php-7.1.6/
[root@localhost src]# ./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
注意:php7与php5不通处在于php7没有“--with-mysql”选项 -
编译安装
[root@localhost php-7.1.6]# make
[root@localhost php-7.1.6]# echo $?
0
[root@localhost php-7.1.6]# make install
[root@localhost php-7.1.6]# echo $?
0 -
一台机器可以同时安装php5和php7。apache调用的时候需要指定好。
apache配置文件/usr/local/apache2.4/conf/httpd.conf
[root@localhost php-7.1.6]# vim /usr/local/apache2.4/conf/httpd.conf
LoadModule php5_module modules/libphp5.so
LoadModule php7_module modules/libphp7.so
(150行/151行)
不想用哪个就把把哪个注释掉就行了。
转载于:https://blog.51cto.com/754599082/2051883