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

Note: For Fedora and CentOS, you may have to edit the /etc/httpd/conf/httpd.conf file and remove the # character before NameVirtualHost *:80 near the bottom of the file. This will allow name-based virtual hosts to function. To do this, open the file in nano:

nano /etc/httpd/conf/httpd.conf

Then press Ctrl-W and locate NameVirtualHost by typing in that search string. Remove the # (comment character) from the beginning of the line and save the file.

Now we're ready to create our virtual host. Using Fedora, we'd open a new file in /etc/httpd/conf.d/:

nano /etc/httpd/conf.d/test.conf

For Ubuntu, we would run:

sudo nano /etc/apache2/sites-available/test

We now have an empty file that we need to fill up with the configuration for our virtual host. Here's an example file for Fedora or CentOS:

<VirtualHost *:80>    ServerAdmin
webmaster@www.test.com    DocumentRoot /var/www/test   
ServerName www.test.com    ServerAlias test.com    ErrorLog
logs/www.test.com-error_log    CustomLog logs/www.test.com-access_log
combined</VirtualHost>

We need a slightly different file for Ubuntu due to different conventions for log file placement:

<VirtualHost *:80>     ServerAdmin webmaster@www.test.com
    DocumentRoot /var/www/test     ServerName www.test.com
    ServerAlias test.com     ErrorLog
${APACHE_LOG_DIR}/www.test.com-error_log     CustomLog
${APACHE_LOG_DIR}/www.test.com-access_log combined </VirtualHost>

This configuration snippet tells Apache that we have a virtual host that will be listening on TCP port 80 (the standard HTTP port). It also tells Apache that the document root for this virtual host is /var/www/test, indicates that the server name is www.test.com, and specifies where the logs should be placed. It then ends the configuration snippet with the </VirtualHost> directive.


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

Twitter

Pinterest

Tumblr

LinkedIn

Google+

SoftwareWhite Papers & Webcasts

See more White Papers | Webcasts

Join us:
Facebook

Twitter

Pinterest

Tumblr

LinkedIn

Google+

Ask a Question
randomness