Installation

MySQL

Install MySQL from source:

sudo apt-get install mysql-server php5-mysql
sudo mysql_install_db
sudo mysql_secure_installation

Enter MySQL CLI:

mysql -u root -p

Create DB and user:

mysql> CREATE DATABASE wordpress;
Query OK, 1 row affected (0.00 sec)

mysql> CREATE USER username@localhost;
Query OK, 0 rows affected (0.00 sec)

mysql> SET PASSWORD FOR username@localhost= PASSWORD("***");
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON wordpress.* TO username@localhost IDENTIFIED BY '***';
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

(Optional) Show DB/User:

mysql> SHOW DATABASES;
+```````````````+
| Database           |
+```````````````+
| information_schema |
| mysql              |
| test               |
| wordpress          |
+```````````````+
4 rows in set (0.00 sec)

mysql> SELECT User,Host FROM mysql.user;
+`````````---+````````````--+
| User          | Host             |
+`````````---+````````````--+
| root          | 127.0.0.1        |
|               | default.hostname |
| root          | default.hostname |
|               | localhost        |
| root          | localhost        |
| wordpressuser | localhost        |
+`````````---+````````````--+
6 rows in set (0.00 sec)

(Optional) Delete a DB/User:

mysql> DROP DATABASE IF EXISTS [Database];
Query OK, 0 rows affected (0.00 sec)

mysql> DROP USER [User]@localhost;
Query OK, 0 rows affected (0.00 sec)

PHP

Install PHP from source:

sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt
sudo nano /etc/apache2/mods-enabled/dir.conf

Adjust the index.php as the following order:

<IfModule mod_dir.c>
    DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>

Wordpress

Download:

cd /var/www/html/
wget http://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
cd wordpress
cp wp-config-sample.php wp-config.php

Configure wp-config.php:

define( 'FS_METHOD', 'direct' );
define('WP_HOME','http://localhost/wordpress');
define('wordpressURL','http://localhost/wordpress');

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');

/** MySQL database username */
define('DB_USER', 'root');

/** MySQL database password */
define('DB_PASSWORD', '***');

Change the permission:

cd /var/www/html/wordpress
sudo chown -R root:www-data *
mkdir wp-content/uploads
sudo chown -R :www-data wp-content/uploads
chmod -R 777 wp-content/

Create .htaccess file at /var/www/html with:

cd /var/www/html/wordpress
nano .htaccess

Change Permalink:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Test WordPress: http://localhost/wordpress

Setting Virtual Host for WordPress Website

WordPress Configuration

Edit the wp-config.php:

nano /var/www/html/wordpress/wp-config.php

Add the following rules:

define('WP_HOME','myWordpressWebsite.org');
define('WP_SITEURL','myWordpressWebsite.org');

Make sure the .htaccess file is configured as follow:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Apache Virtual Host Configuration

Create a configuration file:

cd /etc/apache2/sites-available/
nano myWordpressWebsite.org.conf

Configure the localhost, here is an example:

<VirtualHost *:80>
        ServerName myWordpressWebsite.org.org
        ServerAlias www.myWordpressWebsite.org.org
        ServerAdmin admin@example.com
        DocumentRoot /var/www/html/wordpress
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Link the file:

cd /etc/apache2/sites-enabled
ln -s /etc/apache2/sites-available/myWordpressWebsite.org.conf ./myWordpressWebsite.org.conf

Enable the virtual host:

sudo a2ensite myWordpressWebsite.org.conf

Test the Website at myWordpressWebsite.org

Q&A

For example:

Not Found

The requested URL /about/ was not found on this server.

Apache/2.4.7 (Ubuntu) Server at localhost Port 80

Solution: Edit .htaccess:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /subdirectory/
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /subdirectory/index.php [L]
</IfModule>
# END WordPress

Edit apache configure file /etc/apache2/apache2.conf and add the following content:

<Directory /var/www/html/wordpress>
        Options FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>

Reference

Correct file permissions for WordPress

How To Set Up Apache Virtual Hosts on Ubuntu 14.04 LTS

Changing The Site URL