Web server (Apache)

From Oxxus Wiki

Jump to: navigation, search

Web server, Apache, is an Open Source server application and can be installed from the source or appropriate distro's package.

With Apache, by default, comes PHP interpreter, which has to be installed separately if installation is done from the source. If it's done with automatic packages, it'll pull it for installation automatically.

Instructions on installation from packages is detailed below.

For Ubuntu/Debian OS, Apache comes as deb package and can be installed either using dpkk installer, which requires deb package, or by apt-get, automatic installer.

For RedHat related, like Centos, RedHat ES or Fedora, rpm installer can be used for installation, which again requires rpm package, or yum, automatic updater/installer.

In either case, once Apache is installed, you're ready to configure it for default s and start it up to serve your web pages. Apache comes with default configuration file which needs minor settings to be able to serve web pages. Configuration file is at Apache's configuration folder and is named httpd.conf, regardless which OS distribution is used.

Several required settings for Quick-Start-Up

First, ServerName directive needs proper name, or Apache will assume that there is no name assigned to web server and will start as localhost service. ServerName directive always uses domain's name which web pages are to be served.

Port directive tells which TCP port will be used for this service, commonly it's 80 because every browser is going to send request to port 80 in order to access web pages served by server.

If set to any other port, you'll have to do the redirection from 80 to custom port.

With these directives your web server is ready to serve your web site pages.

All web site related files have to be placed into Apache main web folder. By default, this is /var/www/html/ for RedHat related, or /var/www/ for Debian related OS.

Main web folder, if not used one from default configuration, can be set in Apache's configuration file with directive DocumentRoot ""

By default, Apache queries for index.html or index.php which are standard index pages, depending if pages are written in PHP or in plain HTML This one can be set to custom value with directive DirectoryIndex Default Character Code set is not defined, but if you need special characters or Foreign Language support for your pages, then you can set it up with directive AddDefaultCharset

Other features

Another interesting feature of Apache service is having aliases. This feature allows serving pages from by files that are not in main web folder but are placed anywhere in server. Setting is pretty straight-forward. Place Alias directive like follows.

Alias /test/ “/var/www/test/”. With this example Apache will serve pages defined in files from folder /var/www/test/

You can restrict accessing entire folders, and subfolder, and any contents within by setting .htaccess feature

In Apache configuration file, set the directive AllowOverride All and here are files that has to be placed into desired folder. Apache will automatically vring up this service once it finds .htaccess.

.htaccess file (place it into desired folder)

AuthName ZoneName
AuthType Basic
AuthUserFile FOLDER_FOR_PROTECTION/.htpasswd
Require valid-user

If you have access to shell prompt of apache's server then use commands below in order to generate .htpasswd file with users and passwords allowed

htpasswd -nbm USENAME PASSWORD >>.htpasswd

Execute this command from shell prompt and at folder where .htpasswd is defined to at .htaccess file

All these directives are allowed for global web server configuration, set to serve pages from default web folder. But they can be set for specific folders as well. This is enabled by directive Directory, set as follows, in example

<Directory /FOLDER_NAME>
...options and directives set here are strictly for this FOLDER_NAME and files server from it

Serve contents for multiple domains

With Apache application server, you can also serve contents for multiple domains, separately. This feature is called Virtual Hosting and basic settings for test.com is as follows.

NameVirtualHost *:80 (required for Apache to set to serve multiple domains)

<VirtualHost *:80>
    ServerName test.com
    ServerAlias www.test.com
    ErrorLog logs/test.com-error_log
    CustomLog logs/test.com-access_log common

With configuration set as above and web files placed into FOLDER_WHERE_WEB_FILES_ARE_STORED, you can restart Apache and access web site contents of www.test.com By configuring virtual domains as shown, you can serve as many domains as you need.

Apache's configuration file contains detailed how-to instructions for all directives and options that are required for your web site to work correctly.

Contact About Us Support Network Servers Java Hosting Oxxus.net Order Now! Dedicated Servers VPS Hosting Tomcat Hosting Java Hosting Money Back Guarantee Privacy Policy Oxxus.net Terms of 
Service Contact About Us Servers Networks Support Domain Names SSL Certificates Java Wiki Tutorials E-learning