Installing WordPress in Ubuntu

WordPress is the most popular blogging platform on the Internet. According to some statistics, WordPress powers up about 25% of all websites on the web, so if you are planning to start a blog or a website, you can’t go wrong with WordPress.

There are many ways of installing WordPress, some web hosting providers even offer a one click install option, but in this tutorial I will guide you step by step on how to manually install and configure a WordPress site using Ubuntu as a server.

Prerequisites

In this guide I assume you already have an Ubuntu server installed with SSH access to it. The latest LTS Ubuntu release at the time of this writing is 14.04. the latest WordPress release at the time of this writing is 4.4.2 If you already installed Apache, MySQL and PHP5 on the server, make sure PHP 5.6 MySQL 5.6 or higher are installed on the server to successfully complete this tutorial.

Installing the LAMP stack

If you haven’t installed Apache, MySQL and PHP5 yet, the easiest way to install the whole stack in Ubuntu is using the “tasksel” script.  On your terminal type “sudo apt-get install tasksel and then type sudo apt-get update && sudo tasksel install lamp-server

enter a MySQL password when prompted:

image

After the installation is done. type in the IP address of your server in a browser, and you should get the apache default web page letting you know that apache was successfully installed:

image

Setting up the VirtualHost

I assume you will be hosting multiple websites from your server, so we need to create a VirtualHost for your WordPress website or bog. VirtualHosts are located at this path on your server /etc/apache2/sites-available so lets create a virtual host based on your website name. for example I will name my VirtualHost  “forevergeeks.conf”

Using nano editor create it: sudo nano /etc/apache2/sites-available/forevergeeks.conf and then put the following in it:

<VirtualHost *:80>
        ServerAdmin youremailaddress.com
(type your email address here )
        ServerName forevergeeks.com ( type the name of your domain here )
        ServerAlias www.forevergeeks.com (type your domain alias here )
        DocumentRoot /var/www/wordpress ( your wordpress directory )
        <Directory />
                Options -Indexes
                AllowOverride All
        </Directory>
        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory “/usr/lib/cgi-bin”>
                AllowOverride All
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>
        ErrorLog ${APACHE_LOG_DIR}/error.log
        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    Alias /doc/ “/usr/share/doc/”
    <Directory “/usr/share/doc/”>
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>
</VirtualHost>

Change all the information on the virtualhost above to reflect yours, and then save the file, and exit To activate the VirtualHost type sudo a2ensite nameofyourvirtulahost on your terminal. For example my command was sudo a2ensite forevergeeks.conf  and then reload Apache sudo service apache2 reload

Creating the database

Login to your MySQL server and create the database. type mysql –u root –p to login, and create the database using this command: create database wordpress ;

if you need to create a new user to use with this database, run these commands:  CREATE USER ‘newuser’@’localhost’ IDENTIFIED BY ‘password’;

for example, my command looked like this: CREATE USER ‘forevergeeks’@’localhost’ IDENTIFIED BY ‘forevergeeks’;

Grant this user full permissions to the WordPress database:

GRANT ALL PRIVILEGES ON databasename.* TO ‘user’@’localhost’;

for example my command was:

GRANT ALL PRIVILEGES ON wordpress.* TO ‘forevergeeks’@’localhost’;

Type FLUSH PRIVILEGES; then exit.

Downloading WordPress

Let’s download the latest WordPress file. from your server type this cd /var/www/ && sudo wget https://wordpress.org/latest.zip then type sudo apt-get install unzip && sudo unzip latest.zip

Now if you do ls on your terminal, you should see a wordpress directory:

image

Installing WordPress

Give the web server full access to the WordPress web root directory sudo chown -R www-data:www-data /var/www/wordpress/  Type the name of your site on your browser, and the WordPress setup page should come up””

image

click on Let’s go!

Type the name of the database the User Name and the password of your MySQL server on the next screen:

image

Alright sparky, run the installer:

image

Type the Site Title the Username and password  for your website on the next screen.

image

Success, your WordPress has been installed!

image

Setting up Permalinks

The First thing you should do when you login to your WordPress site is changing the permalinks structure of your site. To do that, click on Settings then click on “Permalinks” you can choose any permalink structure you like. for forevergeeks.com, I use the Post name permalink:

image

One thing you will notice when you use the Post name permalink is that when you try to open a page on your site, you get the error The requested URL was not found on this server.

image

The reason you get that error is because the Mod_rewrite module is not enabled on your server. Enable it by typing this on terminal Sudo a2enmode rewrite then restart apache sudo service apache2 restart . Now check your site and see if the permalinks are working. if you continue getting the error page not found then change this setting on your apache configure file: sudo nano /etc/apache2/apache2.conf and find this piece <Directory /var/www/> And make sure the AllowOverride directive is set to All. Reload apache and the permalinks should work now.

Installing Themes

There are thousands of free themes that you can install within WordPress. to install a a theme, just click on Themes and then Add new:

image

Browse through the bazillion themes available. once you find a theme you like, click on it and then click on Install:

image

then click on Activate after the theme is installed:

image

Installing Plugins

Installing Plugins in WordPress is almost the same as installing themes. click on Plugins then click on Add New:

image

Then click on the Plugin you want to install, and click on Install Now then activate it after it is installed.

The Must have Plugins for your WordPress site:

WP Fastest Cache This plugin makes your website faster because it generates static html files from your dynamic WordPress site

Yoast SEO This plugin help you optimize your WordPress site for Search Engines

JetPack Jetpack simplifies managing WordPress sites by giving you visitor stats, security services, speeding up images, and helping you get more traffic. Jetpack is a free plugin.You can find and install all these plugins from the repository in WordPress

Conclusion

As you can see, installing and configuring WordPress in Ubuntu is quick and simple. If you have any question or problem that you need help with, please use the comment section below.


More WordPress Tutorials