how to install A-M-P on Linux

LAMP is not a program.
It just means that you are using on Linux: the Apache web server, Mysql database, and Php.
You would also have PHPMyAdmin and some other useful tools.

It's easier to do it than it is to write it! But here is a checklist for installing and configuring Apache, MySQL, and PHP on Linux.

1. If Skype is installed, disable ports 80 and 443 in Skype

For some reason the Skype programmers made Skype to start up using ports 80 and 443. These are the ports that your webserver uses! If Skype is using them, your Apache won't work. So we tell Skype not to use those ports.

  1. Start Skype and go to: Tools -> options -> connections
  2. There is a box that is checked, that says 'use port 80 and 443 for incoming connections'
    Uncheck it.
  3. Then quit Skype to make it save that setting.

(You can now restart Skype any time.)

2. Install Apache, PHP, and MySQL

2a. It may already be installed when you installed your Linux.
Try typing at the command line:
locate apache
locate php
locate mysql
locate phpmyadmin

2b. For any that are not found, install them through your Package Manager, or command line apt-get (ubuntu) or yum (fedora/redhat).

3. Test Apache is working

Now open a browser window (FireFox, right?!), and type in the address box:


You should see a web page, with some information about your server. This is showing you an index file in the "document root".

Or possibly you will just see an empty directory if there are no files at all in the directory. Either way, your web server is working.

Congratulations! You have a web server!

"localhost" is the local name of your web server on your computer.
In fact, it is the local name of everyone's own web server on their own computer. It is kind of like "me", or "ང་".
My machine (linux laptop) is also localhost. The Macintosh at NAVA Office is also localhost. Your MSwndws machine is localhost. Your friend's MSwndws machine is localhost too. The server is localhost, and so is the server, and the server, and ... Anyone who has a web server on their machine, their local "domain name" is localhost.

See what happens when the web server is not running:

As root (or with sudo), type httpd -k stop
Now reload that 'localhost' page.
The page won't show, and you should see an error message.
Because the web server (apache) is not running, so it can't "serve" the web page at localhost.

If the page still loads, try shift-reload.
This makes the browser try to get the page from the server, not from its cache.
If it still loads — check your browser settings, (e.g., firefox or msie) and make sure that it is not caching pages.
tools -> options -> ... "always get the newest page" ... something like that

apache is not starting! What to do?

Apache is telling us what is wrong, but where can we see what it is telling us?
Now we need to get to the command line (linux terminal or windows dos prompt) to see what apache is telling us.

  1. In a terminal window, become root, or use sudo, for the following command:
  2. Type httpd -t
    • you will see some output on the screen, telling you if there is some error on some line number.
    • Edit the httpd.conf or virtual hosts file and fix the error.
    • Now try httpd -t again. If no errors, try restarting the server. If errors, try fixing again!

4. Put your website files into the document root folder

On Linux the server usually gets the files from /var/www/. This is called the "document root".

"document root" means, the "root", the topmost folder, where Apache looks for files to serve.
So we say that /var/www/ is the localhost document root.

Go to that folder, you may see an index.php or index.html file.

4a. You can delete all the files in that folder, and put your own website there.

Q. Can i just copy the website folder which has all the folders and files for my website?

A. Copy everything *inside* your website folder — but not the folder itself. Remember that Apache is looking directly into 'www' for an index.html page. You want it to see the index.html of your website, not the folder of your website!

4b. Shift-reload localhost in the browser, and you should see your own website.

4c. This is now where you will work on your website, and view it in the browser, and everything will work just like on the live web server. Actually if you have server-side-includes they won't work yet, but we can fix that!)

Extra – Configure Apache: ssi | document root | virtual hosts

All the below are extra. If you are happy with the way your web server is working, you don't need to do any of the next steps.

To set preferences for Apache web server, we edit a text file called httpd.conf

The httpd.conf file will be in /etc/httpd/conf/

It is a normal text file, and you can edit it in any text editor, such as gedit or vi.

Notice the lines in the httpd.conf file that have a # in the beginning. They are comments. They don't do anything for Apache, but they are very useful to us!
If you read the comments for the part of the file you are are working on, you will slowly gain good knowledge of Apache and all web servers.

Extra: server-side includes

To set up Apache for server-side includes (SSI), we need to edit two places in the httpd.conf file:

1. Search in the file for something that looks like this:
AddOutputFilter INCLUDES .shtml .htm
You can delete the .shtml and .htm you see there.
Add .html at the end of that line. So it will now look like this:
AddOutputFilter INCLUDES .html

2. Then search in the file for a line that begins Options and add +Includes to that line:
Options +Includes

Extra: Changing the document root

You may not want your document root in /var/www/. For example, i like my web folder to be called "websites". No problem! You can make a folder anywhere on your system that you want. Then you tell Apache that the document root is in that folder.

You do this in two places in the httpd.conf file::

    DocumentRoot "/var/www"

and just a few more lines down:

    <Directory "/var/www">
  1. Change both of those, to the new location.
    (They must be exactly the same.)
  2. Restart Apache:
    # httpd -k restart
  3. Go to localhost in the web browser - it should now be showing the files in the new location.

Extra: Setting up multiple sites (virtual hosting)

See the Virtual Hosts how-to

Extra – Test PHP and MySQL

If you are doing PHP programming,

If you are using the MySQL database, make a database using the MySQL command-line or phpMyAdmin, and see if it works. Write a little PHP script to connect to your database, put it in your document root, and see if it works.

Extra – phpMyAdmin

There is a very nice web-based MySQL client called phpMyAdmin. You can use this program to do everything with MySQL, such as create databases, create tables, view and enter data, etc etc etc.

To use phpMyAdmin, type in your browser address bar:

There is a config file in the phpMyAdmin directory, where you may need to put the username and password for your database. (I know this is a little unclear ... The config file is in different places in Ubuntu and Fedora. Google will help you find it; and the phpmyadmin website will help you with configuration howtos!)

get help

Many people in the world are using Apache, PHP, and MySQL, so there are many great resources on the web, to find out anything you want to know.

Some starters:

When i have problems, i usually find good answers when i go to google and type in some words about it.

It would be great to have Tibetan and Chinese translations of this page. Can you help? Contact us!