开发php环境搭建脚本一键部署php服务环境


#!/bin/bash

Soft_Dir=/soft
Mysql_Install_Dir=/usr/local/mysql
Php_Version=5.5.43
Apache_Version=2.2.29
Apache_Install_Dir=/application/apache$Apache_Version
Apache_Apxs2_Path=/application/apache/bin/apxs
Php_Install_Dir=/application/php$Php_Version

#Source function library
. /etc/init.d/functions

echo "------------step1:check if apache and mysql installed------------"
[ ! -d $Mysql_Install_Dir ] && "please check mysql."&& exit 1
[ ! -e $Apache_Apxs2_Path ] && "please check php." && exit 1

echo "------------step2:check if php related soft installed------------"
rpm -qa zlib-devel libxml2-devel libjpeg-turbo-devel freetype-devel libpng-devel libxslt-devel
yum install -y yum install zlib libxml libjpg freetype libpng gd curl libiconv zlib-devel libxml2-devel libjpg-devel freetype-devel libpng-devel gd-devel curl-devel libxslt-devel perl
sleep 2

echo "------------step3:install libiconv------------"
cd /soft
[ ! -f libiconv-1.14.tar.gz ] && \
wget http://down.teddylu.info/libiconv-1.14.tar.gz
tar zxf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
make &&make install

echo "------------step4:install mhash and mcrypt------------"
cd /soft
wget http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
tar zxf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
./configure
make &&make install

cd /soft
wget http://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz
tar zxf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure
make &&make install


echo "------------step5:dowload and install php------------"
cd /soft
[ ! -f php-5.4.43.tar.gz ]&& \
wget http://mirrors.sohu.com/php/php-5.4.43.tar.gz
tar zxf php-5.4.43.tar.gz
cd php-5.4.43

./configure \
--prefix=/application/php$Php_Version \
--with-apxs2=/application/apache/bin/apxs \
--with-mysql=/usr/local/mysql \
--with-xmlrpc \
--with-openssl \
--with-zlib \
--with-freetype-dir \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-iconv-dir=/usr/local/libiconv \
--enable-sockets \
--enable-zend-multibyte \
--enable-soap \
--enable-mbstring \
--enable-static \
--enable-gd-native-ttf \
--with-curl \
--with-xsl \
--enable-ftp \
--with-mhash \
--with-mcrypt \
--with-mysqli \
--with-libxml-dir

make &&make install

ln -s ${Php_Install_Dir} /application/php

echo "------------step6:setup php.ini------------"
/bin/cp php.ini-production ${Php_Install_Dir}/lib/php.ini

# disable some php functions for security
sed -i 's/allow_url_fopen = On/allow_url_fopen=Off/g' ${Php_Install_Dir}/lib/php.ini
sed -i 's/expose_php = On/expose_php = Off/g' ${Php_Install_Dir}/lib/php.ini
sed -i 's/disable_functions =/disable_functions =system,passthru,exec,shell_exec,popen,phpinfo, chdir,chroot,dir,getcwd,opendir,readdir,scandir,fopen,unlink,delete/g' ${Php_Install_Dir}/lib/php.ini

echo "------------step7:setup apache supports php------------"
sed -i '/AddType application\/x-gzip \.gz \.tgz/ a AddType application/x-httpd-php  .php  .php3' /application/apache/conf/httpd.conf
sed -i '/AddType application\/x-gzip \.gz \.tgz/ a AddType application/x-httpd-php-source .phps' /application/apache/conf/httpd.conf
sed -i 's/DirectoryIndex index.html/DirectoryIndex index.php index.html/' /application/apache/conf/httpd.conf

#restart apache
service httpd restart

action “php is isntalled!!!” /bin/true

此条目发表在Shell分类目录,贴了标签。将固定链接加入收藏夹。