How can I use WP-CLI to manage my WordPress instance on cPanel?

Procédure

What is WP-CLI ?

WP-CLI is a command line tool that allows you to administer your WordPress installations from the command line console. WP-CLI allows you to access WordPress functionalities without necessarily using a web browser and without connecting to your site's administrator space.

Installing WP-CLI on cPanel

It is no longer necessary to install WP-CLI on cPanel, as it is now pre-installed and available by default on all our shared cPanel and CloudCP packages. To test WP-CLI, you can use the following command from the terminal of your cPanel web hosting package:

wp --info

You should then have information relating to your web hosting environment, such as the PHP version active on your console and the version of WP-CLI :

How can I use WP-CLI to manage my WordPress instance on cPanel?

Installing Wordpress with WP-CLI

1. Go to the "public_html" or"www" directory

cd public_html

2. Download WordPress :

wp core download

How can I use WP-CLI to manage my WordPress instance on cPanel?

3. Create your database and username via your cPanel interface

4. Modify the configuration file for your WordPress site

wp core config --dbname="dbuser_name" --dbuser="dbuser" --dbprefix="wp_" --dbpass="password
  • dbname : Name of your database
  • dbuser : User name of your database
  • dbprefix : This is the prefix of your SQL tables
  • dbpass : must be the password of your database username

If you reload your web page, you should arrive on a page explaining that you already have a"wp-config" configuration file installed.

How can I use WP-CLI to manage my WordPress instance on cPanel?

5. Startinstalling WordPress.

wp core install --url="http://mondomaine.com"--title="My WordPress site" --admin_user="Franck" --admin_password="password" --admin_email="contact@mondomaine.com"
  • url : Indicate your domain name
  • title : Enter the title of your website
  • admin_user : Enter your Wordpress username
  • admin_password : Indicate the password linked to your Wordpress login
  • admin_email : Enter your email address

How can I use WP-CLI to manage my WordPress instance on cPanel?

6. When you install Wordpress with WP-CLI, the default language is English. To change the language and put WordPress in French, type the following commands to install and activate the French language:

wp core language list wp core language install --activate fr_FR

How can I use WP-CLI to manage my WordPress instance on cPanel?

Installing a WordPress theme with WP-CLI

1. To view the list of themes installed on WordPress, type the following command:

wp theme list

How can I use WP-CLI to manage my WordPress instance on cPanel?

2. Toinstall a new Wordpress theme, go to the Wordpress site and choose the theme. Once the theme has been chosen, copy the theme name from the URL.

How can I use WP-CLI to manage my WordPress instance on cPanel?

3. Type the following command in SSH:

wp theme install theme_name

theme_name must be replaced by the name of the theme you have chosen.

How can I use WP-CLI to manage my WordPress instance on cPanel?

4. Activate the theme with the following command line:

wp theme activate theme_name

How can I use WP-CLI to manage my WordPress instance on cPanel?

Installing a WordPress extension with WP-CLI

1. List the existing extensions on your WordPress site.

wp plugin list

How can I use WP-CLI to manage my WordPress instance on cPanel?

2. Install the extension you want. The principle is the same as for installing a theme. Choose the name of the plugin on the Wordpress site and type the installation command in SSH, not forgetting to change"my_plugin" to the name of the desired extension.

wp plugin install my_plugin

How can I use WP-CLI to manage my WordPress instance on cPanel?

3. Now activate the module you have installed.

wp plugin activate my_plugin

How can I use WP-CLI to manage my WordPress instance on cPanel?

Deactivating a WordPress extension with WP-CLI

Thanks to WP-CLI, you can deactivate a WordPress extension without accessing the administration interface. This is certainly useful if you have lost access to your administration following the installation of a plugin (such as a security plugin).

To deactivate a plugin, use the following command:

wp plugin deactivate my_plugin

Cleaning up expired transients

WordPress stores temporary information such as user preferences in the MySQL wp_options table in the form of transients. If this table is too large, your site will be slow to search for information. Fortunately, WordPress indicates the expiry date of a transient, which means that after this date, WordPress no longer needs it. You can then delete them to reduce the size of wp_options with the following command:

wp transient delete-expired

You can also delete all transients, regardless of their expiry date, with the following command:

wp transient delete-all

Checking the integrity of a WordPress site

If your website has been or is infected, it is possible that WordPress files or plugin and theme files have been altered by viruses so that they can embed themselves. The following command can be used to automatically check WordPress files for possible corruption, and even identify files that should not exist in the wp-admin or wp-includes folder.

wp core verify-checksums

You can use the following command to do the same for plugins:

wp plugin verify-checksums --all

If you have corrupted files, you can remedy this problem by replacing the corrupted files with the original files available on www.wordpress.org in your FTP space.

Conclusion

You are now able to use SSH command lines and WP-CLI to install your Wordpress website, theme and modules.

Don't hesitate to share your comments or questions!

Rate this article :

5/5 | 2 opinion

This article was useful to you ?

Article utileYes

Article non utileNo

Vous souhaitez nous laisser un commentaire concernant cet article ?

Si cela concerne une erreur dans la documentation ou un manque d'informations, n'hésitez pas à nous en faire part depuis le formulaire.

Pour toute question non liée à cette documentation ou problème technique sur l'un de vos services, contactez le support commercial ou le support technique

MerciMerci ! N'hésitez pas à poser des questions sur nos documentations si vous souhaitez plus d'informations et nous aider à les améliorer.


Vous avez noté 0 étoile(s)

Similar articles

1mn reading

How do I program a Cron task in cPanel?

0mn reading

How do I connect to cpanel via SSH using putty?

1mn reading

How do I resolve the ERR_CONNECTION_REFUSED error on cPanel?

2mn reading

How do I create cPanel hosting sub-accounts?


Ask the LWS team and its community a question