InfoWorld how-to's

How to install Apache on Linux

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

InfoWorld how-to's

Show More
1 2 3 4 5 Page 2
Page 2 of 5

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:

service httpd stop

To restart the server, you can also use:

service httpd restart

For simply reloading the configuration file without restarting the service, use the following command:

service httpd reload

Another very handy control:

service httpd configtest

This tests the Apache configuration file and all included files for errors without starting or restarting the server. This allows you to make sure your configurations are valid before actually causing Apache to run with that configuration, which makes it easier to add and test configurations without disturbing the running server.

To make sure that Apache starts when the server boots, simply run:

chkconfig httpd on

This will add Apache to the list of services to start at boot time.

Ubuntu. Ubuntu follows the same basic procedure as Fedora and CentOS, but places the files in different directories. The global Apache configurations are found at /etc/apache2/apache2.conf. As in Fedora and CentOS, includes break out different Apache configuration elements to separate files, but go further in Ubuntu, breaking out many more sections of the global configuration to other files (such as ports.conf, which controls the ports Apache listens on). For beginners, these files will not need to be modified.

Unlike Fedora and CentOS, Ubuntu has a specific directory for virtual host configurations, /etc/apache2/sites-available, and a companion directory, /etc/apache2/sites-enabled. Configuration elements specific to individual virtual hosts are placed in sites-available, then symlinked from sites-enabled, making it easy to add and remove active virtual hosts from the configuration without deleting or renaming the files. Just add or remove a symlink to bring them to the configuration.

Ubuntu also has a different default Web root, /var/www, so if a file named test.html exists in /var/www, Apache will deliver that file to a Web browser that requests the URL http://<server IP address>/test.html. If the server will host only a single website, then you can put all 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 Apache in Ubuntu is as simple as in Fedora and CentOS, but generally relies on a different command-line method. Although some versions of Ubuntu support the service command, you can always count on the following commands.

1 2 3 4 5 Page 2
Page 2 of 5