Ubuntu 14.04 – From Apache2 till Wordpress

Construct a WordPress site on an Ubuntu 14.04 machine with eyes closed


We will use the linux command line as root user to input our commands so…

sudo -i


su -


Apache2 and php5 installation

apt-get install -y apache2 php5 libapache2-mod-php5

Xcache is a free and open PHP opcode cacher for caching and optimizing PHP intermediate code. It’s similar to other PHP opcode cachers, such as eAccelerator and APC. It is strongly recommended to have one of these installed to speed up your PHP page.

apt-get install -y php5-xcache

MySQL and php5 installation

For the next keep in mind that you’ll be asked for the database’s root user password[1].

apt-get install -y php5-mysql mysql-server mysql-client

Php5 needed modules installation

Useful commands:

  • Shows all the packages that contain the letters php5: apt-cache search php5 | awk '{print $1}' | sort | column
  • Shows all the packages that are installed and contain the letters php5: dpkg -l *php5* | awk '/^ii/ { print $2 }' | sort | column
apt-get install -y php5-curl php5-gd php5-imagick php5-intl php5-mcrypt php5-memcache php5-sqlite php5-tidy php5-xmlrpc php5-xsl php-pear

phpMyAdmin installation

apt-get install -y phpmyadmin apache2-utils

You’ll be asked which web server to reconfigure automatically?. Choose apache2.
Next, you’ll be asked if you want to configure database for phpmyadmin with dbconfig-common?. Choose No.
Useful link(s): phpMyAdmin Documentation, phpMyAdmin Documentation (beta version)

Test the installation procedure till now

Open your browser and check that the following url are working.


Use the username root and the password you specified to login to phpMyAdmin enviroment. Note that phpMyAdmin gives an error message saying that: The mcrypt extension is missing. Please check your PHP configuration which is weird to me because for Ubuntu Linux it’s already in the file /etc/php5/conf.d/mcrypt.ini. Anyway, to correct this edit the file php.ini with the command:

vi /etc/php5/apache2/php.ini

Add the following line at the Dynamic Extensions section.


As Unixmen suggests in the article “How To Install WordPress In Ubuntu 14.10”: Search for the expose_php directive and the allow_url_fopen directive and set them both to “Off”.

. . .
expose_php = Off
. . .
allow_url_fopen = Off
. . .

Save the file and restart apache2 web server with the command:

service apache2 reload


WordPress installation

apt-get install -y wordpress

Useful link(s): Official Ubuntu Documentation – WordPress

WordPress config file

Edit the configuration file with the command:

vi /etc/wordpress/config-localhost.php

and copy-paste the followings:

CAUTION: Change the values that I recommend to change with the prompt:
*** USE YOUR OWN ***


// ** MySQL settings - You can get this info from your web host ** //
/** MySQL hostname */
define('DB_HOST', 'localhost');

 * The name of the database for WordPress
 *** USE YOUR OWN ***
define('DB_NAME', 'wordpressdb');

 * MySQL database username
 *** USE YOUR OWN ***
define('DB_USER', 'wordpressuser');

 * MySQL database password
 *** USE YOUR OWN ***
define('DB_PASSWORD', '12345678');

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');

 * Authentication Unique Keys and Salts.
 * Change these to different unique phrases!
 * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ secret-key service}
 * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
 * @since 2.6.0
 *** USE YOUR OWN ***
 * Get your own salt here: https://api.wordpress.org/secret-key/1.1/salt/ ***
define('AUTH_KEY',         '454jHWA7 4DNGF|flOK!M&gZpnNg/5n0+$P Go17FhjP-il6oMem3ABo%~+2N8v|');
define('SECURE_AUTH_KEY',  'd?kyI)1-Z;H|:|s;|}#n>6T/{*jj/:wrRgW_u[U81d/%u`f||W|KIB?JK]>_Rloe');
define('LOGGED_IN_KEY',    'WIt!$7%/)qs V1=X*x9xO<!Ku#<(7e,[}|e-XumpT9?%_b6 ;_g+AAe^TS:THPER');
define('NONCE_KEY',        'YqNZRpyT3sjI1;)+-mJ!UcsT|s|K$UZfn!XSsJ7M;NCE<xo]H~s6UQX]_%.(hqv+');
define('AUTH_SALT',        'hW<;S|9L-XP+mi!vbmE-4aMI3.CHW=,7uHL,Q{EPm`lSX>QuYl/+=ubYM3;U2Hnf');
define('SECURE_AUTH_SALT', 'YGzj7{}{h&ZMys/ZB)Vq#@J03Jh&)8xmn%IWF#|K+7mtELFlfu(3fa5A&y{Un464');
define('LOGGED_IN_SALT',   'Ar/Nd.(S3lxuNcMd}bI|m]<h,S$ql3Vu1kvFVl3_-}8Tns&`1FD}f+sz3i7?7C.;');
define('NONCE_SALT',       'Sp:ARq;u+88$Ll=c$lEyg.Q/g|io,3=G??SB$j()!{pg2 .YwWr_TAo[o<A?(+!{');

 * WordPress Database Table prefix.
 * You can have multiple installations in one database if you give each a unique
 * prefix. Only numbers, letters, and underscores please!
 *** USE YOUR OWN ***
$table_prefix  = 'wptbl_';

 * WordPress Localized Language, defaults to English.
 * Change this to localize WordPress. A corresponding MO file for the chosen
 * language must be installed to wp-content/languages. For example, install
 * de_DE.mo to wp-content/languages and set WPLANG to 'de_DE' to enable German
 * language support.
