bash 使用 Shell 脚本自动安装 LAMP 堆栈

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29669320/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 12:48:45  来源:igfitidea点击:

Automated Installation of LAMP Stack Using Shell Script

bashshellinstallationlamp

提问by Pratik Patil

How to automate the installation of LAMP Stack? As we have to install several packages one by one and then configure them. Again we have to separately install some GUI tool like phpMyAdmin or MySQL-Workbench to access MySQL databases. Is it possible to make this full installation completely automated? Using shell script or something else?

如何自动安装 LAMP Stack?因为我们必须一个一个安装几个包然后配置它们。同样,我们必须单独安装一些 GUI 工具,如 phpMyAdmin 或 MySQL-Workbench 来访问 MySQL 数据库。是否有可能使这个完全安装完全自动化?使用shell脚本还是其他什么?

Thanks..

谢谢..

回答by Pratik Patil

I have prepared the following shell script to make this installation fully automated.

我准备了以下 shell 脚本来使此安装完全自动化。

#!/bin/bash
# ******************************************
# Program: LAMP Stack Installation Script
# Developer: Pratik Patil
# Date: 10-04-2015
# Last Updated: 11-01-2016
# ******************************************

if [ "`lsb_release -is`" == "Ubuntu" ] || [ "`lsb_release -is`" == "Debian" ]
then
    sudo apt-get -y install mysql-server mysql-client mysql-workbench libmysqld-dev;
    sudo apt-get -y install apache2 php5 libapache2-mod-php5 php5-mcrypt phpmyadmin;
    sudo chmod 755 -R /var/www/;
    sudo printf "<?php\nphpinfo();\n?>" > /var/www/html/info.php;
    sudo service apache2 restart;

elif [ "`lsb_release -is`" == "CentOS" ] || [ "`lsb_release -is`" == "RedHat" ]
then
    sudo yum -y install httpd mysql-server mysql-devel php php-mysql php-fpm;
    sudo yum -y install epel-release phpmyadmin rpm-build redhat-rpm-config;
    sudo yum -y install mysql-community-release-el7-5.noarch.rpm proj;
    sudo yum -y install tinyxml libzip mysql-workbench-community;
    sudo chmod 777 -R /var/www/;
    sudo printf "<?php\nphpinfo();\n?>" > /var/www/html/info.php;
    sudo service mysqld restart;
    sudo service httpd restart;
    sudo chkconfig httpd on;
    sudo chkconfig mysqld on;

else
    echo "Unsupported Operating System";
fi

Open Following URL in browser to verify the installation of Apache Server:

在浏览器中打开以下 URL 以验证 Apache Server 的安装:

http://localhost

Open Following URL in browser to verify the installation of PHP:

在浏览器中打开以下 URL 以验证 PHP 的安装:

http://localhost/info.php

回答by David C. Rankin

This process is distribution/package manager dependent, but yes, it is entirely possible. You can even enable ssl/httpscapability and generate your server keys, certificate, and signing request key all with a single keystroke. You break it down into tasks and add script capability for each. Key generation will require ssh-keygen. I have older versions of similar scripts for both openSuSE and Archlinux. If you get stuck, I'm happy to take a look and share the approach I took years ago.

这个过程依赖于分发/包管理器,但是是的,这是完全可能的。您甚至可以ssl/https通过一次按键启用功能并生成服务器密钥、证书和签名请求密钥。您将其分解为任务并为每个任务添加脚本功能。密钥生成将需要ssh-keygen. 我有用于 openSuSE 和 Archlinux 的类似脚本的旧版本。如果您遇到困难,我很乐意查看并分享我多年前采用的方法。

In your script above, I would limit the permissions on /var/wwwto 0755, no need to give worldwrite to those directories -- ever. Additionally, instead of an extended if .. elif ... elif ... fisetup for identifying the distribution, A case statement can help you organize a bit more:

在上面的脚本中,我会将权限限制/var/www0755,无需world写入这些目录 - 永远。此外,与if .. elif ... elif ... fi用于识别分布的扩展设置不同,case 语句可以帮助您组织更多内容:

case "lsb_release" in 

    Ubuntu  )
        ... ;;
    Debian  )
        ... ;;
    Centos  )
        ... ;;
esac