Skip to content

Instantly share code, notes, and snippets.

@mengstr
Last active March 15, 2021 11:13
Show Gist options
  • Save mengstr/b2338e76ffeda92f85ec379db13b9030 to your computer and use it in GitHub Desktop.
Save mengstr/b2338e76ffeda92f85ec379db13b9030 to your computer and use it in GitHub Desktop.
Setup a Azure Ubuntu 18.04 for LAMP development
#
# Setup of LAMP on virgin Azure Ubuntu 18.04
# Run this as root
#
# Version 2021-03-15a
#
SITE=$1
EMAIL=$2
if [[ -z "$SITE" ]] || [[ -z "$EMAIL" ]]; then
echo "Usage: source setupLAMP.sh <domain> <email>"
return 1 2> /dev/null || exit 1
fi
apt-get -y update
apt -y install software-properties-common
add-apt-repository -y ppa:ondrej/php
apt-get -y update
apt-get -y upgrade
apt-get install -y links joe curl wget unzip
apt-get install -y nginx php7.4-fpm
apt-get install -y php7.4-{dom,curl,bcmath,bz2,intl,gd,mbstring,mysqli,zip,fpm}
apt-get install -y mariadb-server
apt -y autoremove
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php --install-dir=/usr/local/bin --filename=composer
snap install core;
snap refresh core
snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
rm -f /etc/nginx/sites-enabled/default /etc/nginx/sites-available/default
cat << EOF > /etc/nginx/sites-available/$SITE
server {
server_name $SITE;
listen 443 ssl;
root /var/www/html/$SITE;
index index.php index.html index.htm;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location ~ /\.ht {
deny all;
}
#FIX ssl_certificate /etc/letsencrypt/live/$SITE/fullchain.pem;
#FIX ssl_certificate_key /etc/letsencrypt/live/$SITE/privkey.pem;
#FIX include /etc/letsencrypt/options-ssl-nginx.conf;
#FIX ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}
server {
server_name $SITE;
listen 80;
return 301 https://\$host\$request_uri;
}
EOF
ln -s /etc/nginx/sites-available/$SITE /etc/nginx/sites-enabled/$SITE
mkdir /var/www/html/$SITE
echo '<?php phpinfo(); ?>' > /var/www/html/$SITE/index.php
systemctl reload nginx
certbot certonly -n --nginx --agree-tos -m $EMAIL -d $SITE
sed -i s/#FIX//g /etc/nginx/sites-available/$SITE
systemctl reload nginx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment