Linux Powered By Azure – Turn on the LAMP

Welcome to part 2 of this series entitled, Linux Powered by Azure (#poweredbyazure).  In the previous tutorial we stood up an Ubuntu virtual machine and connect to is securely through SSH by creating a private and public key pair using openssl. The server is up and running but is not really configure to do anything. In this tutorial we will look at filling out the LAMP stack (Linux, Apache, MySQL, PHP)

Some requirements:

  • Azure subscription is needed. If you do not have one, please sign up for a free trial.
  • A computer to connect to the internet and run command line utilities.
  • I will be using a Mac to show how this is done, however the same mechanics can be applied to running other OS’s except for a few steps which I will point out.
  • Completion of the first part of the series


Installation of Apache

After we tested our connection in the prior tutorial, we issued an update command using Ubuntu’s package manager. If you did not do that please issue the following command:

  • sudo apt-get update

This will update any packages and dependencies that are needed to continue.

Once that is comple we need to install Apache

  • sudo apt-get install apache2

After about 30 seconds, Apache should be installed. We now need to log back into our Azure control panel and open up an endpoint so that Apache can serve traffic coming through port 80.

Find your Virtual Machine and choose Endpoints from the dashbaord overview page. From the bottom of the page choose “Add”. The first screen is asking if it is part of a load balanced set, but in our case it is not, so just click next.

Then you can scoll through the list of perdefined endpoints and choose HTTP. This will populate the boxes with the appropriate information.


Click ok and wait until the server is finished configuring itself.

Once complete, you should be able to open up a web browser and access your server via DNS. You should see the following screen:


Installation of MySQL

We completed the L and the A now lets work on the M.

Installation is straightforward like Apache. We will be issuing the following commands

  • sudo apt-get install mysql-server php5-mysql

If you notice, we are installing the server and some thing for php. This is a helper package that will assist us getting other components to communicate with each other later on.

A fancy looking prompt will appear asking for a root password for MySQL. It is highly reccommend you add one. Be sure to write it down, it is a pain to recover if lost.


Once the installation is complete we need to issue a few more commands. The first is a shell script that will set up some system tables and a data directory.

  • sudo mysql_install_db

The other command removes some test databases and some remote access. It is a good idea to lock the database down so running this script makes sense.

  • sudo mysql_secure_installation

It will prompt you for your password, if you dont want to change it hit No. The other prompts you can just hit ENTER to accept the default which is removing most of the items.

At this point we are running a MySQL DB. You can test it out by issuing the following commands:

  • mysql -u root -p

Now you are in! Issue the command exit; to leave.

Installation of PHP

Almost done! L A M now we need the P for PHP.

At a command prompt we need to issue the following to install PHP, Apache Helper for PHP and a crypto package for PHP.

  • sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt

PHP should be installed now but there are a few tweaks we can make to Apache. First, lets make sure PHP is running correctly. In order to do this we need to create a php file with a function in it.

  • Go to the /var/www/html directory and create a new file
  • sudo vi info.php
  • You can use the editor of you choice.
  • Within the file add the following snipped of code
  • <?php phpinfo(); ?>
  • Save the file and load up that url in your web browser
  • php-step-1
  • PHP is Running!!!

Now there are all sorts of tweaks you can do to get PHP really running but I am only going to do a few that are necessary.

Index.php file:

  • In /etc/apache2/mods-enabled/dir.conf there is a list of the order to process files. Index.php is towards the back.
  • Edit that file and move index.php so that it is the first one.
  • Make sure you restart the server by: sudo service apache2 restart

Other PHP Packages

  • Issue the command apt-cache search php5-
  • This will list all php5 packages that are available. curl, Oauth, json..all could be installed if needed.

Well, for now we are done. We completed the LAMP stack installation.

Next up installing WordPress.