admin管理员组文章数量:1323716
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
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 .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
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
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/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
Share
Improve this question
edited Sep 11, 2020 at 23:37
Jesse Nickles
7357 silver badges19 bronze badges
asked Jan 17, 2018 at 23:42
ArcticoolingArcticooling
1
1 Answer
Reset to default 1Having the "shortest" script is a fairly pointless goal here I think, besides for entertainment purposes. But if you are looking for something that is very minimal and easy to understand, you can check out Bash scripts like my own free SlickStack project on GitHub, which is geared toward LEMP stack newbies.
Keep mind that if you integrate something like WP-CLI, it might appear to be "shorter" commands, but the backend is a rather complicated system of scripts and aliases. And by the time you've installed WP-CLI and ran through all the necessary commands, it might not save much time...
You also seem to skip over PHP-FPM and MySQL installation which WordPress requires, not to mention other common things like MU (Must-Use) plugins and drop-in plugins e.g. object-cache.php
which is pretty mainstream these days, also wp-config.php
configuration, and so forth.
I spent years putting SlickStack together, employing an extremely user-friendly and minimal approach, and yet it still ended up containing several different Bash scripts... ultimately, anytime you are getting into server management and DevOps tools, it is probably going to require more than 30 lines of code! In the case of SlickStack, the ss-config
file is where you can modify all your stack variables and options, before installation, meaning that you don't have to edit any of the actual Bash scripts.
You can also search public Gists on GitHub, which tend to be smaller in size than repos.
本文标签: installationShortest possible shell script to install WordPress on Nginx server
版权声明:本文标题:installation - Shortest possible shell script to install WordPress on Nginx server? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742124656a2421881.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论