A Lubuntu LAMP VM

I wrote previously about the pre-made OpenSUSE 10.2 LAMP Server for Windows Virtual PC and it has been helpful in brushing up on command line Linux with a LAMP stack. After playing around it dawned on me that if I had a virtual LAMP server with a more recent version of PHP I could have a development mirror of this WordPress blog. So starting with the Lubuntu VM I created I’ve added a LAMP solution stack and a cloned copy of this blog.

Installing the LAMP Stack

Most of the pages I found about installing a LAMP stack on Lubuntu where very old (in Linux years) so they had far more steps than necessary. The fastest way I found was in a Comment on the Installing LAMP On Ubuntu For Newbies page.

Its really easy to install LAMP with ONE single command in ubuntu:

sudo apt-get install lamp-server^ phpmyadmin

When the installation nears the end you’ll be prompted to do these steps.

  1. Create a password for the MySQL root user.LAMP01_thumb4
  2. Re-enter the MySQL root password.
  3. Press the spacebar to select apache2 then press Enter.LAMP04_thumb1
  4. At the first Configuring phpmyadmin dialog press Enter to select Yes.LAMP06_thumb1
  5. Enter the MySQL root password.
  6. Create a password for phpMyAdmin.
  7. Re-enter the phpMyAdmin password.

DO NOT DO THE FOLLOWING PART of the comment’s instructions! It will cause php5 to attempt to load the module twice because it is already being loaded by the default installation via /etc/php5/mods-available/.

Copy past, and you are set. All you need to do to get started is add


to your /etc/php5/apache2/php.ini file

There was only one step from the how-to Installing LAMP On Ubuntu For Newbies, HowtoForge page that was worth doing. It’s the Test PHP section, here are the commands modified for Lubuntu’s standard programs. Execute the following command to create the file.

gksudo leafpad /var/www/testphp.php

Put this single line of PHP code into the file then save it.

<?php phpinfo(); ?>

Now open a web browser and enter this address, http://localhost/testphp.php, you should see something like this.


Warning this next process is a major security risk!

Fix permissions/ownership to make the default Apache installation easier to work with.

The default installation leaves the web site files owned by root and only writable by root. This is very inconvenient but is important for security if the server will ever be exposed to the internet. Since my server will never be accessible outside of my private LAN I am going for convenience over security.

  1. Add yourself to the group www-data:
sudo usermod -a -G www-data your_username
  • Change ownership of all files & directories under /var/www:
    sudo chown -R your_username:www-data /var/www
  • Change permissions of all files & directories under /var/www:
    sudo chmod -R g+rwx /var/www

To make it easy to change permissions after copying in files from FTP or other methods that don’t give the correct ownership and permissions I created a shell script. To do this create a directory named bin in your home directory, /home/your_username/bin. Then create a file named fix-www.sh in the bin directory containing the following code and make it executable.


echo sudo_password | sudo -S chown -R your_username:www-data /var/www
echo chown complete
echo sudo_password | sudo -S chmod -R g+rwx /var/www
echo chmod complete

Now when you need to fix up the permissions in the web directory you can just run the script.

Testing Features and Fixing Problems

Next we’ll test out phpMyAdmin, enter http://localhost/phpmyadmin in the browser and log in as root with the password you set earlier. Once you’re in phpMyAdmin scroll to the bottom of the page and you’ll see this error message.


To fix this error execute the following command sequence from a terminal window. (I adapted this fix from an ask Ubuntu post)

sudo mv -i /etc/php5/conf.d/mcrypt.ini /etc/php5/mods-available/
sudo php5enmod mcrypt
sudo service apache2 restart

When the final command executes you will see this warning message, if you watched carefully you may have seen it during the installation or if you looked in /var/log/apache2/error.log:

AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using Set the ‘ServerName’ directive globally to suppress this message

As the message says we get rid of this warning by editing the Apache configuration file.

gksudo leafpad /etc/apache2/apache2.conf

At the start of the # Global configuration section add

ServerName localhost

or use your server’s fully qualified domain name like I did.

Since we’ve got the file open already we can add a change that will be needed to enable .htaccess mod_rewrite rules for WordPress permalinks.

