« HOWTO: Work with Services, auto start, stop, startHOWTO Handcraft network configurations »

HOWTO: Setup Apache server on Fedora

02/12/10

HOWTO: Setup Apache server on Fedora

To install and configure Apache web server is really simple the second or third time. :>

To install the software, use yum or rpm to install the rpm httpd.

sudo yum install httpd

Setting an automatic start for Apache on a reboot of your server. this is not automatically setup as with all services in Fedora.

Set the httpd service to start up for the default runlevels

sudo /sbin/chkconfig httpd on

Confirmation of automatic startup and which levels it will be starting on

/sbin/chkconfig --list httpd
httpd 0:off 1: off 2: off 3: on 4: off 5:on 6: off

To start up the service use the normal stop, start and restart options on the command line with service.

sudo service httpd start
sudo service httpd stop
sudo service httpd restart
sudo service httpd reload

This last one tests the syntax of all the conf files that will be loaded, spitting out diagnostic lines as necessary.

sudo service httpd configtest

Adding Virtual hosts.

sudo nano /etc/httpd/conf/httpd.conf
ServerAdmin webmaster <email address here>
NameVirtualHost *:80
NameVirtualHost *:443
cd /etc/httpd/conf.d
sudo mv mod_dnssd.conf 00_mod_dnssd.conf
sudo mv python.conf 05_python.conf
sudo mv welcome.conf 99_welcome.conf
sudo nano /etc/httpd/conf.d/10_default.conf
default virtual host
# The Default web site, when there are no matches to the URL we end up here  
# There must not be a ServerName in this config file or it will not function  
# as we hope it will do.  
<VirtualHost *:80>  
        ServerAdmin webmaster@example.com

  


         # Indexes + Directory Root.  
        DirectoryIndex index.html  
        DocumentRoot /var/www/default/  
         # CGI Directory  
        ScriptAlias /cgi-bin/ /var/www/default/cgi-bin/  
        <Location /cgi-bin>  
                Options +ExecCGI  
        </Location>  
         # Logfiles  
        ErrorLog   /var/log/httpd/default_error.log  
        CustomLog  /var/log/httpd/default_custom.log combined  
</VirtualHost>

Test/check that syntax for the file is correct, if it is start or reload the service httpd.

sudo service httpd configtest
sudo service httpd start
sudo mkdir -p /var/www/default
sudo nano /var/www/default/index.html
/var/www/default/index.html
<html><body><h1> Default start page for my web server</h1>
<p>This is the default web page for this server.</p>
<p>The web server software is running but no content has been added, yet.</p>
</body></html>

http://localhost

sudo nano /etc/httpd/conf.d/15_example.com.conf
example.com virtual host
<VirtualHost *:80>  
        ServerAdmin webmaster@example.com  
        ServerName  www.example.com

  


        ServerAlias example.com  
        # Indexes + Directory Root.  
        DirectoryIndex index.html  
        DocumentRoot /var/www/example.com/  
        # CGI Directory  
        ScriptAlias /cgi-bin/ /var/www/example.com/cgi-bin/  
        <Location /cgi-bin>  
                Options +ExecCGI  
        </Location>  
        # Logfiles  
        ErrorLog   /var/log/httpd/example.com_error.log  
        CustomLog  /var/log/httpd/example.com_custom.log combined  
</VirtualHost>
sudo mkdir -p /var/www/example.com

Test/check that syntax for the file is correct, if it is reload the service httpd.

sudo service httpd configtest
sudo service httpd reload

Create the index page for example.com site. No need to go too mad on this temporary marker page.

sudo nano /var/www/example.com/index.html
/var/www/example.com/index.html

<html><body><h1> Default start page for example.com</h1> 


<p>This is the default web page for this server.</p> 
<p>The web server software is running but no content has been added, yet.</p> 
</body></html>
rewrite address command line on the fly
ServerAlias www.example.com  
 
# Redirect all requests for a www host  
RewriteEngine On  
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]  
RewriteRule ^(.*)$ http://%1/$1

 [R=301,QSA,L] 


No feedback yet

Here are a collection of Mini-HOWTOs some of which are too short even for that grand title. I keep them around as it is easier to remember where to look these up that to remember the content of the mini-HOWTO

Search

Contents

powered by b2evolution free blog software