Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 26, 2022 07:01 pm GMT

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.

View This On YouTube

SSH Into Your 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.

Download and Extract WordPress

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.

Switch to the folder you created on the server

cd /var/www/samplelocal/

Download latest Version

sudo wget  http://wordpress.org/latest.tar.gz

Extract WordPress

sudo tar xfz latest.tar.gz

Move Folders

Once you have the WordPress folder, you will need to move it and then remove the extractable file you downloaded previously.

Move WordPress folder to the parent

sudo mv wordpress/* ./

Remove WordPress folder

sudo rmdir ./wordpress/

Remove downloaded file

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.

Setup Database

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:

mysql>

Create Your Database

create database databasename;

Exit MySQL

exit

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

Modify Hosts File

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
%SystemRoot%\System32\drivers\etc\hosts

OSX and Unix/Linux is typically located at
/etc/hosts

Add the following to your host file. domainname.fdg should be changed to the virtual host that was created above.

192.168.0.1 sample.local

Open Your Website

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.

Good luck.


Original Link: https://dev.to/thedevdrawer/install-wordpress-from-cli-3cio

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To