This post is designed for those of you who have some experience working on webpages, but may not have a lot of background with actually setting up the webserver itself. Basically, if you want to setup a quick webserver (perhaps on a spare computer for testing), this will get things started. This will not tell you how to install Ubuntu (okay, I lied: put in the CD, boot from it, double-click the install icon, BAM!) This tutorial makes use of the
apt-get install X command (and may be useful for Debian and Debian-based Linux installs). As always, what works for me might give you the plague…
Most of these commands have to be input into the terminal as the “super user,” which means you will have to put
sudo in front of a command if you don’t have proper permissions. In other words, instead of
apt-get install NEWPACKAGE, you would run
sudo apt-get install NEWPACKAGE. If you try any of these directions and have permission problems, it’s probably something that needs to be done as the super user. The terminal can be opened via the Accessories folder in the Application menu, via shortcut (System, Preferences, Keyboard Shortcuts), or you can switch to a terminal if you must (CTRL+ALT+F1-F6, F7 returns to the desktop). I personally setup a shortcut, because terminal is something you should be using a lot in Linux.
Okay, here it is, get ready…
apt-get install apache2 php5 libapache2-mod-php5 Run that command (using
sudo if necessary) and pretty much everything will be done for you. Your root web directory will be
/var/www, which can be accessed via 127.0.0.1 (or “localhost”) in a web browser. You can also create a
public_html folder in your home directory (type
mkdir public_html). Then you can access your username files with 127.0.0.1/~USERNAME (or “localhost/~USERNAME”). For detailed information about the install, create a file in one of the web directories with
<?php phpinfo(); ?> as the contents.
If you name it index.php, it will automatically load when you visit that web directory, or you can name it whatever you want (adding a “php” extension so that it is parsed properly). Viewing this file in your browser will tell you a lot about your install. One of the most important things to know is the location of your
php.ini file (it should be
/etc/php5/apache2/php.ini, but might be different). If you open it, you can make any changes you would like (for instance, I maxed out the error reporting since it’s a test machine). You may also want to install specific packages. I do a lot of image manipulation, so I installed the GD library with
apt-get install php5-gd and Linux did the rest. You may also want to install PEAR (php-pear) and others.
If you refresh your phpinfo page, you’ll notice that no info is listed about GD (and no php.ini changes show up). Simply restart the web server (
/etc/init.d/apache2 restart) and refresh the phpinfo page.
That should be all you need to know to get started, but you may want to play around some. You may also need or want additional software, perhaps MySQL (
apt-get install mysql-server mysql-client php5-mysql) and PHPMyAdmin (
apt-get install phpmyadmin). Fortunately, the Internet is a vast resource. Put it to use!