Solved Automated WordPress Installation on DirectAdmin script

Dwebb

Verified User
Joined
Mar 13, 2023
Messages
10
This automates the entire process of setting up a fresh WordPress installation upon account creation, when certain packages are selected.

This was created for web hosting providers that want be able to offer ordering of WordPress Hosting packages, so a customer has a seamless instant setup of not only their account but their entire base WordPress installation done for them.

Link to full article & setup (quite easy!)


The script, but please read the full article for explanation & prerequisites. This shouldn't take you more than maybe 5 minutes to setup.

Bash:
#!/bin/bash

# Constants
DIRECTADMIN_HOSTNAME="your.directadminurl.com"
DIRECTADMIN_PORT=2222
DIRECTADMIN_USERNAME="admin"
DIRECTADMIN_PASSWORD=$(cat /usr/local/directadmin/scripts/adminpassword) # assuming you stored your password in a secure file
DIRECTADMIN_HTTPS=true  # Set this to true if your DirectAdmin server uses HTTPS

# The protocol should be https if DIRECTADMIN_HTTPS is true, http otherwise
if [ "$DIRECTADMIN_HTTPS" = true ]; then
  PROTOCOL="https"
else
  PROTOCOL="http"
fi

# Directory to the user's public_html
USER_DIR=/home/${username}/domains/${domain}/public_html

# Admin username, password, and email
ADMIN_USER=${username} # use the username provided during account creation
ADMIN_PASSWORD=$(openssl rand -base64 12 | tr -dc 'a-zA-Z0-9') # use openssl to randomly generate a password
ADMIN_EMAIL=${email}

# Check the package name and install WordPress if it matches
if [[ "${package}" = "wordpress_10gb" ]] || [[ "${package}" = "wordpress_50gb" ]] || [[ "${package}" = "wordpress_100gb" ]]; then

# MySQL Database details
DB_NAME="wp"
DB_USER="wp"
DB_PASSWORD=$(openssl rand -base64 12 | tr -dc 'a-zA-Z0-9')

# DirectAdmin API URL for MySQL database creation
API_URL_DB="${PROTOCOL}://${DIRECTADMIN_HOSTNAME}:${DIRECTADMIN_PORT}/CMD_API_DATABASES"

# Create the MySQL database
RESPONSE_DB=$(curl -s -u "${DIRECTADMIN_USERNAME}|${username}:${DIRECTADMIN_PASSWORD}" -d "action=create&name=${DB_NAME}&user=${DB_USER}&passwd=${DB_PASSWORD}&passwd2=${DB_PASSWORD}" "${API_URL_DB}")

if [[ $RESPONSE_DB == *"error=0"* ]]; then
    echo "Database created successfully."

    # Download WordPress
    sudo -u ${username} wp core download --path=${USER_DIR} --allow-root

    # Full path to wp executable. Replace this with the actual path.
    WP_CLI_PATH="/usr/local/bin/wp"
 
    # Create the wp-config file
    sudo $WP_CLI_PATH config create --dbname=${username}_${DB_NAME} --dbuser=${username}_${DB_USER} --dbpass=${DB_PASSWORD} --dbhost=localhost --path=${USER_DIR} --allow-root
 
    # Change the ownership of the wp-config.php file
    sudo chown ${username}:${username} ${USER_DIR}/wp-config.php
 
    # Install WordPress
    sudo $WP_CLI_PATH core install --url="${domain}" --title="New WordPress Site" --admin_user=${ADMIN_USER} --admin_password="${ADMIN_PASSWORD}" --admin_email=${ADMIN_EMAIL} --path=${USER_DIR} --allow-root

else
    echo "Error creating database. $RESPONSE_DB"
fi
fi

exit 0;
 
Last edited:
Already available in the Pro version and please stop spamming the forum with double posts!
 
Already available in the Pro version and please stop spamming the forum with double posts!
Posted in 3 relevant places. Just trying to help out the community.

Also there is absolutely no way to automate WordPress installations currently on DirectAdmin in 2023
 
Well you do help by posting what you made, thats correct.

But you also link back to your website for the full tutorial which is not that nice/could be considerd as self promotion. And for backlinks of course
 
Well you do help by posting what you made, thats correct.

But you also link back to your website for the full tutorial which is not that nice/could be considerd as self promotion. And for backlinks of course
All links are nofollow links on the DirectAdmin forum. This doesn't help me with backlinks.

I really don't know what else to say, was simply trying to help out by giving away a free solution to a problem that many people have.
 

you can just install it from the panel self
I think you're not understanding what this script does.

This automates the entire process of setting up a fresh WordPress installation upon account creation, when certain packages are selected. What you're linking to is completely manual. The user has to do it themselves.

This was created for web hosting providers that want be able to offer ordering of WordPress Hosting packages, so a customer has a seamless instant setup of not only their account but their entire base WordPress installation done for them.
 
