WordPress is known for its quick 5-minute installation process. However, it can be done even faster, much faster, using WP CLI (Command Line Interface).
To install WordPress, you need to follow these steps:
- Download WordPress.
- Create a database.
- Generate the wp-config.php file (created by the WP installer).
- Provide administrator and site basic information.
To download the latest version of WordPress, use the command:
wp core download --skip-content
--skip-content parameter prevents downloading default plugins and themes. You can also download the Polish version using the
Before creating the database, you should generate the wp-config file using the command:
wp config create --dbname=db_name --dbuser=user --dbpass=pass
You don’t have to remember these parameter names; you can use:
wp config create --prompt
This way, you’ll be prompted to provide all the necessary parameters.
Before installing WordPress, you need a database. You can create it with the following command:
wp db create
This command will use the settings configured in the wp-config.php file.
Now that you have downloaded WordPress, created a database, and generated the wp-config.php file, it’s time to install WordPress:
wp core install --prompt
Just like when creating wp-config, you can use prompts to set the necessary parameters.
WP CLI config file
There are quite a few commands, and you need to be familiar with all of them, so installing WordPress in this way, especially in the beginning, can take some time. However, you can make it even faster using a configuration file called wp-cli.yml. Here’s an example of what such a file might look like:
url: https://my-site.locale path: ./ core download: locale: pl_PL version: '6.3' skip-content: 1 core install: title: "My site" admin_user: admin admin_password: admin admin_email: email@example.com config create: dbuser: wordpress dbpass: wordpress dbname: wordpress dbhost: localhost dbprefix: wdr56_ extra-php: | define( 'WP_DEBUG', true ); define( 'WP_DEBUG_DISPLAY', true ); define( 'WP_DEBUG_LOG', true ); define( 'WP_ENVIRONMENT_TYPE', 'local' );
Now all you need to do is execute all of the above commands one after the other:
wp core download && wp config create && wp db create && wp core install
The above configuration is just an example and can be applied to a local environment. Here’s an explanation of the new parameters:
url– the address under which my WordPress will be accessible.
path– the directory where WordPress files will be located relative to the WP CLI configuration file.
version– it will download WordPress in the specified version; omitting this parameter will download the latest version of WordPress.
dbprefix– in my projects, I aim to keep the table prefix the same across all environments.
extra-php– additional PHP code that I want to include in the wp-config.php file. Here, I’ve set sample values for a local environment.
With a configuration file prepared in this way, I can copy it from one project to another, only changing the
dbprefix. When using Lando, I don’t need to change
dbname, but that’s a topic for another time.