Menu Close

How to Create a WP-CLI Connection to WordPress

If you’re a frequent developer of a WordPress and make use of the command-line, in that case we have some good news for you. WP-CLI is basically command-line software to administer WordPress websites and it’s also pre-installed plus it is accessible for employ on Rochen’s servers. WP-CLI allows you to govern different regions of your WP website without handling the web server and dashboard of WordPress administration. With the majority of hosts you would need to set up and deal with WP-CLI on the web server on your own however with Rochen’s optimized WP hosting plans we look after this weight for you.

With the use of WP-CLI, you can simply deal with your WP upgrades and installations. You can just modify configuration documents, and work with the database of your website. Also, you can deal with some administrative tasks for example, processing or uploading media files, deleting or approving comments, or posting. WP-CLI can actually accelerate a number of recurring WP administration tasks. As a customer of Rochen, you previously have WP-CLI accessible with any WP install on our web servers. To begin working with the WP-CLI instrument, you will require enabling SSH from the portal of Rochen customer for the appropriate account, open an SSH customer on your desktop, and get connected to your Rochen account with the use of SSH.

If you run Linux or Mac, you previously have a pre-installed SSH client along with your OS. In case, you have Windows on your computer, we advise you to download and set up an SSH client for example Putty. For additional security, by default, each and every Rochen hosting accounts get SSH disabled however you can easily enable it from the given My-Rochen customer portal only with some clicks.

The process of WP-CLI Installation

The process of installation of WP-CLI for the very first time is quite a frightening task. Hence, it is important for you to read the installation guide properly before it really makes sense. However, it will not be so hard for you as soon as you know what is needed actually. In the beginning, you will need to get the newest edition of WP-CLI. The suggested method to do the same is to download WP-CLI tool as a Phar Document with the help of command line. This is basically a PHP archive file that consist of all the PHP documents requires for the WP-CLI tool to run, and all covered up in just one suitable file ready for you to download.

The process of WP-CLI Installation on macOS

First of all you will need to open a terminal screen and type the below mentioned command –

  • $ curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

This will help you to download the Phar file of WP-CLI tool into your PC. Now, you will need to check it to know that everything’s good just by checking the WP-CLI archive.

  • php wp-cli.phar –info

To make employing the WP-CLI tool more expedient, you should be capable to run the same from anywhere and through a small line of command like wp in place of typing the wp-cli.phar every time. You can simply do the same with the use of below mentioned commands –

  • sudo mv wp-cli.phar /usr/local/bin/wp
  • chmod +x wp-cli.phar

Now you require running up wp –info command into the terminal screen (which point to any directory). When you see the exact same fallout as previous when you ran the command php wp-cli.phar –info then you learnt it. You have successfully installed WP-CLI tool which you can use now. In addition, there are several other methods through which you can set up WP-CLI tool, for example through Composer, thus you might wish to see the optional methods if you are facing problem with the suggested default method.

The process of WP-CLI Installation on Windows

Well, the process of WP-CLI Installation on Windows is rather more engaging, because PHP is not accessible from the by default command line. You can simply set up PHP manually; however the simplest method is to make use of a local web development server like MAMP since PHP is installed automatically as part of the entire package. As soon as PHP is accessible on your computer system, you will require finding the route to the PHP-executable plus you can make it accessible internationally (Normally, all these details are covered carefully in the PHP guidebook).

With PHP set up and accessible from any of the directory, just download the file named wp-cli.phar file manually plus save the file into a folder like c:\wp-cli. If you wish to be capable to run the WP-CLI tool through the wp command in the same way you did on mac operating system, you need to make a batch file known as wp.bat within the same folder in which you saved an archive file with the name of wp-cli.phar.

Include this into the batch-file:

@ECHO OFF

php “c:/wp-cli/wp-cli.phar” %*

In the end, include c:\wp-cli file into your universal path:

setx path “%path%;c:\wp-cli”

Now, the WP-CLI tool should be accessible from any sort of command line screen.

More Simple Method!

If you are experiencing some problem in the process we have something beneficial for you. If you tend to use DesktopServer then it is extremely easy to configure WP-CLI tool. While DesktopServer 3.8.2 is a brand new developer plugin, it helps you to set up the WP-CLI tool on almost all of your development websites. As soon as it is activated, you can easily access the WP-CLI tool through the main DesktopServer website list, or the WP toolbar. However, if you have enough access to your DesktopServer website we would certainly suggest you to install the WP-CLI tool in this manner, because ultimately it is the easiest installation method. There are so many users who have used DesktopServer for the past few years, and they found themselves lucky that WP-CLI tool installation was breeze for them.

Using WP-CLI distantly

This tutorial is completely focused on newbies who don’t know anything about WP-CLI, with the use of WordPress installation.  But, if you really wish to perform commands on a distant server (that is, an active WordPress website) then you can yet follow down if you have already installed WP-CLI. You will require being able to connect to web server through an SSH client plus have your web hosting login credentials handy. As soon as WP-CLI is connected and signed in, you will be capable to make use of all the WP-CLI tool commands in this guide. It’s worth getting in touch with your host for watching if they support the WP-CLI too because setting it up will be quite easier.

Updating Core WordPress Files

Please be informed that “wp core version” simply tell you the existing WP edition which is set up in the folder. It does not tell you whether a latest edition is accessible or not. To check whether you require installing a further latest edition, you will require using the below mentioned command –

  • wp core update-check

If you are already at the most recent edition, it will give you a notification stating that “WordPress is at the recent edition”. Or else, you can update your WordPress site manually to the recent edition with the use of following command –

  • wp core update

