Monday, April 04, 2011

Rackspace Step 3: Creating the LAMP Server

In the past there was usually a number of steps to set up an Ubuntu cloud based LAMP server. This can also be done using a single command. However you install the AMP on your Ubuntu (Linux) Server one important thing to remember is to install the php-mysql package after mysql. Usually installation takes the following steps;
  1. Install Apache
  2. Install MySQL
  3. Install PhP
All of these steps can also be completed with a single command of;
# sudo apt-get install lamp-server^


After running the apt-get command you will need to reboot the server to finish the install and preform a couple of tests to check everything is working. First test would be to point your browser at the ip address of your new server; if apache was installed correctly you should get the following web page;


Once you have confirmation of the apache web server working you should then check the php and mysql features are also working. Creating a simple html / php script will help with this;

<html>
<body>
The Apache2 server works!</br>
<?php
print "PhP5 is working!</br>";
$usr = "username";
$pwd = "password";
$hst = "localhost";
$dbms = mysql_connect($hst, $usr, $pwd) or die("Unable to connect to MySQL");
print "Connected to MySQL!</br>";
mysql_close($dbms);
?>
</body>
</html>
Save a similar section of code with your MySQL username and password to a file with the .php extension in the root directory of your web server (should be /var/www) and point your browser at this new file. If all goes well you should get the following lines displayed in your browser. Congratulations, you have a running LAMP server (In a coming post I will talk about securing PhP and mySQL).

The Apache2 server works!
PhP5 is working!
Connected to MySQL!
Again, this would be an opportune time to do a complete backup of your LAMP server so you have an image to restore from as you continue in setting up your new server.

No comments: