PHP5和PHP7的安装、PHP和apache的整合!
1、PHP5的安装:
下载:
wget -c http://cn2.php.net/distributions/php-5.6.36.tar.gz (php5)
wget -c http://cn2.php.net/distributions/php-7.2.5.tar.gz (php7)
解压:
tar -xvf php-5.6.36.tar.gz
tar -xvf php-7.2.5.tar.gz
进入到解压后的目录里面去:
cd php-5.6.36
安装:
./configure --prefix=/usr/local/php56 --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php56/etc --with-mysql=/usr/local/mysql56 --with-pdo-mysql=/usr/local/mysql56 --with-mysqli=/usr/local/mysql56/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
若出现这些报错:
yum install bzip2-devel.x86_64 -y
yum install openssl-devel.x86_64 -y
yum install libxml2-devel.x86_64 -y
yum install libjpeg-turbo-devel.x86_64 libjpeg-turbo.x86_64 -y
yum install libpng-devel.x86_64 libpng.x86_64 libpng12.x86_64 libpng12-devel.x86_64 -y
yum install freetype-devel.x86_64 -y
yum install libmcrypt.x86_64 libmcrypt-devel.x86_64 -y
make && make install 编译并安装。
查看PHP 所加载的模块:
/usr/local/php56/bin/php -m
查看apache 所加载的模块:
因为php做为apache的一个模块而调用的,所以,想看php启动成功没,就看apache是否有调用。
/usr/local/apache2.4/bin/apachectl -M
查看apache配制文件中是否有加载PHP模块:
cat /usr/local/apache2.4/conf/httpd.conf |grep -i PHP
复制源码包里的配制文件到/usr/local/php56/etc/ 目录里面去。
cp /home/nfyx/source/php-5.6.36/php.ini-production ./php.ini
到此php5模块,安装成功!
2、PHP7的安装:
下载:
wget -c http://cn2.php.net/distributions/php-7.2.5.tar.gz (php7)
解压:
tar -xvf php-7.2.5.tar.gz
进入目录:
cd php-7.2.5
安装配制:
./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/mysql56 --with-mysqli=/usr/local/mysql56/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
安装成功后:
查看相应加载的模块:
php7所加载的模块
/usr/local/php7/bin/php -m
apache所加载的模块:
(php做为apache的模块:所存放的路径:/usr/local/apache2.4/modules/)
/usr/local/apache2.4/bin/httpd -M
复制配制文件:
cp /home/nfyx/source/php-7.2.5/php.ini-production /usr/local/php7/etc/php.ini
apache 自己设置需要调用php5或php7:
修改:/usr/local/apache2.4/conf/httpd.conf文件 把不需要调用的给注释掉就可以了。
到此php5 或 php7 都安装完成。
如何 把apache 和 php 组合起来 ?
(关闭防火墙或在防火墙内添加80端口,关闭selinux)
修改:apache的配制文件:/usr/local/apache2.4/conf/httpd.conf
配制 server name:
配制访问权限:
重新读取配制文件:/usr/local/apache2.4/bin/apachectl graceful (即不重启服务的情况下,重新读取配制文件)
增加php应用解析模块:
AddType application/x-httpd-php .php
增加一个index.php 默认模块:
重启apache 或重新加载apache服务:
/usr/local/apache2.4/bin/apachectl restart 或 /usr/local/apache2.4/bin/apachectl graceful
然后写一个写一测试页:
echo "<?php phpinfo(); ?>" > /usr/local/apache2.4/htdocs/index.php
访问:
换一个PHP版本:
vim /usr/local/apache2.4/conf/httpd.conf
重启apache ,然后,再访问页面:
这样子apache和php的整合,就成功了!