Building A Lamp Stack On Ubuntu

Installing the LAMP stack (Linux, Apache, MySQL, PHP) is extremely simple in Ubuntu. This article will guide you through building a LAMP server for both development and production environments. I'm assuming Ubuntu Server for production, this means this article will be focused on the command line.

A single command will get your web server up and running.

sudo apt-get install lamp-server^

You'll get a prompt for a MySQL password, enter you password and confirm on the following screen. This should be the only interaction required on your part. Open your browser and type localhost into the address bar. If you get a page saying "It works!" you now have a functioning LAMP server. The remainder of this article discusses advanced installation, much of which centers around my specific needs.

Users

If your in a production environment you will want to add a new user (in development your normal user is fine). This is the user that will be responsible for keeping the web sites and directories up to date. For the sake of this article, we'll call that user production.

sudo adduser production
sudo passwd -l production

I like to keep my web directories on the default Apache path /var/www. This directory is owned by root and since we never want to login as root just to update a web directory, we will change ownership to the production user.

sudo chown production:production -R /var/www /var/www/*
sudo chmod 775 -R /var/www /var/www/*

Apache Modules

Apache modules provide additional functionality for your web applications. My applications tend to utilize the following moduels.

sudo a2enmod headers rewrite ssl env filter
sudo service apache2 restart

Supporting Applications

In addition to Apache modules, we may want to ask the server for even more features. We can install some additional Linux applications to provide these features. My applications tend utilize the following applications.

sudo apt-get install php5-imagick zip mcrypt php5-mcrypt curl php5-curl
sudo service apache2 restart

All of the applications to this point have required no cofiguration. The following applications will require some additional configuration. Thus they are listed seperatly.

Postfix

I like to use postfix to send email via PHP. You could use sendmail but in my experience postfix is a bit faster.

apt-get install postfix

You will get a dialog asking "General type of mail configuration:". Choose the "Internet Site" option.

You will then be asked "System mail name:" Enter the fully qualified domain name (FQDN).

FTP

While I mostly interact with my server over SSH, FTP can be very useful. I'll install ProFTP on my server and Filezilla on my client machine. At this point I can get the best of both worlds, a simple FTP client over an SSH connection. Answer [Y] to all of the questions and choose the standalone option.

apt-get install proftpd

phpMyAdmin

phpMyAdmin is a good, high level tool for managing a MySQL database.

apt-get install phpmyadmin

SSL

See Creating a Self-Signed SSL Certificate on Ubuntu for createing a self signed SSL certificate.


LinkedInGitHubTwitter