六 安装PHP5
PHP官网www.php.net
当前主流版本为5.6/7.1
1)下载cd /usr/local/src/
wget http://cn2.php.net/distributions/php-5.6.32.tar.gz
2)解压tar zxf php-5.6.32.tar.gz
3)编译cd php-5.6.32
./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: xml2-config not found. Please check your libxml2 installation.
解决:yum install –y libxml2-devel
继续编译报错2:configure: error: Cannot find OpenSSL's <evp.h>
解决:yum install –y openssl-devel
继续编译有报错3:checking for BZip2 in default path... not found
configure: error: Please reinstall the BZip2 distribution
解决:yum install -y bzip2-devel
继续编译报错4:If configure fails try --with-vpx-dir=<DIR>
checking for jpeg_read_header in -ljpeg... yes
configure: error: png.h not found.
解决:yum install –y libpng-devel
继续编译又出错5:If configure fails try --with-xpm-dir=<DIR>
configure: error: freetype-config not found.
解决:yum install -y freetype-devel
继续编译又出错6:configure: error: mcrypt.h not found. Please reinstall libmcrypt.
解决:yum install -y libtomcrypt-devel
如果之前没有安装epel,现在要安装yum install -y epel-release
centos默认yum源没有libtomcrypt-devel这个包,所以稚嫩个借助epel yum扩展源。
继续编译成功。
4)安装
#make && make install
5)查看安装后的文件
/usr/local/php/bin/php –m下的模块都是静态的。
php和Apache结合起来是通过libphp.so文件实现的。
/usr/local/apache2.4/bin/httpd –M查看Apache的模块,发现下面有了php5_module (shared)
命令/usr/local/php/bin/php -i |less可以查看PHP的一些信息
cp php.ini-production /usr/local/php/etc/php.ini
php.ini-production是生产环境,php.ini-development是开发环境,拷贝生产环境就可以了。
自动加载了。
七 安装PHP7
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
ls /usr/local/apache2.4/modules/libphp7.so
/usr/local/apache2.4/bin/apachectl –M
vim /usr/local/apache2.4/conf/httpd.conf
不用哪个可以注释掉
cp php.ini-production /usr/local/php7/etc/php.ini