The Apache HTTP Server, commonly known as Apache, is one of the most widely used and trusted web servers in the world. It is open-source, highly stable, and flexible enough to host everything from simple static websites to complex enterprise web applications.
This guide provides a clear, step-by-step process to install and configure Apache on openSUSE and SUSE Linux Enterprise Server (SLES) using the
zypperpackage manager.
Prerequisites
Before you begin, ensure that:
- You have a running instance of openSUSE or SLES.
- You have a user account with sudo privileges.
- Your system has internet connectivity for package installation.
Steps to install and configure Apache
Step 1: Updating our System
Before installing any software, ensure your system is up to date:
sudo zypper refresh
sudo zypper update
This ensures all repositories and installed packages are up to date.
Step 2: Install Apache
for installing apache we will use zypper package manager
sudo zypper install apache2
Once the installation completes, Apache is installed but not yet running.
Step 3: Start and Enable Apache
After the installation is complete, start the Apache service and enable it to start on boot:
sudo systemctl start apache2
sudo systemctl enable apache2
To verify that Apache is running, you can check the status of the service:
sudo systemctl status apache2
You should see a status message indicating that Apache is active and running.
Step 4: Configure the Firewall
If you have a firewall running on your system, you need to allow HTTP and HTTPS traffic. Use the following commands to open the necessary ports:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
This allows web traffic on ports 80 (HTTP) and 443 (HTTPS).
Step 5: Testing Apache Installation
To ensure that Apache has been installed correctly, open a web browser and navigate to your server's IP address:
http://your_server_ip
You should see the default Apache welcome page, which confirms that Apache is working correctly.
Step 6: Additional Configuration
Edit Apache’s main configuration file at /etc/apache2/httpd.conf to make changes. For example:
sudo nano /etc/apache2/httpd.conf
Here are a few common configurations you might want to adjust:
6.1. Changing the Document Root
The Document Root is the directory where your website files are stored. By default, this is set to /srv/www/htdocs. To change it, locate the following line:
DocumentRoot "/srv/www/htdocs"
And update it to your desired directory, for example:
DocumentRoot "/var/www/html"
Ensure the directory exists and has the correct permissions:
sudo mkdir -p /var/www/html
sudo chown -R wwwrun:www /var/www/html
Restart Apache:
sudo systemctl restart apache2
6.2. Configuring Virtual Hosts
Virtual Hosts allow you to run multiple websites on a single server. To set up a Virtual Host, create a new configuration file in the /etc/apache2/vhosts.d/ directory. For example:
sudo nano /etc/apache2/vhosts.d/example.conf
Add the following configuration to the file:
<VirtualHost *:80>
ServerAdmin admin@example.com
ServerName example.com
DocumentRoot "/var/www/example"
ErrorLog "/var/log/apache2/example.com-error_log"
CustomLog "/var/log/apache2/example.com-access_log" common
</VirtualHost>
Create the document root directory and set the correct permissions:
sudo mkdir -p /var/www/example
sudo chown -R wwwrun:www /var/www/example
Restart Apache to apply the changes:
sudo systemctl restart apache2
Step 7: Enable and Test the Configuration
Before restarting Apache after configuration changes, test the syntax:
sudo apachectl configtest
If you see: Syntax OK
- Restart Apache:
sudo systemctl restart apache2
Optional: Enable SSL (HTTPS)
To enable SSL support:
sudo a2enmod ssl
sudo systemctl restart apache2
You can then configure SSL certificates inside your Virtual Host file.