How to automate WordPress installation?

WordPress installation is simple, but sometimes boring and time-consuming. So how to fit 20 minute operations into less than 2 minutes?


This topic is related to task automation so if you want to understand this example well, check out this or at least tools section that describes how to use those scripts.

I always try to put more effort installing WordPress, ensuring a solid foundation for the development process and saving time in the long run. I try to perform actions that are more than required and it takes time.


The manual process consists of steps that are just boring. I would rather spend time learning something new instead of clicking through all of this, but I don't want to skip them. So how to improve that?

- Create a local environment.
- Download WordPress core files and put them in the document root.
- Install WordPress and perform minimal required configuration.
- Dismiss all dashboard widgets. They don't provide any value for me.
- Remove default plugins. I don't want to keep things that is not used in the codebase.
- Select one theme for testing purposes and remove all others.
- Create a Home & Blog pages and set them in the configuration.
- Remove the default posts and widgets.
- Disable comments.
- Rename the "Uncategorized" category to "News".
- Add default menus.
- Set default permalinks.
- Add gitignore, and .htaccess configuration.


I just put WordPress installation responsibility to my environment! The software does what we tell it to do so why not spend some time writing commands and just ask env for doing them using bash and wp-cli?

function wp:init() {
  read -p "Are you sure? (y/n) " choice
  if [ "$choice" == "y" ]
    wp core download
    curl -o .gitignore
    curl -o .htaccess
    curl -o .htpasswd

    wp config create --dbname=$DB_NAME --dbuser=$DB_USER --dbpass=$DB_PASS --dbhost=$DB_HOST --dbcharset=utf8mb4 --dbcollate=utf8mb4_general_ci
    wp config set WP_DEBUG true --raw
    wp config set WP_DEBUG_DISPLAY true --raw
    wp config set WP_DEBUG_LOG true --raw
    wp config set WP_ENVIRONMENT_TYPE development
    wp config set DISALLOW_FILE_EDIT true --raw
    wp config set WP_AUTO_UPDATE_CORE true --raw

    wp db reset --yes
    wp core install --url=https://$DOMAIN_LOCAL --title=$TITLE --admin_user=$ADMIN_LOGIN --admin_password=$ADMIN_PASS --admin_email="$ADMIN_EMAIL" --skip-email

    wp user update 1 --first_name=Dev --last_name=Team
    wp post delete 3 --force
    wp post update 2 --post_title=Homepage --post_name=homepage
    wp term update category 1 --name=News --slug=news
    wp plugin delete hello akismet
    wp theme activate twentytwentyone
    wp theme delete twentytwentytwo twentytwentythree
    wp plugin install wordpress-seo
    wp comment delete 1 --force
    wp menu create "Primary"
    wp menu create "Secondary"
    wp menu create "Footer"
    wp widget reset --all
    wp widget delete $(wp widget list wp_inactive_widgets --format=ids)
    wp rewrite structure '/%postname%/'
    wp option set blog_public 0
    wp option update show_on_front page
    wp option update page_on_front 2
    wp option update page_for_posts $(wp post create --post_title=Blog --post_name=blog --post_type=page --post_status=publish --post_author=1 --porcelain)
    wp option update default_comment_status closed
    wp option update default_ping_status closed

    open "https://$DOMAIN_LOCAL"

How does the installation look like when using automation?

  1. Download the script and set privileges to 744.
  2. Create a local environment for the project.
  3. Run ./ wp:env and fill the required values.
  4. Run ./ wp:init script in the terminal.

And that's all. In less than a minute and WordPress is fully ready for the development process with all those boring steps that takes maunally at least 15 minutes performed. All those boring and repetitive tasks are now handled by the script.


How satisfied you are after reading this article?