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 an Ubuntu virtual machine, 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 machine type 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 set up DNS for your domain to point 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'. Make sure to assign the user sudo privileges and switch to the new user before continuing. 

Step 4 — Install LAMP

While you certainly can install everything on it's own, the LAMP stack for Ubuntu is perfect for WordPress. A separate DreamHost article on how to configure LAMP is available below, but an overview is also provided here.

[user@instance]$ sudo apt-get update
[user@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.

You will also be asked to set a password for the root user of your SQL software. Create a secure password and save it as you will need this later to set up a database for WordPress.

Enable mod_rewrite

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

[user@instance]$ sudo a2enmod rewrite

Finally restart Apache.

[user@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. If you need help working with security groups, see DreamHost's article here:

Step 5 — Create a folder for your website

Create a folder for the website.

[user@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.

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

Step 6 — 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.

[user@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 that file:

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

Add the following code to it. Make sure to adjust the domain name to your actual site.

<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 a command called a2ensite.

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

[user@instance]$ sudo a2ensite

This will prompt you to pick what site you want to enable. Type it in, hit enter, and you'll be told what's next.

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. It's a fast way to enable sites without having to rename or mess with files. Finally reload your Apache service so it reads the changes.

[user@instance]$ sudo service apache2 reload

Step 7 — Create the database and users

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

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

Enter the password that you created for the MySQL root user when installing LAMP.

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

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

This creates a new database named 'wordpressdb'.

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> GRANT ALL ON wordpressdb.* TO dbuser@localhost IDENTIFIED by 'PASSWORD';

Exit the mysql prompt.

mysql> exit

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

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

Step 8 — 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, see the project homepage below.

To install, run the following.

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

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

[user@instance]$ php wp-cli.phar --info
PHP binary:     /usr/bin/php7.0
PHP version:    7.0.22-0ubuntu0.16.04.1
php.ini used:   /etc/php/7.0/cli/php.ini
WP-CLI root dir:        phar://wp-cli.phar
WP-CLI vendor dir:      phar://wp-cli.phar/vendor
WP_CLI phar path:       /home/ubuntu
WP-CLI packages dir:
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 1.4.1

And if it does move it so everyone can use it.

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

That will make it accessible for all users. 

Step 9 — Install WordPress

Switch to the site directory you created and use WP-CLI to download the latest version of WordPress.

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

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

Installing using WP-CLI

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

In the first command, enter your MySQL database and user credentials.

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

In the next command, create a new username for WordPress with a new password.

If you use secure passwords like cWG8j8FPPj{T9UDL_PW8 then you MUST put quotes around them.

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.

[user@instance]$ wp core install --url= --title=DreamComputePress \ 
--admin_user=YOURUSERNAME --admin_password=PASSWORD --skip-email
sh: 1: /usr/sbin/sendmail: not found Success: WordPress installed successfully.

If you visit your site now, you'll see a new WordPress site has been created.

Step 10 — 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.

[user@instance]$ sudo find /var/www/ -type d -exec chmod 755 {} \;
[user@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.

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

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

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

Next, to secure your installation of WordPress, modify the permissions of wp-config.php so that only users on your instance can access it.

[user@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.

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

Step 11 — Editing the wp-config.php file

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

[user@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.

[user@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.

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

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

[user@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.

[user@instance]$ sudo apt install php-imagick php7.0-gd

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

[user@instance]$ sudo service apache2 restart


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

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

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

<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 from DreamHost's Knowledge Base for assistance setting up Let's Encrypt on your instance and configuring WordPress to use HTTPS.

For further WordPress customizations, please review the WordPress category in DreamHost's knowledge base below.

See also

Did this article answer your questions?

Article last updated PST.

Still not finding what you're looking for?