What you're linking to is completely manual. The user has to do it themselves.
True, but its still automated by panel without uploading files.

This was created for web hosting providers that want be able to offer ordering of WordPress Hosting packages,
Was not really mentioned in your post and i didn't want to use the link to your website because i didn't like the way you were promoting your business name., but thanks for sharing.

Still not agree with the way your are posting (promoting) your business all over the forum.
 
delete your bussiness name from thread title, body or anyplace, otherwise you will get banned from moderator.
 
Yep, might be nice for users with legacy licenses to use, they don't haev the pro pack. Thanks for sharing.

However, it's indeed best you remove your company name from the title. You created the script it so I guess it's fine to keep it in your post.
 
Automated WordPress Installation on DirectAdmin script from CainHosting

Link to full article & setup (quite easy!)


The script, but please read the full article for explanation & prerequisites. This shouldn't take you more than maybe 5 minutes to setup.

Bash:
#!/bin/bash

# Constants
DIRECTADMIN_HOSTNAME="your.directadminurl.com"
DIRECTADMIN_PORT=2222
DIRECTADMIN_USERNAME="admin"
DIRECTADMIN_PASSWORD=$(cat /usr/local/directadmin/scripts/adminpassword) # assuming you stored your password in a secure file
DIRECTADMIN_HTTPS=true  # Set this to true if your DirectAdmin server uses HTTPS

# The protocol should be https if DIRECTADMIN_HTTPS is true, http otherwise
if [ "$DIRECTADMIN_HTTPS" = true ]; then
  PROTOCOL="https"
else
  PROTOCOL="http"
fi

# Directory to the user's public_html
USER_DIR=/home/${username}/domains/${domain}/public_html

# Admin username, password, and email
ADMIN_USER=${username} # use the username provided during account creation
ADMIN_PASSWORD=$(openssl rand -base64 12 | tr -dc 'a-zA-Z0-9') # use openssl to randomly generate a password
ADMIN_EMAIL=${email}

# Check the package name and install WordPress if it matches
if [[ "${package}" = "wordpress_10gb" ]] || [[ "${package}" = "wordpress_50gb" ]] || [[ "${package}" = "wordpress_100gb" ]]; then

# MySQL Database details
DB_NAME="wp"
DB_USER="wp"
DB_PASSWORD=$(openssl rand -base64 12 | tr -dc 'a-zA-Z0-9')

# DirectAdmin API URL for MySQL database creation
API_URL_DB="${PROTOCOL}://${DIRECTADMIN_HOSTNAME}:${DIRECTADMIN_PORT}/CMD_API_DATABASES"

# Create the MySQL database
RESPONSE_DB=$(curl -s -u "${DIRECTADMIN_USERNAME}|${username}:${DIRECTADMIN_PASSWORD}" -d "action=create&name=${DB_NAME}&user=${DB_USER}&passwd=${DB_PASSWORD}&passwd2=${DB_PASSWORD}" "${API_URL_DB}")

if [[ $RESPONSE_DB == *"error=0"* ]]; then
    echo "Database created successfully."

    # Download WordPress
    sudo -u ${username} wp core download --path=${USER_DIR} --allow-root

    # Full path to wp executable. Replace this with the actual path.
    WP_CLI_PATH="/usr/local/bin/wp"
 
    # Create the wp-config file
    sudo $WP_CLI_PATH config create --dbname=${username}_${DB_NAME} --dbuser=${username}_${DB_USER} --dbpass=${DB_PASSWORD} --dbhost=localhost --path=${USER_DIR} --allow-root
 
    # Change the ownership of the wp-config.php file
    sudo chown ${username}:${username} ${USER_DIR}/wp-config.php
 
    # Install WordPress
    sudo $WP_CLI_PATH core install --url="${domain}" --title="New WordPress Site" --admin_user=${ADMIN_USER} --admin_password="${ADMIN_PASSWORD}" --admin_email=${ADMIN_EMAIL} --path=${USER_DIR} --allow-root

else
    echo "Error creating database. $RESPONSE_DB"
fi
fi

exit 0;
Can it set for reseller account?
 
I tested, it has error
Unix User created successfully

User's System Quotas set
User's data directory created successfully
Domains directory created successfully
Domains directory created successfully in user's home

Domain Created Successfully

User added to ssh config file.
Database created successfully.
sudo: wp: command not found
Error: This does not seem to be a WordPress installation.
The used path is: /home/legiang2/domains/legiang.io.vn/public_html/
Pass --path=`path/to/wordpress` or run `wp core download`.
chown: cannot access '/home/legiang2/domains/legiang.io.vn/public_html/wp-config.php': No such file or directory
Error: This does not seem to be a WordPress installation.
The used path is: /home/legiang2/domains/legiang.io.vn/public_html/
Pass --path=`path/to/wordpress` or run `wp core download`.
 
Back
Top