Installing Apache locally on Linux

Apache is often used as part of a LAMP (Linux, Apache, MySQL, PHP) stack to accommodate web applications such as a content management system or customer relation manager.

These instructions assume an installation for a trusted local network. Installations that face the Internet or another untrusted network require additional security measures outside the scope of this article.

Apache expects the computer to have an FQDN set and will complain otherwise. Alternatively, see the tips and tricks section below.

I prefer to install and test each LAMP component separately, so I skip the all-in-one LAMP metapackages. I also prefer to do things in distro-agnostic ways, so I likewise pass on the Apache installation wizards some distros provide. I’m not a masochist, however, so I do take advantage of whatever Apache-only metapackage my repositories might have. Each distribution dreams up a slightly different name for them, so you’ll have to hunt around a bit. Examples include:

  • Mageia 2: apache
  • Ubuntu 12.10: apache2

Pay attention to any instructions or advisories the installer may give you. Apache needs to be configured for use, and packages differ on how much configuration is done automatically and how much is left to you. When ready, test by pointing a browser to “http://localhost/“, “http://your-hostname/“, and “http://your-fqdn/“. Each should resolve to the same “It works!” confirmation page. Reboot your computer and repeat the tests to confirm that Apache starts on boot and continues to work.

It’s good form to restart apache from the command line to spot any obvious error messages. How this is done may differ on different distributions. On Ubuntu, for example, the command is sudo /etc/init.d/apache2 restart. Correct any issues you notice.

If Apache cannot determine your FQDN, it will complain when (re)starting with a message such as “Could not reliably determine the server’s fully qualified domain name”. You can ignore this (Apache will work), correct your computer’s FQDN, or hardwire a server name into Apache’s configuration. To do this, add the line “ServerName localhost” to /etc/apache2/apache2.conf, substituting your computer’s name for localhost. Restart Apache to check your work.

If you have a nonstandard network setup, such as sharing the Internet connection with other local machines, localhost might not resolve. In that case, point your browser to your local IP address (e.g. ““).

Confirm that the Apache service is configured to start on boot and is running. Different distributions have different names for it: apache, apache2, httpd, and perhaps others. Whatever it’s called, reboot the system to test.

If you installed Apache for local use only, make sure your firewall is not letting the world in.

If you installed Apache to set up a LAMP stack, your next step is to install a database management system. Unless I have a reason to do otherwise, I install either MySQL or MariaDB, whichever is the default for my distribution.

That’s outside the scope of this article. If what you want is a full WAMP stack, take the easy way out and try WampServer.


About Warren Post

So far: Customer support guy, jungle guide, IT consultant, beach bum, entrepreneur, teacher, diplomat, over-enthusiastic cyclist. Tomorrow: who knows?
This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.

6 Responses to Installing Apache locally on Linux

  1. Pingback: Installing WampServer locally | Warren's tech notes

  2. Pingback: Installing and configuring vtiger | Warren's tech notes

  3. Pingback: Installing and configuring Joomla | Warren's tech notes

  4. Pingback: Installing MySQL locally | Warren's tech notes

  5. Pingback: Installing and configuring PHP | A maze of twisty little passages

  6. Pingback: Internet sharing on Linux | A maze of twisty little passages

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s