How to install Apache on Linux

An easy step-by-step guide to setting up an Apache Web server on Fedora, CentOS, or Ubuntu

By Paul Venezia, InfoWorld |  Software, Apache, centos

Apache on Linux: Initial configuration While the Apache and PHP packages are essentially the same across the different distributions, there are differences in how they are actually installed on the file system. We'll start with Fedora and CentOS.

Fedora and CentOS. After installation, you'll find a new directory: /etc/httpd. Within this directory are all the Apache configuration files. The important subdirectories for our purposes are /etc/httpd/conf and /etc/httpd/conf.d. Within /etc/httpd you'll find the main Apache configuration file, httpd.conf. In /etc/httpd/conf.d you will find includes, or supplemental files that are included in the main configuration file.

Includes are a way to break out complex configurations into separate files for easy organization and management. For instance, if you have an Apache server that has 20 virtual hosts, then each virtual host should have a separate file in /etc/httpd/conf.d/ that contains its specific configuration parameters. In this way, you can easily add or remove virtual hosts without editing the main Apache configuration file.

In order for files to be included in the Apache configuration, they must have a filename that ends with .conf. If we have a virtual host named www.test.com, all the configuration elements for that virtual host would reside in a file named test.conf or test.com.conf.

You can see how these files are included in the main configuration file by looking at /etc/httpd/conf/httpd.conf. Press Ctrl-W to search for "Include conf.d" and you'll find this line:

Include conf.d/*.conf

That tells Apache to include all files matching *.conf in the /etc/httpd/conf.d folder into the main configuration.

There are many configuration elements present in the Apache configuration file, but beginners need to be concerned with only a few. These are the elements that control where our Web root is, how to handle virtual hosting, and a few other minor tweaks. To start with, the default settings present in this file will be fine.

By default, the Web root on Fedora and CentOS is /var/www/html. This means that any files placed under /var/www/html will be served via Apache when a Web browser connects to the server. If a file exists as /var/www/html/test.html, and you open a Web browser and connect to http://<server IP address>/test.html, the server will deliver that file to the browser. If the server will host only a single website, then you can put all of your content under this directory and configure DNS to map a name, such as www.test.com, to the server's IP address, and then http://www.test.com/ will work.

Controlling the Apache server is very simple. To start the server on Fedora or CentOS, run:

service httpd start

Stopping the server is equally simple:


Originally published on InfoWorld |  Click here to read the original story.
Join us:
Facebook

Twitter

Pinterest

Tumblr

LinkedIn

Google+

SoftwareWhite Papers & Webcasts

Webcast On Demand

HP DevOps KnowledgeVault

Sponsor: HP

See more White Papers | Webcasts

Answers - Powered by ITworld

ITworld Answers helps you solve problems and share expertise. Ask a question or take a crack at answering the new questions below.

Join us:
Facebook

Twitter

Pinterest

Tumblr

LinkedIn

Google+

Ask a Question
randomness