I develop sites locally, then migrate the changes to the staging site or to the live site. I never make changes without testing them in my local server. I already have a repo to bootstrap a live server with Nginx, MySQL, PHP and a few more other goodies. However, there are lot of areas to improve to speed-up the development of local sites. For example, PhpMyAdmin runs on its own domain named https://pma.dev
(it doesn’t exist on the internet, just a local domain). Since, I do not expose my local server to the internet, I wouldn’t want to enter the credentials whenever I type it in my browser. It saves time! So, here’s my next project… local LEMP server.
Note: This works only on Linux servers and desktops (such as Juno from Elementary OS). Particularly tested on Ubuntu 18.04 based distros. There are a number of alternatives available if you wish you to develop sites locally on a mac or on a Windows PC. Since, I host most of the sites on the latest LTS version of Ubuntu, it make sense to closely resemble the live environment.
Bootstrapping WP Sites
It’s important to have the feature to quickly spin-up WordPress sites without having to manually download WP core files, create MySQL database credentials, create wp-config.php
file, install WordPress (with a pre-defined username and password; remember you’re developing locally, so, it’s okay to use the same username / password for multiple local sites). A few more things could be done too, such as, automatic update of WordPress core, plugins and themes. You may pre-install your favorite plugins. The demo content can be imported automatically too. There is a lot to automate. Only your imagination is the limitation here.
Running your own SSL CA
When you own your own SSL Certificate Authority, it is easy to spin up an SSL certificate for any domain (even non-existing domain such as pma.dev
mentioned earlier). Most importantly, it is easy to automate it locally. I’ll probably write a post on how to run your own SSL certificate authority on your own in your local network of servers and sites.
Deleting and re-creating sites
The most important feature that I’d like to have in any local box is the ability to quickly remove and re-create the sites so that I can start from scratch. Or the ability to quickly reset all the existing data. Kind of reset switch. While wp-cli has the ability to quickly reset the database, we may still need to go through the installation process, setting up permalinks, timezone, etc. Wouldn’t be a time-saver, if you have all these features? Well, it is easy again with wp-cli. We just need to run a series of wp-cli commands like mentioned below…
function reset_wp {
# required variables: $wp_path, $domain, $wp_user_name, $wp_user_pass
cd $wp_path
wp db reset --yes
wp core install --url="https://${domain}" --title=$domain --admin_user=$wp_user_name --admin_email="${user}@${domain}" --admin_password="${wp_user_pass}" --skip-email
wp rewrite structure '/%postname%/'
wp option update timezone_string $timezone_string
}
Please checkout the rest of the code in its official Github repo for local LEMP box. What do you use for local development? Please share it in the comments, below.