Find this section in the file,

<Directory /var/www/>
  Options Indexes
  AllowOverride None
  Require all granted

and change the AllowOverride parameter to All:

<Directory /var/www/>
  Options Indexes
  AllowOverride All
  Require all granted

Now we will enable mod_rewrite with the following command:

sudo a2enmod rewrite

Then restart Apache:

sudo service apache2 restart

When I was checking /var/log/apache2/error.log I also saw this error:

[:error] [pid 7276] [client] PHP Warning:  phpinfo(): It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. … We selected the timezone ‘UTC’ for now, but please set date.timezone to select your timezone. in /var/www/testphp.php on line 1

The solution seemed too obvious and simple (it could have been pre-configured during the install) so I searched around and this page confirmed it really is this simple to correct. I wouldn’t be surprised if some future release of the installer resolves this issue.

Open the configuration file:

gksudo leafpad /etc/php5/apache2/php.ini

Change this section from:

; Defines the default timezone used by the date functions
; http://php.net/date.timezone
;date.timezone =

To this, using your time zone:

; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = America/New_York

Save the file then restart Apache:

sudo service apache2 restart

Checking /var/log/mysql/error.log I saw this warning:

[Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.

Another easy one to fix.

Open the configuration file:

gksudo leafpad /etc/mysql/my.cnf

Change this section from:

# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover         = BACKUP

To this:

# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover-options  = BACKUP

Save the file, reboot the server then check the error log to make sure the warning is gone.

Now that everything is working and all error and warning messages have been fixed it’s time to clone the live blog to the development blog.

Adding WordPress

My first thought was that I needed to install WordPress in the VM. So my first pass followed the instructions from Ubuntu 13.10 » Ubuntu Server Guide » LAMP Applications » WordPress. This got me a working WordPress installation but I never quite worked through how to get a mirror of my live blog working with it.

This was when it dawned on me that there is no need to install WordPress because it is simply a database and collection of PHP code files. So I started down the road of simply copying everything over to the development server VM roughly following the instructions at Moving WordPress and later with these much better instructions, How to Move a WordPress Site from CraniumStorm. I ended up with a functioning mirror but there was an awful lot of hand work involved with many opportunities to do it wrong.

This was when I discovered this post, Quickly Clone and Migrate WordPress Sites with the Duplicator Plugin from WPMU DEV. The post pointed me to this plugin and this article from the creator Do You Localhost Your WordPress?. at the Life in the Grid blog. Here’s my step by step instructions, to me they are much easier, safer and faster than any other method.

  1. Install the Duplicator plugin on the live blog.
  2. Run the Duplicator program on your live blog.
  3. Create a directory in the VM that matches the live version location (/var/www/wordpress for my setup).
  4. Copy the Duplicator files to the VM.
  5. Run your fix-www.sh script or enter the commands manually to set the permissions on the Duplicator files.
  6. Create an empty database with the name you want in phpMyAdmin (I made the name match the name on my live blog).
  7. Run installer.php in the VM. When I ran it I received the following warning.GENERAL WARNINGS:
    MEDIA SETTINGS WARNING: The table ‘wp_options’ has at least one the following values [‘upload_url_path’,’upload_path’] set please validate settings. These settings can be changed in the wp-admin by going to Settings->Media area see ‘Uploading Files’
    I did as instructed and also checked the database row values in phpMyAdmin and found no problem.
  8. Run your fix-www.sh script or enter the commands manually again to set the permissions for the imported files.

Fire up a browser and check the mirror of your blog on the VM. It worked correctly on the first try for me however there are few WordPress setting changes I made.

  • Changed the blog title to My Blog Mirror so that I don’t confuse the two when both are open the my browser.
  • Turned off the Google Analytics for WordPress and Google XML Sitemaps plugins so that my mirror doesn’t interfere with my live blog in Google’s services.
  • Removed http://rpc.pingomatic.com/ from Writing Settings -> Update Services.
  • Unchecked Attempt to notify any blogs linked to from the article & Allow link notifications from other blogs (pingbacks and trackbacks) in Discussion Settings -> Default article settings.
%d bloggers like this: