由于脚本需要从网站上下载数据包来本地安装这样有时候URL链接地址失效就会导致脚本不能用,于是我就在本地搭建了HTTP服务来提供下载的方式安装LAMP脚本。
具体方法是:
1,先在一台主机上搭建一个http服务器。
2,然后在/usr/local/apache2/htdocs新建一个download文件夹。
3,接着把所需要的下载的软件放到/usr/local/apache2/htdocs/download文件夹下即可。
4,这样的话就可以正常使用内网的地址来跑脚本了。
![357a09a470f8eaa3b652a8a68c325bc3.png](https://i-blog.csdnimg.cn/blog_migrate/242f90d0496f8a15f06e260cd2bc0e3f.jpeg)
LAMP
脚本参考如下
#!/bin/bash#auto install LAMP#by tony 2019-08-2#Httpd define path variable#APR Install####安装apr############################A_FILES=apr-1.5.2.tar.gzA_FILES_DIR=apr-1.5.2A_URL=http://10.93.58.209/download/apr-1.5.2.tar.gzA_PREFIX=/application/apr#APR-Util Install####安装apr –util#####################AU_FILES=apr-util-1.5.4.tar.gzAU_FILES_DIR=apr-util-1.5.4AU_URL=http://10.93.58.209/download/apr-util-1.5.4.tar.gzAU_PREFIX=/application/apr-util#PCRE Install####安装pcre###########################PC_FILES=pcre-8.38.tar.gzPC_FILES_DIR=pcre-8.38PC_URL=http://10.93.58.209/download/pcre-8.38.tar.gzPC_PREFIX=/application/pcre#Apache Install####安装apache########################H_FILES=httpd-2.4.18.tar.gzH_FILES_DIR=httpd-2.4.18H_URL=http://10.93.58.209/download/httpd-2.4.18.tar.gzH_PREFIX=/application/apache2/#Mysql define path variable ####定义mysql的安装路径#####M_FILES=mysql-5.5.32.tar.gzM_FILES_DIR=mysql-5.5.32M_URL=http://10.93.58.209/download/mysql-5.5.32.tar.gzM_PREFIX=/application/mysql/#PHP define path variable######定义php的安装路径#########P_FILES=php-5.6.20.tar.gzP_FILES_DIR=php-5.6.20P_URL=http://10.93.58.209/download/php-5.6.20.tar.gzP_PREFIX=/application/php5/echo -e "033[34m-------------------------033[0m"echo -e "033[35mReady to set up LAMP source environmentWait for 5 seconds, please select menu033[0m"sleep 5if [ -z "$1" ];then echo -e "033[36mPlease Select install menu follow:033[0m" echo -e "033[32m 1)编译安装Apache服务器033[1m" echo "2)编译安装Mysql服务器" echo "3)编译安装PHP服务器" echo "4)配置index.php并启动LAMP服务" echo -e "033[31mUsage: { /bin/sh $0 1|2|3|4|help}033[0m" exitfiif [[ "$1" -eq "help" ]];then echo -e "033[36mPlease Select Install Menu follow:033[0m" echo -e "033[32m1)编译安装Apache服务器033[1m" echo "2)编译安装MySQL服务器" echo "3)编译安装PHP服务器" echo "4)配置index.php并启动LAMP服务" echo -e "033[31mUsage: { /bin/sh $0 1|2|3|4|help}033[0m" exitfi###################################Install httpd web server 安装httpd服务####if [[ "$1" -eq "1" ]];then yum -y install gcc gcc-c++ wget -c $A_URL && tar zxvf $A_FILES && cd $A_FILES_DIR && ./configure --prefix=$A_PREFIX if [ $? -eq 0 ];then make && make install echo -e "033[32m The $A_FILES_DIR install OK!033[0m" else echo -e "033[32m the $A_FILES_DIR install error,please check...033[0m" exit 0 fi wget -c $AU_URL && tar zxvf $AU_FILES && cd $AU_FILES_DIR && ./configure --prefix=$AU_PREFIX --with-apr=$A_PREFIX if [ $? -eq 0 ];then make && make install echo -e "033[32m The $AU_FILES_DIR install OK!033[0m" else echo -e "033[32m the $AU_FILES_DIR install error,please check...033[0m" exit 0 fi wget -c $PC_URL && tar zxvf $PC_FILES && cd $PC_FILES_DIR && ./configure --prefix=$PC_PREFIX if [ $? -eq 0 ];then make && make install echo -e "033[32m The $PC_FILES_DIR install OK!033[0m" else echo -e "033[32m the $PC_FILES_DIR install error,please check...033[0m" exit 0 fiwget -c $H_URL && tar -zxvf $H_FILES && cd $H_FILES_DIR && ./configure --prefix=$H_PREFIX --with-apr=$A_PREFIX --with-apr-util=$AU_PREFIX --with-pcre=$PC_PREFIX --enable-so --enable-rewrite if [ $? -eq 0 ];then make && make install cp $H_PREFIX/bin/apachectl /etc/init.d/httpd echo "# chkconfig: 2345 50 90" >> /etc/init.d/httpd && chkconfig --add httpd && chkconfig --level 35 httpd on && /etc/init.d/httpd restart echo -e "033[32m----------------------------------033[0m" echo -e "033[32m The $H_FILES_DIR Server install Success ! 033[0m" else echo -e "033[32m The $H_FILES_DIR Make or Make install ERROP,please check....033[0m" exit 0 fifi#Install mysql DB server安装mysql服务####if [[ "$1" -eq "2" ]];then yum -y install make cmake gcc-c++ bison ncurses ncurses-devel libaio-devel groupadd mysql useradd mysql -s/sbin/nologin -M -g mysql wget -c $M_URL && tar -zxvf $M_FILES && cd $M_FILES_DIR && cmake ./ -DCMAKE_INSTALL_PREFIX=/application/mysql-5.5.32 -DMYSQL_DATADIR=/data/mysql -DMYSQL_UNIX_ADDR=/application/mysql-5.5.32/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii -DENABLED_LOCAL_INFILE=ON -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 -DWITHOUT_PARTITION_STORAGE_ENGINE=1 -DWITH_FAST_MUTEXES=1 -DWITH_ZLIB=bundled -DENABLED_LOCAL_INFILE=1 -DWITH_READLINE=1 -DWITH_EMBEDDED_SERVER=1 -DWITH_DEBUG=0if [ $? -eq 0 ];then make && make install ln -s /application/mysql-5.5.32 /application/mysql cp support-files/mysql.server /etc/init.d/mysqld chmod +x /etc/init.d/mysqld chown mysql.mysql /application/mysql chown mysql.mysql /data echo 'export PATH=/application/mysql/bin:$PATH '>>/etc/profile source /etc/profile mv /etc/my.cnf /etc/my.cnf.bak cat >/etc/my.cnf <>$H_PREFIX/conf/httpd.conf IP=`ifconfig eth0|grep "Bcast"|awk '{print $2}'|cut -d: -f2` echo "You can access http://$IP/"cat >$H_PREFIX/htdocs/index.php <EOFfi
![83cf2e28bb92f43865941671f574f584.png](https://i-blog.csdnimg.cn/blog_migrate/90cc26409c78813bac081fd72e35c09b.jpeg)
PHP
注意
1,脚本在centos6下面跑的最顺利,脚本的IP和路径需要更改一下。
2,使用sed -i "s/10.93.58.209/192.168.0.10/g" /root/lamp_install.sh来修改IP地址。
3,脚本运行完成启动mysql可能会提示找不到这个命令,需要 source /etc/profile一下。
4,如果数据库换成5.6的版本需要把这个参数改变- DWITHOUT_PARTITION_STORAGE_ENGINE=0
5,如果你不是root权限运行脚本请先给脚本chmod +x lamp_install.sh
6,你如果想试试又找不到软件的话你可以私信我,私信发我信息“LAMP”,我会把软件发给你,最后感谢您的观看,谢谢!