define('WPLANG', '');
 * Download files http://el.wordpress.org/
 * define('WPLANG', 'el');

 * Single-Site (serves any hostname)
 * For Multi-Site, see: http://www.turnkeylinux.org/docs/wordpress/multisite
define('WP_SITEURL', 'http://'.$_SERVER['HTTP_HOST']);
define('WP_HOME', 'http://'.$_SERVER['HTTP_HOST']);


Permalink Settings

If we want to use permalinks like e.g. Post name we must enable the rewrite apache2 module. To do so issue the commands:

chown www-data /etc/wordpress/htaccess
a2enmod rewrite

WordPress database creation

Next we’ll build the WordPress database using the info that we’ve input in the WordPress config file.

First login as root user in our dbms with the command:

mysql -u root -p

Input the root user’s password and then issue the following commands

MySQL commands

We’ll create a database named wordpressdb for the db-user wordpressuser and give him the 12345678 password. You *** MUST *** type your own.

CREATE DATABASE wordpressdb;
ON wordpressdb.*
TO wordpressuser@localhost
IDENTIFIED BY '12345678';

Apache2 web-root folder configuration

Create a file named wordpress.conf under the /etc/apache2/sites-available/ directory with the command:

# cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/wordpress.conf
vi /etc/apache2/sites-available/wordpress.conf

Then copy-paste the following lines:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /usr/share/wordpress
        Alias /wp-content /var/lib/wordpress/wp-content

        <Directory /usr/share/wordpress>
                AllowOverride Limit FileInfo
                DirectoryIndex index.php
                Options FollowSymLinks MultiViews
                Order allow,deny
                Allow from all

        <Directory /var/lib/wordpress/wp-content>
                DirectoryIndex index.php
                Options FollowSymLinks
                Order allow,deny
                Allow from all

        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

# Tell something about AllowOverride Limit FileInfo
Save and exit the editor.
Then edit the file apache2.conf in order to comment out the <Directory /> directive under the default security model section.

vi /etc/apache2/apache2.conf

Final and most important steps

Set the required permissions

chown -R www-data:www-data /usr/share/wordpress
find /usr/share/wordpress -type f -exec chmod 0644 {} \; && find /usr/share/wordpress -type d -exec chmod 0755 {} \;
chown -R www-data:www-data /var/lib/wordpress/wp-content
find /var/lib/wordpress/wp-content -type f -exec chmod 0644 {} \; && find /var/lib/wordpress/wp-content -type d -exec chmod 0755 {} \;

Enable the site

a2dissite 000-default
a2ensite wordpress

Restart the Apache2 web server

service apache2 reload

Ready to Rock ‘n’ Roll

Login and curate your site:



Our website from outside

Suppose that we want access this website either from our intranet using an ip address e.g.,, or from everywhere using a domain name we own e.g., wordpress.example.com . We have to issue a command like this:

cp /etc/wordpress/config-localhost.php /etc/wordpress/config-

…or this respectively:

cp /etc/wordpress/config-localhost.php /etc/wordpress/config-wordpress.example.com.php

Finally, don’t forget to make the proper ip forwarding settings to your router.

Themes folders

I found very annoying the fact that the default themes folders are links from the /usr/share/wordpress/wp-content/themes/ directory to /var/lib/wordpress/wp-content/themes/ directory. So I’d suggest the followings:

find /var/lib/wordpress/wp-content/themes -type l -exec unlink {} \;
mv /usr/share/wordpress/wp-content/themes/* /var/lib/wordpress/wp-content/themes/

After a WordPress package update from Ubuntu repos

If you have problems updating WordPress themes, plugins etc after an Ubuntu update you should issue the command:

chown -R www-data:www-data /usr/share/wordpress

Nowhere else to go

Configure Per-user web directories

Suppose that we have a user named john and we want to have his own web-root under the directory ~/public_html. To allow this feature issue the commands:

a2enmod userdir
sed -i '/php_admin_value/s/^/#/' /etc/apache2/mods-enabled/php5.conf
service apache2 reload
# ln -s /usr/share/wordpress /var/www/wordpress

5 thoughts on “Ubuntu 14.04 – From Apache2 till Wordpress

  1. This tutorial messed up the installation. “ERROR: The themes directory is either empty or doesn’t exist. Please check your installation”. By default it will install wordpress 3.6.1 (which is outdated) and you have no option to upgrade to 3.7.1 (current version) because it says it is up to date. Still can’t find theme directories. Completely confusing tutorial.

  2. you just replied to a spam bot ;oP

    could you explain a bit more about this?
    it’s rather unclear as to which part you infer

    “Then edit the file apache2.conf in order to comment out the directive under the default security model section.”

    This is what I have in my setup – please correct if need be – thanks

    # Sets the default security model of the Apache2 HTTPD server. It does
    # not allow access to the root filesystem outside of /usr/share and /var/www.
    # The former is used by web applications packaged in Debian,
    # the latter may be used for local directories served by the web server. If
    # your system is serving content from a sub-directory in /srv you must allow
    # access here, or in any related virtual host.

    Options FollowSymLinks
    # AllowOverride None
    AllowOverride All
    Require all denied

    AllowOverride None
    Require all granted

    # Options Indexes FollowSymLinks
    Options FollowSymLinks
    # AllowOverride None
    AllowOverride All
    Require all granted

    # Options Indexes FollowSymLinks
    # AllowOverride None
    # Require all granted

    • Thanks for your comment/hint, I corrected my bot-reply-mistake but
      in my humble opinion it’s better for me to use the directives per VirtualHost rather than the globals in the file apache2.conf
      Thank you

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s