安装PHP5
PHP官网www.php.net
当前主流版本为5.6/7.1
进入安装包存放目录:cd /usr/local/src/
下载php5.6.31包:# wget http://mirrors.sohu.com/php/php-5.6.31.tar.gz
解压php:tar zxvf php-5.6.31.tar.gz
进入解压出来的php目录:cd php-5.6.31
编译
# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/httpd/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、错误如下:
Sorry, I cannot run apxs. Possible reasons follow:
1. Perl is not installed
2. apxs was not found. Try to pass the path using –with-apxs2=/path/to/apxs
3. Apache was not built using –enable-so (the apxs usage page is displayed)
The output of /usr/local/apache/bin/apxs follows:
./configure: /usr/local/apache/bin/apxs: not found
configure: error: Aborting
解决方法如下:
找到apache目录下的apxs脚本文件,然后编辑它,把第一行的注释的地方修改为perl的可执行路径(首先要保证你安装过perl,没有安装请先行安装),如
yum install perl perl-devel
# vi /usr/local/httpd/bin/apxs
修改成
#!/usr/bin/perl -w
####原来为 /replace/with/path/to/perl/interpreter
2、错误:configure: error: xml2-config not found. Please check your libxml2 installation.
解决方法如下:yum install libxml2-devel -y
3、错误:configure: error: Cannot find OpenSSL's <evp.h>
解决方法如下: # yum install openssl-devel -y
4、错误configure: error: Please reinstall the BZip2 distribution
解决方法如下:yum install -y bzip2-devel -y
5、错误:configure: error: jpeglib.h not found.
解决方法如下:yum install -y libjpeg-devel -y
6、错误configure: error: png.h not found.
解决方法如下:yum install -y libpng-devel -y
7、错误configure: error: freetype-config not found.
解决方法如下:yum install -y freetype-devel
8、错误configure: error: mcrypt.h not found. Please reinstall libmcrypt.
解决方法如下:# yum install epel-release
# yum install -y libmcrypt-devel
重新执行configure,最后显示如下
# make && make install
执行完后如下
php的安装目录下有这些目录
查看加载的模块# /usr/local/php/bin/php -m
他是以apache模块加载的
安装PHP7
进入安装目录存放地址:cd /usr/local/src/
下载php7.1.6包:wget http://mirrors.sohu.com/php/php-7.1.6.tar.gz
解压:tar zxvf php-7.1.6.tar.gz
进入php-7.1.6目录:cd php-7.1.6
编译(编译方法和编译php5的差不多)
# ./configure --prefix=/usr/local/php7 --with-apxs2=/usr/local/httpd/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
ls /usr/local/apache2.4/modules/libphp7.so
拷贝配置文件:cp php.ini-production /usr/local/php7/etc/php.ini
拷贝配置文件:cp php.ini-production /usr/local/php/etc/php.ini