Welcome To CODED
Latest From The Blog
I’m sure you’ll agree that it is important to build and work on sites in a staged environment before putting them live. Even though we don’t always follow this advice (quick fixes don’t always warrant the effort of syncing to a local environment), it is an important habit to adopt.
The only problem here is that it is time-consuming. It’s not going to take hours but, it takes enough time to be an inconvenience.
I’m always on the lookout for new tools to speed up my workflow. For example, when migrating sites, I use duplicator as it makes the process smoother and quicker. So, when it comes to building a new website locally, I have a powerful tool that makes the process a breeze.
I prefer to do as much of my work as possible from the command line. There’s a lot less reaching for the mouse that way. It just so happens that there is a tool that mashes WordPress and the command line together. WP-CLI (WordPress Command Line Interface). There are so many jobs you can do using this helpful tool. What I’m going to show you today, is how to install WordPress locally using this tool.
Make a folder for your new site
I’m going to assume you know at least a little bit about command-line while doing this (fire a comment below if you need me to clarify any of the commands). We need to make a new folder for our new WordPress install. I use a Mac therefore, I use MAMP to serve my WordPress sites locally. If you are using windows check out WAMP. We need to go to the folder that MAMP uses to store websites. By default, it is located in:
unless you have explicitly changed it. Change it to that directory
Next, we need to create a new folder.
Then move into the newly created directory.
Now the fun begins.
Download WordPress in a flash
This is the easiest part by far. Type the command below into your terminal (or copy and paste, your choice).
wp core download
Before your eyes, you will see WordPress installing into your newly created directory.
Create the config file and database.
The next step is to create you wp config file
create --dbname="name of your database" --dbuser="root" --dbpass="root"
You can call your database whatever you’d like. It doesn’t exist yet. Let’s create it
wp db create
You have now created a WordPress database in seconds. No stuffing around with MySQL or phpmyadmin required.
The famous 5 minute install done in less than a minute!
Now we have to install WordPress. I often forget parts of this one but here is a little tip I picked up. By typing
wp core install you will receive an error message. However, contained in that error message are all the missing parameters you will need.
wp core install --title="Name of your site" --url="path to your site" --admin_user="user" --admin_password="password" --admin_email="email@example.com"
Congratulations, you have now installed a new WordPress website locally. It only took 4 commands total. Pretty neat huh!
WP CLI is an amazing tool with a heap of different functions that it can perform. If you do nothing with it other than installing WordPress sites locally it is worth the effort to install it alone. I challenge you to delve a bit deeper and find out what else you can do with this tool. Leave a comment below and tell me what you discover. I will be writing a lot more about WP CLI in the future, so stay tuned for more tricks.
Turns out that enqueuing for the backend has a subtle difference to enqueuing for the front end.
Enqueuing On the Front End
wp_enqueue_script('My Custom Script',
Enqueing On The Back End
wp_enqueue_script('My Custom Script',
Happy coding folks!!
For site migration of WordPress sites, I use a plugin! Before you all look down on me, let me explain why. I have moved plenty of sites around the manual way. Sometimes this was for clients moving there site to our hosting and sometimes it was going from a staging site to a live site (or vice versa). I’ve done the search and replace of the sites URL in the site’s database countless times. Its easy enough to do all this but for some reason, I always feel a little nervous about it. So, I decided to try out Duplicator and I would never go back.
As soon as duplicator is installed and activated on the site you want to migrate, you head over to the admin section and click the create package button. From there you are given options to filter out any files you don’t want to move over (think subdomains and addon domains), you are given the option to enter in the name of the new database and host so that you don’t need to fill it in later. It then does a check to see if everything looks good. This is where there may be a downfall for some of you (this can be fixed by purchasing the pro version), if your site is over 250mb then you will be warned that the package may not be able to be created. It will check the database. If all looks good it will create a zip file containing your whole site + your database and a hand installer file to download.
The next step is to move the file you just downloaded into their new destination. Once you have moved or uploaded the files to where you want to have your site, you simply need to go to the site in your browser with installer.php tacked on to the end.
You are then taken through the steps to install your site. This takes a matter of seconds to complete. You will be stunned when your site is up and running exactly the way you intended (no search-replace required). You will be prompted to delete the installations files which are taken care of with the click of a button.
A few things to note.
- It may be worth resetting the permalinks once you have the site up. This ensures every page is going where it needs to.
- When at the database section of installation, if you use the option create new database, pressing test will return an error saying the database was unable to be reached. This is because it doesn’t yet exist. Ignore this.
So, next time you migrate a WordPress website, give duplicator a go. It will seriously speed up your workflow and take any anxiety the goes with moving websites and databases away.