How-To

WordPress On VPS (Step 3): Installing WordPress

By now, you should have registered your domain name and configured the DNS settings so that it will point to your VPS. If you haven’t, and somehow stumbled on this post, go back to Step 1 to register your domain name via NameSilo. If you’ve missed Step 2, go back and configure the DNS settings for your domain.




Step 3: Installing WordPress
First, you need to SSH into your VPS. Next, perform the following commands while in your user directory (replace all yourdomain.com with your own domain name):


  1. Wget the latest copy of WordPress from wordpress.org:
    sudo wget https://wordpress.org/latest.tar.gz
  2. Extract the wordpress folder from the .tar.gz file:
    sudo tar -xzvf latest.tar.gz
  3. Create the directory using your domain name in /var/www, and public_html folder in /var/www/yourdomain.com:
    sudo mkdir /var/www/yourdomain.com
    sudo mkdir /var/www/yourdomain.com/public_html
  4. Copy the contents of the wordpress folder into /var/www/yourdomain.com/public_html/:
    sudo cp -r wordpress/* /var/www/yourdomain.com/public_html/
  5. Change the owner of your public_html folder and all its contents to www-data (the OS of my VPS is Ubuntu, so we use www-data):
    sudo chown -R www-data:www-data /var/www/yourdomain.com/public_html/
  6. In /etc/apache2/sites-available/, create a new file named yourdomain.com.conf:
    sudo vi /etc/apache2/sites-available/yourdomain.com.conf
    Then type in the following:

    <Directory "/var/www/yourdomain.com/public_html">
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
    </Directory>
    <VirtualHost *:80>
    ServerAdmin support@yourdomain.com
    DocumentRoot /var/www/yourdomain.com/public_html
    ServerName www.yourdomain.com
    ServerAlias yourdomain.com
    ErrorLog /var/www/yourdomain.com/error.log
    CustomLog /var/www/yourdomain.com/requests.log common
    </VirtualHost>

  7. Create a MySQL database for this WordPress website and a user that will have all privileges to access and modify it. I used phpMyAdmin as it’s definitely way easier to just click around, but if you haven’t got it installed and need to use commands, here they are.
    1. Login to MySQL:
      mysql -u root -p
    2. Create database (replace wordpress_db with your desired database name):
      create database wordpress_db;
    3. Create user and grant him all privileges to access and modify the database (replace wordpress_user and wordpress_pass with your desired username and password respectively):
      create user wordpress_user@localhost identified by 'wordpress_pass';
      grant all privileges on wordpress_db.* to wordpress_user@localhost;
    4. You’re done with the database, so exit:
      exit;
  8. Make a copy of wp-config-sample.php and name it wp-config.php in /var/www/yourdomain.com/public_html folder:
    sudo cp /var/www/yourdomain.com/public_html/wp-config-sample.php /var/www/yourdomain.com/public_html/wp-config.php
  9. Open wp-config.php and modify the following lines:

    define('DB_NAME', 'database_name_here');
    define('DB_USER', 'username_here');
    define('DB_PASSWORD', 'password_here');

    Go to https://api.wordpress.org/secret-key/1.1/salt/ to obtain the secret keys and replace the following lines with those from your browser:

    define('AUTH_KEY', 'put your unique phrase here');
    define('SECURE_AUTH_KEY', 'put your unique phrase here');
    define('LOGGED_IN_KEY', 'put your unique phrase here');
    define('NONCE_KEY', 'put your unique phrase here');
    define('AUTH_SALT', 'put your unique phrase here');
    define('SECURE_AUTH_SALT', 'put your unique phrase here');
    define('LOGGED_IN_SALT', 'put your unique phrase here');
    define('NONCE_SALT', 'put your unique phrase here');

    Save your file.

  10. Now type in this command:
    sudo a2ensite yourdomain.com.conf
  11. Reload your Apache2 service:
    sudo service apache2 reload
  12. You may now access your WordPress site by entering your domain name into your browser! You will see a setup page and just go ahead to get your site ready!

Ta-da you’re done! You may now enjoy the process of selecting an appropriate theme for your WordPress site and designing your website to suit your needs. Have fun! 🙂






Leave a Reply

Your email address will not be published. Required fields are marked *