Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Create a NGINX file, index.php and mysql DB for $DOMAIN passed in first argument e.g
- # sudo bash create.sh domain.co.uk
- # needs /root/.my.conf set up with [client] root user and password to create DB
- # needs certbot installed to do certbot
- DOMAIN=$1
- cp /etc/nginx/sites-available/basic /etc/nginx/sites-available/${DOMAIN}
- sed -i "s/:domain/${DOMAIN}/g" /etc/nginx/sites-available/${DOMAIN}
- ln -s /etc/nginx/sites-available/${DOMAIN} /etc/nginx/sites-enabled/${DOMAIN}
- printf "created /etc/nginx/sites-available/${DOMAIN}"
- mkdir -p /var/www/${DOMAIN}/public
- printf "public folder here /var/www/${DOMAIN}/public"
- printf "<?php echo 'Domain ${DOMAIN} waiting for your magic'; ?>" > /var/www/${DOMAIN}/public/index.php
- chown -R www-data:www-data /var/www/${DOMAIN}
- PASSWDDB="$(openssl rand -base64 12)"
- mysql --defaults-extra-file=/root/.my.conf -e "CREATE DATABASE ${DOMAIN//[^a-zA-Z_-]/_} /*\!40100 DEFAULT CHARACTER SET utf8 */;"
- mysql --defaults-extra-file=/root/.my.conf -e "CREATE USER ${DOMAIN//[^a-zA-Z_-]/_}@localhost IDENTIFIED BY '${PASSWDDB}';"
- mysql --defaults-extra-file=/root/.my.conf -e "GRANT ALL PRIVILEGES ON ${DOMAIN//[^a-zA-Z_-]/_}.* TO '${DOMAIN//[^a-zA-Z_-]/_}'@'localhost';"
- mysql --defaults-extra-file=/root/.my.conf -e "FLUSH PRIVILEGES;"
- printf "Database: ${DOMAIN//[^a-zA-Z_-]/_}\nUsername:${DOMAIN//[^a-zA-Z_-]/_}\nPassword:${PASSWDDB}" > /var/www/${DOMAIN}/config
- printf "Database config here: /var/www/${DOMAIN}/config"
- sudo systemctl reload nginx
- sudo systemctl restart nginx
- certbot -n --redirect --nginx -d ${DOMAIN} -d www.${DOMAIN}
Add Comment
Please, Sign In to add comment