Thursday, January 10th, 2008

Apache, MySQL & PHP on Ubuntu

Lately I've been performing lots of fresh system installs, a result of testing my Ubuntu respin. Restoring my personal data after such an install is simple enough, but having to reinstall my Apache, MySQL & PHP set-up requires a little more effort. So, for future reference I've decided to record the process. By following the instructions below I should be able to get my development server up and running within minutes.

AMP install instructions

1. Open a terminal and issue the following command to install the three main packages:

sudo apt-get install apache2 mysql-server php5

This will install the following packages:
apache2 apache2-mpm-prefork apache2-utils apache2.2-common libapache2-mod-php5
libapr1 libaprutil1 libdbd-mysql-perl libdbi-perl libmysqlclient15off libnet-daemon-perl libplrpc-perl libpq5 mysql-client-5.0 mysql-common mysql-server mysql-server-5.0
php5 php5-common

2. Get some additional packages:

sudo apt-get install php-pear php5-gd php5-mysql php5-imagick phpmyadmin

This will install:
libgd2-xpm libmcrypt4 libt1-5 php-pear php5-cli php5-gd php5-imagick php5-mcrypt
php5-mysql phpmyadmin

3. Enable URL rewriting:

sudo a2enmod rewrite

gksudo gedit  /etc/apache2/sites-available/default

Edit line 12 to read, "AllowOverride All". Save and exit.

4. Create a symbolic link to my working directory:

sudo ln -s /home/username/htdocs /var/www/htdocs

5. Finally, restart Apache:

sudo /etc/init.d/apache2 restart

Tagged with: software, ubuntu


4 Responses to “Apache, MySQL & PHP on Ubuntu”

  1. bdam wrote,

    Please use ~ instead of /home/username so we all just can copy&paste the lines

  2. Philip wrote,

    As bdam points out, the command entered at step 4 could be replaced with:

    sudo ln -s ~/htdocs /var/www/htdocs
    

    Either way the end result is the same. Also, it should be noted that "htdocs" is just the name of the directory I use for my website development files. You can name the directory to your liking.

  3. mWm wrote,

    Tnx. Great post. One thing: how can I create files in /var/www without having to be root?

  4. Philip wrote,

    @mWm: This is why I create a symbolic link [step 4] to my working directory under my home directory, it saves me having to move files around the system, plus any changes I make are instantly reflected.

    If you do want to publish directly to your web server's document root you could always try changing the ownership of the directory:

    sudo chown username:username /var/www
    

    However I'm not sure this is such a good idea. Probably a better way to achieve this would be to change the document root listed in the configuration files under /etc/apache2/ to a directory under your home directory.

    Hope this helps :)

Add Your Comment

Use the form below to add your comment. Markdown syntax is available. Note, comments are moderated by me for spam filtering. Alternatively, feel free to contact me privately.