Creating a new WordPress website using WPCLI

First we need to download the core files:

wp core download 

Optionally you can pass attributes as language for example:

wp core download --locale=pt_BR

Not every shared hosting offer wpcli, but fortunally Dreamhost offer it by default. But when trying for the first time I encontered the following error:

PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 36864 bytes) in /usr/local/wp/php/WP_CLI/Extractor.php on line 100

That means PHP get limit when tried to download and extract WordPress (128MB). So we need to increase the “memory_limit” argument in php.ini. Dreamhosts call this file as “phprc” and is located in a folder /home/username/.php/version. (eg: /home/useander/.php/8.2).

So we need to know what version is currently in use by cli. The following command show exactly this:

wp cli info

Returns something like

Shell:  /bin/bash
PHP binary:     /usr/bin/php
PHP version:    8.2.26
php.ini used:   /etc/php82/php.ini
MySQL binary:   /usr/bin/mysql
MySQL version:  mysql  Ver 8.0.30-0ubuntu0.20.04.2 for Linux on x86_64 ((Ubuntu))

We can see PHP 8.2 is in use. As in shared host we cannot directly change this php.ini file, we change the phprc file in our user directory, as demonstrated above.

add the following in /home/yourusername/.php/8.2/phprc file

memory_limit = 256M;
  • The file can already have some arguments. You can leave as is.

Other way is to change the PHP version cp-cli uses. To do this you can add the follow line to the .bash_profile file in root of your user in Dreamhost.

export WP_CLI_PHP=/usr/local/php83/bin/php wp

Probably now you can run the command succesfully

Now we need to create a wp-config file. the following command makes this.

wp config create --dbname=NOME_DO_BANCO --dbuser=USUARIO --dbpass=SENHA --dbhost=localhost

All ready for installation:

wp core install --url=http://seusite.com --title="Título do Site" --admin_user=admin --admin_password=senha_segura [email protected]

More info:

https://help.dreamhost.com/hc/en-us/articles/214693248-WordPress-wp-cli-overview

https://help.dreamhost.com/hc/en-us/articles/214200748-My-phprc-file-isn-t-updating#Update_your_phprc_file_in_your_panel

https://help.dreamhost.com/hc/en-us/articles/214894037-Create-a-phprc-file-via-FTP

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *