Last active
January 23, 2020 21:24
-
-
Save jeremybradbury/fa1b6b5e60c92168d40af0d8e9bb4885 to your computer and use it in GitHub Desktop.
LANMMNP (Linux Apache Nginx MySQL MongoDB Nodejs12 PHP7 ) Stack provisioning script, designed for Amazon EC2 Ubuntu 16.04 instances
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo "https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-16-04" | |
echo -n "Skip nginx (y/N)? " | |
read inginx | |
if [ "$inginx" != "${inginx#[Yy]}" ] ;then | |
echo "nginx skipped" | |
else | |
echo "installing nginx" | |
sudo apt-get update | |
sudo apt-get install nginx | |
echo "press q to quit less" | |
systemctl status nginx | |
sudo apt-get install curl | |
curl -4 icanhazip.com | |
fi | |
echo "install node 12 LTS" | |
echo "https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-16-04" | |
echo -n "Skip node (y/N)? " | |
read inode | |
if [ "$inode" != "${inode#[Yy]}" ] ;then | |
echo "node skipped" | |
else | |
echo "installing node" | |
cd ~ | |
curl -sL https://deb.nodesource.com/setup_12.x -o nodesource_setup.sh | |
#nano nodesource_setup.sh | |
sudo bash nodesource_setup.sh | |
sudo apt-get install nodejs | |
node -v | |
fi | |
echo "install LAMP Stack" | |
echo "https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-16-04" | |
sudo apt-get update | |
echo -n "Skip apache (y/N)? " | |
read iapache | |
if [ "$iapache" != "${iapache#[Yy]}" ] ;then | |
echo "apache skipped" | |
else | |
echo "installing apache" | |
sudo apt-get install curl | |
curl -4 icanhazip.com # show external IP | |
sudo apt-get install apache2 | |
sudo apache2ctl configtest | |
sudo nano /etc/apache2/ports.conf # change port to internal port 4444 to forward with nginx | |
sudo systemctl restart apache2 | |
sudo apache2ctl configtest | |
fi | |
echo -n "Skip mysql (y/N)? " | |
read imysql | |
if [ "$imysql" != "${imysql#[Yy]}" ] ;then | |
echo "mysql skipped" | |
else | |
echo "installing mysql" | |
sudo apt-get install mysql-server # 7a937137598d21b8856204d066a3 | |
mysql_secure_installation | |
fi | |
echo -n "Skip php7 (y/N)? " | |
read iphp | |
if [ "$iphp" != "${imysql#[Yy]}" ] ;then | |
echo "php7 skipped" | |
else | |
echo "installing php7" | |
sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql | |
sudo nano /etc/apache2/mods-enabled/dir.conf # check index.php before index.html | |
sudo systemctl restart apache2 | |
sudo systemctl status apache2 | |
#apt-cache search php- | less | |
sudo apt-get install php7.0-curl php7.0-sqlite3 php7.0-gd | |
sudo echo "<? phpphpinfo(); ?>" > /var/www/html/info.php # | |
echo "verify install and remove '/var/www/html/info.php'" | |
fi | |
echo -n "Remove '/var/www/html/info.php' (Y/n)? " | |
read rphp | |
if [ "$rphp" != "${rphp#[Nn]}" ] ;then | |
echo "WARNING: info.php may be publicly accessable." | |
else | |
sudo rm /var/www/html/info.php | |
echo "SUCCESS: removed info.php file" | |
fi | |
echo "https://www.digitalocean.com/community/tutorials/how-to-install-jenkins-on-ubuntu-16-04" | |
echo -n "Skip jenkins (y/N)? " | |
read ijenkins | |
if [ "$ijenkins" != "${ijenkins#[Yy]}" ] ;then | |
echo "jenkins skipped" | |
else | |
echo "installing jenkins" | |
sudo apt-get install default-jre | |
wget -q -O - https://pkg.jenkins.io/debian/jenkins-ci.org.key | sudo apt-key add - | |
echo deb https://pkg.jenkins.io/debian-stable binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list | |
sudo apt-get update | |
sudo apt-get install jenkins | |
sudo systemctl start jenkins | |
echo "press q to quit less" | |
sudo systemctl status jenkins | |
echo "Unlock Jenkins code below" | |
sudo cat /var/lib/jenkins/secrets/initialAdminPassword | |
fi | |
echo "Enter your base domain: example.com" | |
echo -n "configures nginx reverse proxy, leave blank to skip: " | |
read mydomain | |
if [ "$mydomain" != "" ] ;then | |
echo "reverse proxy config skipped" | |
else | |
echo "nginx reverse proxy & load balancing config" | |
cd /etc/nginx/sites-available | |
## jenkins = ci.domain.tld -> 8080 | |
echo -e "upstream jenkins { server localhost:8080; }\n\n\tserver {\n\t\tlisten 80;\n\t\tserver_name ci.$mydomain.com;\n\tlocation / {\n\t\tproxy_pass http://jenkins;\n\t}\n}" > jenkins | |
## node = www.domain.tld -> 3001, 3002, 3003 [load balanced] | |
echo -e "upstream nb3 { server localhost:3001;\n\tserver localhost:3002;\n\tserver localhost:3003;\n }\n\n\tserver {\n\t\tlisten 80;\n\t\tserver_name www.$mydomain.com;\n\tlocation / {\n\t\tproxy_pass http://nb3;\n\t}\n}" > node | |
## wordpress = www.domain.tld -> 4444 | |
echo -e "upstream apache { server localhost:4444; }\n\n\tserver {\n\t\tlisten 80;\n\t\tserver_name $mydomain.com;\n\tlocation / {\n\t\tproxy_pass http://apache;\n\t}\n}" > apache | |
cd /etc/nginx/sites-enabled | |
ln -sfv /etc/nginx/sites-available/jenkins jenkins | |
ln -sfv /etc/nginx/sites-available/apache apache | |
ln -sfv /etc/nginx/sites-available/node node | |
sudo systemctl restart nginx | |
fi | |
# TODO: MongoDB server | |
# TODO: echo -n "Skip SSL (y/N)? " | |
# https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-16-04 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment