Create a WordPress site data with Nginx app data automatically The following script is aimed for Ubuntu &gt;=16.04 LEMP environments with PHP-FPM &gt;=7.0, MySQL, WP-CLI, Certbot, and WordPress apps.

The script get's one domain as an argument and creates the following aspects based on that argument (drt=document-root):


WP_app directory in drt.
WP_installation in drt/domain.
WP_conf in drt/domain.
NX_app conf in /etc/nginx/sites-available/
NX_symlink in /etc/nginx/sites-enabled/
NX_certbot configuration.


${drt} = document root.



One could then add a database stack via MySQL, accordingly (and also edit the website files, accordingly).

#!/bin/bash
domain="$1" &amp;&amp; test -z ${domain} &amp;&amp; return
read -sp "DB user password:" dbuserp

wp core download --path=${drt}/${domain}/ --allow-root # REDUNDANTS MKDIR
wp config create --path=${drt}/${domain}/ --dbname=${domain} --dbuser=${domain} --dbpass=${dbuserp} --dbhost="localhost" --allow-root

cat ~/myAddons/nginx_app &gt; ${sava}/${domain}.conf
sed -i "s/\${domain}/${1}/g" /${sava}/${domain}.conf

ln -sf ${sava}/${domain}.conf ${sena}
certbot --nginx -d ${domain} -d www.${domain}

chown -R www-data:www-data ${drt}/
chmod -R a-x,a=rX,u+w ${drt}/
/etc/init.d/php*-fpm restart &amp;&amp; systemctl restart nginx.service

echo "Please configure DBstack in phpmyadmin."
echo "Please change permissions as you prefer and restart the Nginx server."


Clarification

The conf template I redirect from ~/nginx_app, for the Nginx app conf, is this one:

server {
    root ${drt}/${domain}/;
    server_name ${domain} www.${domain};
    location ~* \.(jpg|jpeg|png|gif|ico|css|js|ttf|woff|pdf)$ { expires 365d; }
}




Please share your opinion on the above script and adjacent conf file.
Shellcheck.net

I strongly recommend to start using https://shellcheck.net/.
Simply copy-paste your script,
and it will tell you many issues with this code.

Don't use return outside of functions

The return statement only works within functions.
You probably meant exit instead:

domain="$1" &amp;&amp; test -z "${domain}" &amp;&amp; exit


Variables in command arguments

Always double-quote variables in command arguments to prevent glob expansion and word splitting, for example:

cat ~/myAddons/nginx_app &gt; "${sava}/${domain}.conf"


Inconsistent paths

Here, the last argument of the second command starts with a /, but not the last argument of the first command:

cat ~/myAddons/nginx_app &gt; ${sava}/${domain}.conf
sed -i "s/\${domain}/${1}/g" /${sava}/${domain}.conf


I suspect the last arguments are intended to be the same in both of these commands. This is confusing.