How to optimize WordPress with Ubuntu VPS

Ubuntu Virtual Private Server optimized for WordPress

Category: Basic install

  • How to add a new virtual host on Ubuntu and Apache cheat sheet

    Configure the domain name

    Configure and test that your domain name really points to your server.

     

     

     

    Create the MySQL database on Amazon RDS

    A fast and easy tool to create a new MySQL database on Amazon RDS is the free MySQL Workbench

     

     

     

    Create root folder

    NB: Replace example.com with your domain

    cd /var/www/

    Then create the domain

    mkdir example.com

    Change to the root folder

    cd /var/www/example.com

     

     

     

    Create Apache virtual host

    cd /etc/apache2/sites-available

    Use a old config file as a template

    sudo cp 01-existing-domain.com.conf 02-example.com.conf

    Open the new config file to edit

    sudo nano 02-example.com.conf

    Replace all occurrences of existing-domain.com with example.com

    Activate the new configuration file

    sudo a2ensite 02-example.com.conf

    Restart Apache to activate the new virtual host

    sudo service apache2 restart

     

     

     

    Install WordPress

    Update WP-CLI

    wp cli update

    Download wordpress

    wp core download

    Generate the config file named wp-config.php

    NB: Replace: dbname, user, dbpassword and dbhost with your values.

    wp core config --dbname=wordpress --dbuser=user --dbpass=password --dbhost=dcfgvr.1bagob.0002.euw1.cache.amazonaws.com --dbprefix=wp_ --skip-check

    Install WordPress

    NB: Replace URL, Blog Title, adminuser, password, and e-mail with your values.

    wp core install --url="https://www.example.com" --title="Blog Title" --admin_user="adminuser" --admin_password="password" --admin_email="email@domain.com"

     

     

     

    Change file and folder permissions

    NB: Replace “/var/www/html/” with the path to your root folder.

    sudo chown -R www-data /var/www/html/ && sudo chgrp -R www-data /var/www/html/ && sudo find /var/www/html/ -type f -exec chmod 644 {} \; && sudo find /var/www/html/ -type d -exec chmod 755 {} \; && sudo chown www-data:www-data -R /var/www/html/ && sudo usermod -aG www-data ubuntu && sudo chmod -R g+w /var/www/html/ && sudo chmod 660 /var/www/html/wp-config.php

    Test that everything works correctly.

  • How to install WordPress through command-line with WP-CLI

    Setting up WordPress using the command line is fast.
    You can even use a script to automate the process.

    Home » WordPress » Basic install

    Prerequisites and preparations

    Before you begin. Create a MySQL database in Amazon RDS. You also need a working website. Then start creating a list with the following information:

    • Name of your Amazon RDS MySQL database server
    • Database name
    • Database username
    • Database user password
    • The WordPress admin username you intend to use
    • The WordPress admin password you intend to use
    • The WordPress admin e-mail address you plan to use

    If some points are unclear these how-tos should point you in the right direction:
    How to install WP-CLI

    How to set up a virtual host

    How to activate .htaccess

    How to create a MySQL database in Amazon RDS

    Verify the root folder

    Your root folder is beneath

    /var/www/

    In this tutorial are we going to install WordPress in the folder

    /var/www/MyDomain1.com

    Start with going to the root folder:

    cd /var/www/MyDomain1.com

    Verify that there are no files in this folder

    sudo ls

    If here is index.html or another start page file there you should delete this file to avoid problems later on.

    sudo -u www-data rm index.html

    Change ownership and delegate permissions

    The Apache web server needs permission to run WordPress.

    sudo chown -R www-data /var/www/MyDomain1.com

    Download the installations files

    Downloading all the WordPress files is done in a matter of seconds by issuing this command:

    wp core download
    
    

    Create wp-config.php, the main configuration file

    Sometimes WP-CLI is unable  to connect to Amazon RDS MySQL database. Then you can skip the database test by adding the following statement:

     --skip-check

    Creating the configuration file in WordPress. Fill in the values from the list you created previously:

    wp core config --dbname=wordpress --dbuser=user --dbpass=password --dbhost=dcfgvr.1bagob.0002.euw1.cache.amazonaws.com --dbprefix=wp_ --skip-check

    Install WordPress

    wp core install --url="https://www.example.com" --title="Blog Title" --admin_user="adminuser" --admin_password="password" --admin_email="email@domain.com"

    Check the server error logs

    It’s a good practice to examine the error logs. They are here:

    cd /var/log/apache2/
    sudo nano error.log
    sudo nano 01-mydomain1-com-error.log

    Set correct permissions so Apache can access the files and folders

    Basic permission:

    sudo chown -R www-data /var/www/MyDomain1.com

    More thorogh guide on setting permissions is available her: