
Installation on CentOS
On CentOS, Apache is available from the default software repository, meaning no additional repository configuration is needed. Simply install Apache using the package manager, start the HTTP service, and verify its status. If your system has a firewall enabled, make sure to add a rule that permits HTTP traffic.Use the package manager to install, start, and check the Apache service with the commands shown below.
service httpd status command might look like this:
Log Files and Configuration
Apache places its log files within the/var/log/httpd directory. There are two primary logs:
- Access Logs: Updated whenever a user accesses the website.
- Error Logs: Updated whenever an error occurs.
/etc/httpd/conf/httpd.conf. This file manages various operational parameters, including the port number, location of static content, SSL/HTTPS settings, and log configurations. A simplified example of the default settings is:
DocumentRoot specifies the directory containing your static files. To launch your custom website, simply move your static files into this directory. Once you refresh your browser, the default Apache test page will be supplanted by your website’s content.
Server Name Configuration
Setting a server name in the configuration allows Apache to correctly recognize requests for your website. For instance, consider the following configuration for a website about houses:www.houses.com. For this to work seamlessly, the domain name must resolve to your server’s IP address. In a local testing environment, add the following entry to your /etc/hosts file:
Mapping your domain in the
/etc/hosts file can help simulate DNS resolution for local server development.Virtual Hosts
Apache supports hosting multiple websites on a single server using virtual hosts. Each virtual host is defined by its own configuration, including a separate server name and document root. This is useful for hosting multiple domains (e.g.,www.houses.com and www.oranges.com) on one machine.
Below is an example configuration for hosting two websites:
Splitting Virtual Host Configurations
For better organization, you can split virtual host configurations into separate files instead of maintaining everything in the primary configuration file. An example include directive in the main configuration might be:/etc/httpd/conf/houses.conf could be:
/etc/httpd/conf/oranges.conf might contain:
/etc/hosts file:
Splitting configuration files can streamline managing multiple virtual hosts, making maintenance and troubleshooting easier.
www.houses.com or www.oranges.com are directed to your local Apache server on port 80.