一键安装php5.6.40脚本(LAMP环境)

#!/bin/bash

#安装依赖软件
yum -y install libxml2-devel curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel net-snmp net-snmp-devel

#安装libiconv-1.14(下面使用sed增加2行,不增加会报错,详细查看www.cnblogs.com/blog-tim/p/10537708.html)
cd /usr/local/src/
wget -c http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar -xf libiconv-1.14.tar.gz 
sed -i '697a #if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16)' /usr/local/src/libiconv-1.14/srclib/stdio.in.h
sed -i '699a #endif' /usr/local/src/libiconv-1.14/srclib/stdio.in.h
cd libiconv-1.14
./configure --prefix=/usr/local/php/libiconv && make && make install

#安装libmcrypt-2.5.8
cd /usr/local/src/
wget -c http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
tar -xf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure && make && make install
/sbin/ldconfig && cd libltdl/
./configure --enable-ltdl-install && make && make install

#安装mhash-0.9.9.9
cd /usr/local/src/
wget -c http://nchc.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz
tar -xf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure && make && make install

#安装mcrypt-2.6.8
cd /usr/local/src/
wget -c http://nchc.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz
tar -xf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
/sbin/ldconfig && export LD_LIBRARY_PATH=/usr/local/lib: LD_LIBRARY_PATH
./configure && make && make install

#编译安装php-5.6.40
cd /usr/local/src/
wget -c http://jp2.php.net/distributions/php-5.6.40.tar.gz
tar -xf php-5.6.40.tar.gz
cd php-5.6.40
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-iconv=/usr/local/php/libiconv --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gd --with-jpeg-dir --with-png-dir --with-pear --with-freetype-dir --with-zlib --with-libxml-dir --with-iconv-dir --with-xmlrpc --with-mhash --with-mcrypt --with-curl --with-openssl --with-snmp --with-gettext --enable-pdo --enable-mbstring --enable-ctype --enable-simplexml --enable-ftp --enable-sockets --enable-gd-native-ttf --enable-sysvsem --enable-exif --enable-sysvshm --enable-xml --enable-dom --enable-simplexml --enable-shmop --enable-zip --enable-mbregex --enable-bcmath --enable-inline-optimization --enable-soap
make && make install

#配置php和环境变量,关闭httpd服务
cp /usr/local/src/php-5.6.40/php.ini-production /usr/local/php/etc/php.ini
echo "export PATH=/usr/local/php/bin:$PATH" >>/etc/profile
source /etc/profile
killall -9 httpd

#配置php首页,然后重新启动httpd服务
rm -f /var/www/html/index.html
cat > /var/www/html/index.php << EOF

EOF
/usr/local/apache/bin/apachectl start

安装完成后需检查apache主配置文件httpd.conf 中是否有增加 libphp5.so 模块内容

LoadModule php5_module        modules/libphp5.so           #<===编译安装PHP完成后会自动在apache主配置文件httpd.conf中产生此行

测试php5.6.40链接MySQL5.6.43是否成功,新建test.php文件到站点目录下,添加以下内容测试

[root@lamp html]# cat test.php
connect_error) {
die("Connection failed: " . mysqli_connect_error());
}else{
echo "this is connected";
}
?>

打开浏览器测试链接成功

一键安装php5.6.40脚本(LAMP环境)_第1张图片

注意:此脚本适用于LAMP环境,php在apache中以模块形式插入调用,而LNMP中php是进程方式运行!

 

转载于:https://www.cnblogs.com/blog-tim/p/10538573.html

你可能感兴趣的:(一键安装php5.6.40脚本(LAMP环境))