Install WordPress from CLI
At my agency, we do a lot of work with WordPress. If you are also a WordPress developer, you may be in the same situation. When you are creating a new local development site with WordPress, it could take time...more time than you want to spend. If this is the case, try to install it all from CLI. It is easy to do if you are able to SSH into your local or remote server.
This entire tutorial relies on you using SSH and having an already existing server. So, stop and set that up if you have not already done so. Also, keep in mind you can use things like Docker to do this but if you normally do this manually, it may save you some time.
Open your CLI and type the following command (change out the username and server ip address to match your setup.
Enter your password and create your new virtual host / folder. I use Roverwire Virtualhost Manage Script. It makes it as to create virtual hosts on a Linux server using only SSH. You can view more about it here: https://github.com/RoverWire/virtualhost
If you use Roverwire, you can simply type:
sudo virtualhost create sample.local
Once that is done, we can get WordPress set up.
First things first, create a new folder for your website. In this tutorial, I will be using sample.local.
The following commands will install a folder called wordpress in your newly created server folder.
sudo wget http://wordpress.org/latest.tar.gz
sudo tar xfz latest.tar.gz
Once you have the WordPress folder, you will need to move it and then remove the extractable file you downloaded previously.
sudo mv wordpress/* ./
sudo rmdir ./wordpress/
sudo rm -f latest.tar.gz
Finally, after setting this up, you can move on to setting up the database using the MySQL instructions below. Once the database is set up, you can go to the domain you created above and run the typical WordPress installation.
The username and password combination for your MySQL server should already be set up. You can log in by using the following command:
mysql -p -u mysqlusername
You will then be prompted for the password.
Once you have logged in successfully, you should now see a MySQL prompt instead of the normal SSH prompt. It will look like this:
create database databasename;
Lastly, you may need to set up shared or global permissions to your new website. You can do this a few different ways, but I found that a shared user works best:
sudo chown -R shareuser /var/www/samplelocal
or for a global user
sudo chown -R www-data:www-data /var/www/samplelocal
Now your WordPress website is ready to go. To view your new website locally, you will need to modify your hosts file. You can do this using the following instructions:
Windows is typically located at
OSX and Unix/Linux is typically located at
Add the following to your host file. domainname.fdg should be changed to the virtual host that was created above.
Now that you have successfully created your virtual host, installed WordPress, and set up your hosts. You can browse the website URL to finish the installation in the WordPress installer.
Here is a quick video on how to set up WordPress once you get to this step.
Read more articles on DevDrawer