The following maker creates a webapp substrate for webapps/websites on Debian environments (I use Ubuntu).
The substrate includes, based on your domain given as an argument:
/etc/nginx/sites-available/example.com.conf
.etc/nginx/sites-enabled/
symlink.- Appropriate DB user and instance, named example.com.
- Suitable
wp-config.php
file. - Finishes.
I’d especially like to know how I could shorten this code, if at all.
The maker
cat <<-"NWSM" > /opt/nwsm.sh #!/bin/sh for domain; do cat <<-WEBAPPCONF > "/etc/nginx/sites-available/$ {domain}.conf" server { root /var/www/html/$ {domain}; server_name $ {domain} www.$ {domain}; location ~* \.(jpg|jpeg|png|gif|ico|css|js|ttf|woff|pdf)$ { expires 365d; } location / { index index.php index.html index.htm fastcgi_index; try_files $ uri $ uri =404 $ uri/ /index.php?$ args; } location ~ \.php$ { fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; fastcgi_param SCRIPT_FILENAME $ document_root$ fastcgi_script_name; include fastcgi_params; } } WEBAPPCONF ln -s /etc/nginx/sites-available/$ {domain}.conf /etc/nginx/sites-enabled/ echo "Please enter database user password for user $ {domain}: " read -s waps echo "Please enter database root password" mysql -u root -p <<-MYSQL create user "$ {domain}"@"localhost" identified by "$ {waps}"; create database $ {domain}; GRANT ALL PRIVILEGES ON $ {domain}.* TO $ {domain}@localhost; MYSQL certbot --nginx -d $ {domain} -d www.$ {domain} done cd /var/www/html/ wget http://wordpress.org/latest.tar.gz tar xzvf latest.tar.gz && rm latest.tar.gz mv wordpress $ {domain} cp /var/www/html/$ {domain}/wp-config-sample.php /var/www/html/$ {domain}/wp-config.php echo "1/1: Please enter the password of the site's DB user." && read -s dbup sed -i "s/database_name_here/$ {domain}"/g /var/www/html/$ {domain}/wp-config.php sed -i "s/username_here/$ {domain}"/g /var/www/html/$ {domain}/wp-config.php sed -i "s/password_here/$ {dbup}"/g /var/www/html/$ {domain}/wp-config.php chown www-data:www-data /var/www/html/* -R find /var/www/html/* -type d -exec chmod 755 {} \; find /var/www/html/* -type f -exec chmod 644 {} \; systemctl restart nginx.service NWSM chmod +x /opt/nwsm.sh