Automate WordPress Installation on DirectAdmin with a Simple Bash Script - Entexion Hosting Solutions

Automate WordPress Installation on DirectAdmin

with a Simple Bash Script

WordPress

Setting up WordPress manually on a server can be time-consuming and error-prone, especially when handling multiple installations. While some hosting environments provide one-click installers like Softaculous, many users might prefer or need to install WordPress manually, especially on VPS or dedicated servers without those tools.

For those using DirectAdmin on a VPS or dedicated server, automating WordPress installations can significantly simplify the process. By using a bash script, we can streamline everything—from creating a database, configuring the WordPress files, to fetching secure salts and setting up admin credentials—all in just a few minutes.

In this article, we’ll dive into a custom bash script that can be run on any of our VPS or dedicated servers running DirectAdmin. This script automatically handles all the heavy lifting of installing WordPress without needing any one-click installer.

The Bash Script: What It Does

Our script is designed to automate the following steps:

  1. Downloads the Latest Version of WordPress: Fetches the latest version from the official WordPress website.
  2. Configures the MySQL Database and User: Creates a database and a user for the WordPress installation, ensuring no conflicts with existing databases by appending a random suffix if needed.
  3. Fetches and Configures WordPress Salts: Using the WordPress secret-key API, the script automatically inserts secure keys into the wp-config.php file, ensuring your installation is secure from the start.
  4. Sets Up the WordPress Configuration: The script populates the wp-config.php file with database credentials and other necessary configurations.
  5. Creates an Admin User: The script automatically creates an admin account with a randomly generated password and displays it at the end of the process.
  6. Ensures Compatibility with DirectAdmin: It updates the relevant DirectAdmin configuration files so that the new MySQL database and user are visible in the control panel.
  7. Outputs WordPress Admin Login Details: Once complete, the script displays the admin username, password, and login URL.

Why Use This Script?

Many hosting environments provide one-click installers like Softaculous to handle WordPress installations. However, not all environments include these tools, especially when you’re running on a VPS or dedicated server with custom configurations. Here are the benefits of using this script:

1. Full Control Over Installation

When using a bash script, you have complete control over the installation process. You know exactly what is being set up, how the database is created, and where files are placed. This level of transparency can be vital for developers and advanced users who prefer to avoid third-party tools.

2. Enhanced Security with Custom Salts

Security is a top priority when setting up any website. Our script leverages the WordPress secret-key API to automatically generate and insert secure salts (AUTH_KEY, SECURE_AUTH_KEY, and more) into the wp-config.php file. These salts help strengthen your WordPress installation against potential threats by securing the authentication process. Unlike manual installations, which often skip this step, our script ensures that your WordPress site is as secure as possible right from the start.

3. Automated Database Setup

Instead of manually creating databases through the DirectAdmin interface, the script automatically creates a new database and a MySQL user. If a database with the same name already exists, the script appends a random suffix, ensuring no naming conflicts. This makes the process seamless, especially when managing multiple installations.

4. Compatibility with DirectAdmin

The script is built with DirectAdmin in mind. Not only does it handle the WordPress setup, but it also updates DirectAdmin’s configuration files to ensure the new MySQL database and user are visible in the DirectAdmin interface. This eliminates the need for manual database entry updates in DirectAdmin, saving you time and effort.

5. Admin Credentials Displayed Safely

Once WordPress is installed, the script generates a secure password for the admin user and displays it at the end of the installation. This saves you from having to manually set up admin credentials and ensures that the password is strong and secure.

6. Scalability

If you are managing multiple WordPress installations on a VPS or dedicated server, this script is perfect for scaling. You can easily tweak the script to run for different users or domains, making it ideal for developers, agencies, or hosting providers managing multiple WordPress sites.

How to Use the Script

Using this script on one of our VPS or dedicated servers running DirectAdmin is simple. Here’s a quick guide on how to get started:

1. Login via SSH

Connect to your VPS or dedicated server using SSH as the root user

2. Clone the directadmin-wp Git repository

git clone https://github.com/Entexion/directadmin-wp.git

3. Run the Script

Run the script, specifying the DirectAdmin username and domain for which you want to install WordPress:

./install_wordpress.sh <directadmin_user> <domain>

For example:

./install_wordpress.sh alice example.com

The script will then:

  • Clear the public_html directory of the specified domain.
  • Download and extract WordPress.
  • Create the database, user, and necessary configuration.
  • Insert secure salts and set up the wp-config.php file.
  • Output the admin credentials for you to log in.

4. Login to WordPress Admin

Once the script finishes running, it will display the admin login credentials and the URL:

WordPress installation complete for example.com

Admin Username: admin

Admin Password: a-generated-password

Login URL: http://example.com/wp-admin

Visit the wp-admin link, log in with the credentials, and start building your WordPress site!

For those running DirectAdmin on VPS or dedicated servers, this bash script is an excellent alternative to using a one-click installer. It offers more control, security, and scalability, making it perfect for users who want full transparency and efficiency during the installation process.

By automating the entire process, from database creation to fetching secure salts, this script not only saves time but also ensures that every WordPress installation is done right—with security and best practices built in. Whether you’re managing a single site or dozens, this script will simplify your workflow and give you the flexibility you need to manage WordPress installations effectively.

If you’re looking for an easy, secure, and reliable way to install WordPress on your DirectAdmin server, give this script a try today!

Entexion opens the door to your digital transformation journey

Listed on WHTop.com
Review us on TrustPilot

Copyright © 2021-2024 GNET Communications Ltd