LAMP Stack Install

Sep 29 2011 11:27 PM SEP 29 2011 11:27 PM
Setting up a LAMP environment.Apache | PHP | MySQL | Ubuntu

Recently I got curious and adventurous into setting up a Virtual Environment on my Mac's VMware Fusion with Ubuntu, Apache, MySQL and PHP. As a Web Developer I often find little need to be a Sysadmin and spend WAY more time developing. It may come as a shocker but its often not a required effort to need to have the knowledge now days of how to setup the environment I work in! An analogy behind this is a mechanic doesn't necessarily build cars, but rather fixes them. While they may understand the details behind it they may have never put a car together from start to finish, but if they had to they could...

So I figured I would post a little bit about what I did to get it going. Because this was my first run of doing this it took a little longer than it should have. But now that I have gone through it I could probably do it as fast as my machine can download.

L - Firstly the easiest thing in the world is getting the "L" done in your LAMP environment. I went with the easiest and "free" route. Ubuntu. Now because I am running a virtual environment VMware Fusion it basically handles the install of the Linux portion. 

- Apache is easy install - in your terminal run:

sudo apt-get apache2
sudo /etc/init.d/apache2 restart

Apache has to be restarted to run... To test the installation open a web browser and run.

http://localhost OR 127.0.0.1 "Mine happend to be 127.0.1.1"

Changing the directory were you host the files is also relatively simple. 

nano /etc/apache2/sites-available/default

Change the DocumentRoot to the path where your website files are living. Also make sure the "Directory" tag has the same path also. Once done ctrl+x and save out. After that you will need to restart apache.

sudo /etc/init.d/apache2 restart

M - MySQL initially is an easy install. It requires one more step here and thats setting a root password so you can login and make change additional users and such...

sudo apt-get install mysql-server mysql-client

After this you will be prompted to enter a root password for the MySQL root user.

New password for the MySQL "root" user: <-- yourrootsqlpassword
Repeat password for the MySQL "root" user: <-- yourrootsqlpassword

Depending on the route you go other install methods make you log into MySQL to change the password. Note initially the root password is not set in MySQL and is blank. In the event you do not get prompted follow this other method:

mysql -u root
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('yourpassword');

P - PHP is also a easy install.

apt-get install php5 libapache2-mod-php5
/etc/init.d/apache2 restart

Once done you should be able to run a test with PHP. However, MySQL may need to be configured with PHP. This is where the it can be a little bit of a pain. You will need to first check and see if the 'extension_dir' lines up correctly with the mysql(i).so file in your php.ini file. This path needs to match exactly otherwise MySQL will not appear to be installed. Firstly lets look for the mysql.so or mysqli.so file.

One of the sites I used to help me walk through this recommended using:

locate mysql.so

Unfortunately for me this did not work and sure I could have used grep to find it. Best place to start is:

/usr/lib/php5/

My mysql.so happened to be in a strange looking directory called: "20090626+lfs". So now that you have located your mysql.so you should then open your php.ini and check for the 'extension_dir' to see if they match.

gksudo "gedit /etc/php4/apache2/php.ini"

Once done you will need to restart your apache again. And then you can go through and do some testing.

sudo /usr/sbin/apache2ctl start
sudo /usr/sbin/apache2ctl stop
sudo /usr/sbin/apache2ctl configtest
sudo /usr/sbin/apache2ctl restart

With the above you should have successfully installed LAMP Stack. While you can do much more configurations I decided to keep this simple. 

Please note this is more of a quick overview of the process. There are WAY more detailed tutorials out there. Not to mention even faster methods than what I have describe above. I wrote this more of a summary of what I did to get my environment done. 

Other Sources and Sites:

https://help.ubuntu.com/community/ApacheMySQLPHP

http://www.howtoforge.com/installing-apache2-with-php5-and-mysql-support-on-ubuntu-11.04-lamp