Setting up WordPress on DreamCompute


This tutorial explains how to install WordPress on a DreamCompute instance, including both the application itself and the database it uses. All necessary components will be installed and configured without making use of automatic configuration management systems.


This article assumes you've already created a new instance. If not, view the following articles for details on creating a new instance:

This example will use Ubuntu 20, but you can use whichever flavor of Linux you prefer. As long as you can install Apache, PHP, and database software, WordPress will be able to run.

Whichever image you pick, remember it's better to use instances with a volume boot disk as they are permanent (as opposed to instances with ephemeral boot disks).


Step 1 — Point DNS to your instance

First, you'll need to point the DNS of your domain to the instance. View the following article for details:

Step 2 — Add SSH Access

WordPress users often need SSH access in order to accomplish specific configurations within WordPress. By default, this is disabled, so you will need to edit your SSH config using a text editor, such as vim, emacs, or nano (this one is easiest for beginners). View the following article for further information:

Step 3 — Create a user with sudo privileges

While it is not required to make a separate user on the instance for WordPress, it's strongly recommended for security. View the following article for further information:

This article assumes the new user is named exampleuser

After creating the user, assign it sudo privileges. Then log in to your instance using the default user. Once logged in, switch to the new user before continuing.

Step 4 — Install LAMP

While you certainly can install everything on its own, the LAMP stack for Ubuntu is perfect for WordPress. A separate DreamHost article on how to configure LAMP is available below, but you can just run the following commands to install.

[exampleuser@instance]$ sudo apt-get update
[exampleuser@instance]$ sudo apt-get install lamp-server^

The second command is interactive, so you will be asked Do you want to continue? in some places.

Enable mod_rewrite

Enable mod_rewrite so that WordPress permalinks (or "pretty" URLs) work.

[exampleuser@instance]$ sudo a2enmod rewrite

Finally restart Apache.

[exampleuser@instance]$ sudo service apache2 restart

At this point, you should be able to access your instance in a web browser using its IP address. If not, double-check the security group(s) assigned to your instance to make sure that incoming connections to port 80 are allowed for your IP address. View the following article if you need help working with security groups. 

Step 5 — Configure the MySQL server

You must now configure and secure the MySQL server by adding a password and choosing which features you'd like to disable. View the following link for instructions.

Step 6 — Create a folder for your website

Create a folder for the website.

[exampleuser@instance]$ sudo mkdir /var/www/

Then give the user you just created ownership of that directory and its contents. You should also assign group ownership of the directory to the default Apache group of www-data.

[exampleuser@instance]$ sudo chown -R exampleuser:www-data /var/www/

Step 7 — Configure the site's VirtualHosts file

Next, you'll want to configure VirtualHosts so your instance's Apache service knows how to handle the domain. To do this, you need to create a .conf file.

[exampleuser@instance]$ sudo touch /etc/apache2/sites-available/

It is recommended that you name the file after your domain, so that you can always know what .conf file is for what domain.

Edit the file. You can use the vim or nano editor.

[exampleuser@instance]$ sudo vim /etc/apache2/sites-available/

Add the following code to it. Make sure to adjust the domain name to your actual site and email to an existing administrator email.

<VirtualHost *:80>
    DocumentRoot /var/www/
    <Directory /var/www/>
            AllowOverride all
            Require all granted

    ErrorLog ${APACHE_LOG_DIR}/
    CustomLog ${APACHE_LOG_DIR}/ combined

Once the VirtualHost is added, the site will need to be enabled with the a2ensite command.

If you want to disable a site, you would use the command a2dissite.

[exampleuser@instance]$ sudo a2ensite

This will prompt you to pick what site you want to enable. Type your domain name and press the Enter key.

Your choices are: 000-default default-ssl
Which site(s) do you want to enable (wildcards ok)?
Enabling site
To activate the new configuration, you need to run:
  service apache2 reload

Remember this command as it is a fast way to enable sites without having to rename files. Finally, reload your Apache service so it reads the changes.

[exampleuser@instance]$ sudo service apache2 reload

Step 8 — Create the database and users

WordPress requires a database. To create one, start by accessing the MySQL service installed by LAMP earlier.

[exampleuser@instance]$ sudo mysql -u root -p
Enter password:

Enter the password that you created for the MySQL root user in step #5 above.

Your command prompt changes to mysql>. You can now create the database and assign a new user to it with their own unique password.

Create the database

mysql> CREATE DATABASE wordpressdb DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

This creates a new database named wordpressdb.

Create a database user

Run the following command to create a user for this database.

When running the command below, remember to change PASSWORD to a secure password. In this command, dbuser is the new database username for the new database.

mysql> CREATE USER 'dbuser'@'localhost' IDENTIFIED BY 'PASSWORD';

Grant the user access to the database

mysql> GRANT ALL ON wordpressdb.* TO dbuser@localhost;

Exit the mysql prompt.

mysql> exit

You can check that the database was successfully created by running the following command.

[exampleuser@instance]$ mysql -u dbuser -p wordpressdb

This logs you into the MySQL server and your command prompt changes to mysql>.

Step 9 — Install WP-CLI

While this is optional, it is strongly recommended. DreamHost includes WP-CLI on all its managed servers due to its usefulness. For more information about WP-CLI, view the project homepage below.

Run the following to install.

[exampleuser@instance]$ cd ~
[exampleuser@instance]$ curl -O

Run the following command to verify that WP-CLI works.

[exampleuser@instance]$ php wp-cli.phar --info

OS:     Linux 5.4.0-26-generic #30-Ubuntu SMP Mon Apr 20 16:58:30 UTC 2020 x86_64
Shell:  /bin/bash
PHP binary:     /usr/bin/php7.4
PHP version:    7.4.3
php.ini used:   /etc/php/7.4/cli/php.ini
MySQL binary:   /usr/bin/mysql
MySQL version:  mysql  Ver 8.0.26-0ubuntu0.20.04.2 for Linux on x86_64 ((Ubuntu))
SQL modes:
WP-CLI root dir:        phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir:      phar://wp-cli.phar/vendor
WP_CLI phar path:       /home/exampleuser
WP-CLI packages dir:
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 2.5.0

Next, move the location to make it accessible for all users. 

[exampleuser@instance]$ chmod +x wp-cli.phar
[exampleuser@instance]$ sudo mv wp-cli.phar /usr/local/bin/wp

Step 10 — Install WordPress

Navigate into your site's directory and use WP-CLI to download the latest version of WordPress.

[exampleuser@instance]$ cd /var/www/
[exampleuser@instance]$ wp core download

If you visit your domain in a browser now, you'll get a WordPress setup/configuration page.

Option 1 — Installing from the configuration page

You can now install WordPress using the configuration page. You also have the option to install using the command line using WP-CLI.

Option 2 — Installing using WP-CLI

You can also install WordPress using the WP-CLI with the following commands.

Create the wp-config.php file

Enter your database credentials to create the wp-config.php file. This allows your website to connect to the database.

[exampleuser@instance]$ wp core config --dbname=wordpressdb --dbuser=dbuser --dbpass=PASSWORD
Success: Generated 'wp-config.php' file.

Create a WordPress username

If you want to use a secure password like cWG8j8FPPj{T9UDL_PW8, you must put quotes around it.

In this example, the option to skip-emails has been chosen since all the necessary information is specified directly in the WP-CLI command.

The backslash character \ is used when entering a long command. When you enter the \, the terminal command continues to the next line until you finish entering it.

You could also remove the \ character and put every parameter into a single line.

[exampleuser@instance]$ wp core install --url= --title=DreamComputePress \ 
--admin_user=YOURUSERNAME --admin_password=PASSWORD --skip-email
Success: WordPress installed successfully.

Visit your domain to see a new WordPress site has been created.

Step 11 — Set permissions

Setting directory and file permissions

To secure your website folder, make sure all directories are set to 755 permissions and files to 644.

[exampleuser@instance]$ sudo find /var/www/ -type d -exec chmod 755 {} \;
[exampleuser@instance]$ sudo find /var/www/ -type f -exec chmod 644 {} \;

Set the setgid bit for all directories

Setting the setgid bit for all directories causes newly created files to inherit the group permissions of the parent directory. This ensures permissions will remain correct in the future.

[exampleuser@instance]$ sudo find /var/www/ -type d -exec chmod g+s {} \;

Allow the wp-content directory and its subdirectories to be writable.

[exampleuser@instance]$ sudo find /var/www/ -type d -exec chmod g+w {} \;

Modify the permissions of wp-config.php so that only users on your instance can access it.

[exampleuser@instance]$ chmod -v 640 wp-config.php
mode of 'wp-config.php' changed from 0644 (rw-r--r--) to 0640 (rw-r-----)

Change ownership of all WordPress site files to your username and the group to www-data so that Apache can access the files.

In the following command, change exampleuser to the user you created in step #3 above.

[exampleuser@instance]$ sudo chown -R exampleuser:www-data /var/www/

Step 12 — Editing the wp-config.php file

You must now add a line to the bottom of the wp-config.php file.

[exampleuser@instance]$ sudo vim /var/www/

Add the following line to the bottom of the file:

define('FS_METHOD', 'direct');

You can now install Themes and Plugins within the WordPress dashboard.

Additional configurations

Installing Themes and Plugins

When you install a Theme or Plugin, the permissions default to www-data:www-data. For security purposes, it's recommended to switch the user back to your own username when you're finished installing new software.

[exampleuser@instance]$ sudo chown -R exampleuser:www-data /var/www/

Upgrading WordPress

When upgrading WordPress, you need to manually change the permissions back to the Apache www-data group so that the Apache webserver can access the files.

[exampleuser@instance]$ sudo chown -R www-data:www-data /var/www/

When finished updating, switch your permissions back to your user.

[exampleuser@instance]$ sudo chown -R exampleuser:www-data /var/www/

Make PHP Better

If you plan to use a lot of media, install the following system packages to improve how PHP processes images.

[exampleuser@instance]$ sudo apt install php-imagick php-gd

Make sure to restart Apache so that PHP starts using those packages.

[exampleuser@instance]$ sudo service apache2 restart


If permalinks aren't working, make sure you installed rewrite.

[exampleuser@instance]$ sudo a2enmod rewrite && sudo service apache2 restart

And make absolutely sure you have AllowOverride set to All in your Virtual Host.

Open the file.

[exampleuser@instance]$ sudo vim /etc/apache2/sites-available/

How these lines should appear.

<Directory /var/www/>
    AllowOverride all
    Require all granted

Permalinks will not work without it.

Further WordPress configurations

If you're interested in using HTTPS with this WordPress installation, check out the following articles for assistance setting up Let's Encrypt on your instance and configuring WordPress to use HTTPS.

View the WordPress category below for further customizations.

See also

Did this article answer your questions?

Article last updated PST.

Still not finding what you're looking for?