1

The following script is the one I use on Ubuntu-Nginx environments, to get a WordPress webapp up and running.

I run it with a domain as an argument:

bash ~/nwsm.sh example.com

My question is what could be shorten in that script, maybe via some WP-CLI automation, or other automation tool, to get the shortest script possible.

As for now it's 35 lines of code, I assume it could go down to <=30 lines?

#!/bin/sh

domain="$1"
read -sp "What's your DB root password?" dbrootp
read -sp "What's your DB user password?" dbuserp
cd ${drt}

cat <<-WEBAPPBASE > /etc/nginx/sites-available/${domain}.conf
    server {
        root ${drt}/${domain}; 
        server_name ${domain} www.${domain};
        location ~* \.(jpg|jpeg|png|gif|ico|css|js|ttf|woff|pdf)$ {expires 365d;}
    }
WEBAPPBASE
ln -s /etc/nginx/sites-available/${domain}.conf /etc/nginx/sites-enabled/
certbot --nginx -d ${domain} -d www.${domain} # HTTP/2

cat <<-DBSTACK | mysql -u root -p"${dbrootp}"
    CREATE USER "${domain}"@"localhost" IDENTIFIED BY "${dbuserp}";
    CREATE DATABASE "${domain}";
    GRANT ALL PRIVILEGES ON ${domain}.* TO "${domain}"@"localhost";
DBSTACK

mkdir ${domain} && curl -L http://wordpress.org/latest.tar.gz | tar -zx -C ${domain}/
cp ${domain}/wp-config-sample.php ${domain}/wp-config.php
sed -ir "s/username_here|database_name_here/${domain}/g ; s/password_here/${dbuserp}/g" ${domain}"/ ${domain}/wp-config.php

chown -R www-data:www-data ${domain}/*
chmod -R a-x,a=rX,u+w ${domain}/*
systemctl restart nginx.service

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.