The fallout of this is that your WordPress required to be updated to edition 4.6.1. Hence, the aboven mentioned command is used to download as well as set up the needed files.  After completing the process, it represents a status update.

Plugin Maintenance

Well, one of the most usual tasks of a WP admin is to monitor and set up updates to themes and plugins. We have previously seen before how you can adjust the behavior of WP that updates all the plugins automatically for you. However, you still wish to take the path of manual route and see of a specific plugin requires being updated or not. At time the s, because of the code incompatibilities or any other reacons, you might choose to remain with an old-fashioned WP plugin. In any of the case, if you wish to check the status of the recently set up plugins on WP, you will need to enter the below mentioned command:

  • wp plugin status

This will produce a result that appears like this:

WP-CLI Connection

This is basically a list of each and every plugin on the website – inactive and active. The websites that are inactive are in white color and the same are leaded with the initial letter “I”. However the active websites are in green shade plus they have the letter “A” imprinted before them. A few plugins are there that required being updated – and they are imprinted in yellow color with the letter “U”.  You can just see in the above snapshot that we have three plugins that required being updated namely, Q2W3-Fixed Widget, Jetpack, and Akismet. For updating all of these plugins right away, you will need to type the below mentioned command into wp-cli:

  • wp plugin update –all

After that you will get this result:

WP-CLI Connection

In just a few seconds, all your plugins will be updated automatically and that too without any involvement from your side. You can see how much convenient and east this is with the help of CLI rather than a GUI. If you repeat this action a number of times in a day, just imagine how much time you are saving.

Deleting Transients

Well, Transients are old fashioned entries in WP that occupy space as well as can slow down your website in the end.  You can find several tutorials on the web on how you can clear up or delete transients from the database. It just required going straight into the database, running the SQL commands to recognize identify old-fashioned transients, and just clear up them. Since the above mentioned method works, but it’s very time consuming. And because this action is recurring which requires being done a daily basis, it’s a best aspirant for something that can be accomplished by a wp-cli connection.

Well, you can have the option to set up a plugin to plan the task for you, for sure. But, if you really want to save your time, you always try hard to reduce the number of plugins working on your website.

With wp-cli, all it takes is just one command to clear up transients:

  • wp transient delete-expired

In just a simple line of code, you can dispose of all the old transients from your database. However WP contains an object caching system. Thus, since the database has been cleared up from the transients, they still might remain in your site’s object cache. There is also a command to solve this problem with the help of WP-CLI.

  • wp cache flush

Collectively, both the commands will clear up transients from two of the database, plus your object cache as mentioned here:

WP-CLI Connection

Recovering from the White-Screen-of-Death

It is important for you to know that the White-Screen-of-Death has been banned for all the WP users sometime. At what time your website dies and you cannot have any access of it through the admin window, the initial response is to stop your plugins either through directly from the database or FTP. Next step is to disable the recently active theme too in case the previous option failed.

The problem with the above solution is that they can occupy a long time than you are comfy with. Whenever your website slows down, you need a quick solution. A solution, that takes only a few minutes rather than having to log into FTP plus rename your theme folder or all the plugins manually. As a WP-CLI connection does not rely on the GUI of  WordPress, It’s quite faster to just resolve your setbacks from the command-line instead.

For instance, to compel WordPress for disabling all the plugins despite of whether they are showing errors or not, you should type the given below command:

  • wp plugin deactivate –all –skip-plugins

With the usual path, WordPress is incapable to disable the plugins since they are still full before deactivation. In this case “skip-plugins” parameter assists you with this and stops them from being capable to meddle with the process of deactivation. In the same manner, if you wish to deactivate the existing theme and resume a “secure” default such as Twenty Sixteen, just set off a new theme through the command:

  • wp theme activate twentysixteen

With the use of these methods, you can easily recuperate from a White-Screen-of-Death right away. Of course, you still require fixing the theme or plugin which caused the error, however you still have a running website at least. Now you know just how valuable WP-CLI tool is for you.  Since the WP GUI tool is a proficient interface, but it’s not scalable, it’s slow, and it’s not dependable when an error takes place. By avoiding the regular loading of WordPress website, the CLI is capable enough to complete a lot more, and quickly.

Benefits of Employing WP-CLI commands

Though, it may take some time to learn the WP-CLI commands, as soon as you get better grip on them, your daily WordPress management will become simpler. Now, we are going to discuss some top benefits of using WP-CLI.

  1. Abridged Web Server Load

Your WP administrator dashboard is dependent on browser. Whenever you perform a task through your WP dashboard, you generate a load on internet server. If you perform the similar task through WP-CLI, you will sidestep the web server and easily save systems resources. A few WP administrative tasks, for example processing numerous videos or images, can take considerable resources. If you are processing bigger tasks then this could cross web-server timeout limits.

So, just commence the same tasks with the use of WP-CLI and your video or image files processing will function with no interruption once it takes. You won’t face timeouts even as the task runs efficiently in the backdrop.

  1. Better Productivity

Just employ WP-CLI and see the increase in your productivity. Imagine a scene where you require running the exact WP task continually. For instance, if you have numerous WP websites set up and would want to update all the sites. Or possibly you would want to run two or more than 2 tasks alongside.

  1. Better Security

It takes numerous command lines for producing GUI, for example the WordPress dashboard. The more amount of command line an application has, the website is more prone to safety concerns and bugs. On the contrary, WP-CLI is a group of much smaller coding tools, which makes WP-CLI much more protected. In place of setting up loads of management plugins, you can simply make use of WP-CLI to accomplish the similar tasks.

Final Words

It may take some time for you to get familiar with the WP-CLI commands for running everyday WP tasks, however it is worth using. So, it would be wise to turn to WP-CLI commands to get better results.

Related Posts