11.10-11.13 PHP5,PHP7安装
现在流行的php版本主要是php5.6和php7,php7的性能有较大提升,但是在生产环境中为了追求稳定,大家主要还是用php5.6。
php5.6安装
cd /usr/local/src/
wget http://cn2.php.net/distributions/php-5.6.30.tar.gz
tar zxf php-5.6.30.tar.gz
cd php-5.6.30
安装php的过程中会需要很多依赖,所以我们先安装依赖:
yum install -y libxml2-devel
yum install -y openssl openssl-devel
yum install -y bzip2 bzip2-devel
yum install -y libpng libpng-devel
yum install -y freetype freetype-devel
yum install -y epel-release
yum install -y libmcrypt-devel
以下报错需要如下依赖:
//collect2: ld returned 1 exit status
//make[2]: *** [htpasswd] խϳ 1
//make[2]: Leaving directory //`/usr/local/src/httpd-//2.4.26/support'
//make[1]: *** [all-recursive] խϳ 1
//make[1]: Leaving directory //`/usr/local/src/httpd-//2.4.26/support'
//make: *** [all-recursive] խϳ 1
解决办法:yum install libtools-ltdl-devel 并重新编译安装apr-util
./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
//apxs2是httpd的一个工具,只有他才能把php安装到apache的modules目录下。
echo$?
make
echo$?
make install
echo$?
cp php.ini-production /usr/local/php/etc/php.ini //复制配置文件
配置apache以支持php
进入到httpd的配置文件 /etc/local/apache2.4/conf/httpd.conf
vim /etc/local/apache2.4/conf/httpd.conf
让以下内容生效:
ServerName www.example.com:80
<Directory />
AllowOverride none
Require all granted
</Directory>
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
测试lamp是否配置成功
[root@cent01 mariadb]# /usr/local/apache2.4/bin/apachectl -t //检查配置文件是否有语法错误
Syntax OK
[root@cent01 mariadb]# /usr/local/apache2.4/bin/apachectl start //启动httpd服务
[root@cent01 mariadb]# netstat -lnp |grep httpd //查看httpd是否已启动
tcp6 0 0 :::80 :::* LISTEN 3634/httpd
[root@cent01 mariadb]# curl localhost //返回it works说明测试成功
It works!
//测试是否正确解析php
//首先编写测试脚本 vim /usr/local/apache2.4/htdocs/1.php
<?php
echo "php解析正常"
?>
curl localhost/1.php //返回php解析正常,说明测试成功
php解析正常
安装php7
因为前面已经安装了很多依赖,所以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
echo$?
make
echo$?
make install
echo$?
ls /usr/local/apache2.4/modules/libphp7.so
cp php.ini-production /usr/local/php7/etc/php.ini
//在使用php7之前需要先更改httpd的配置文件
vim /usr/local/apache2.4/conf/httpd.conf
搜索php7,找到有loadmodule的那一行,删掉前面的#,然后把php5的那一行加上#。
[root@cent01 mariadb]# /usr/local/apache2.4/bin/apachectl -t //检查配置文件是否有语法错误
[root@cent01 mariadb]# /usr/local/apache2.4/bin/apachectl graceful //重新加载配置文件