Apache is a widely-used open-source web server, popular for its reliability and ease of customization. It is a preferred choice for running web applications on Linux distributions like openSUSE and SUSE Linux Enterprise Server (SLES). These distributions are known for their stability and enterprise-grade features, making them suitable for hosting production environments.
Setting up Apache on openSUSE or SLES requires using the zypper package manager. This process ensures that all necessary dependencies are correctly installed and configured. Understanding how to properly install and configure Apache is essential for running a functional and secure web server.
This guide provides a concise and clear method for installing and configuring Apache on openSUSE and SLES. The steps outlined are designed to help you set up the server efficiently and correctly.
Steps to install and configure Apache on openSUSE or SLES:
- Open the terminal.
- Refresh zypper package list.
> sudo zypper refresh [sudo] password for root: Retrieving repository 'Update repository of openSUSE Backports' metadata ...........[done] Building repository 'Update repository of openSUSE Backports' cache ................[done] Retrieving repository 'Non-OSS Repository' metadata ................................[done] Building repository 'Non-OSS Repository' cache .....................................[done] Retrieving repository 'Open H.264 Codec (openSUSE Leap)' metadata ..................[done] Building repository 'Open H.264 Codec (openSUSE Leap)' cache .......................[done] Retrieving repository 'Main Repository' metadata ...................................[done] Building repository 'Main Repository' cache ........................................[done] Retrieving repository 'Update repository with updates from SUSE Linux Enterprise 15'[done] Building repository 'Update repository with updates from SUSE Linux Enterprise 15' c[done] Retrieving repository 'Main Update Repository' metadata ............................[done] Building repository 'Main Update Repository' cache .................................[done] Retrieving repository 'Update Repository (Non-Oss)' metadata .......................[done] Building repository 'Update Repository (Non-Oss)' cache ............................[done] All repositories have been refreshed.
- Install apache2 package using zypper.
> sudo zypper install --no-confirm apache2 Loading repository data... Reading installed packages... Resolving package dependencies... The following recommended package was automatically selected: w3m The following 8 NEW packages are going to be installed: apache2 apache2-prefork apache2-utils libapr1 libapr-util1 libgc1 system-user-wwwrun w3m 8 new packages to install. Overall download size: 2.8 MiB. Already cached: 0 B. After the operation, additional 14.3 MiB will be used.
- Configure Apache options as necessary.
> sudo vi /etc/apache2/httpd.conf
Related: Understanding Apache web server configuration files
Related: Guide listing for Apache - Test the Apache configuration for errors.
> sudo apachectl configtest AH00557: httpd-prefork: apr_sockaddr_info_get() failed for host AH00558: httpd-prefork: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message Syntax OK
- Restart apache2 service once you're done with yur configuration.
> sudo systemctl restart apache2
- Enable apache2 to start automatically on boot.
> sudo systemctl enable apache2 Created symlink /etc/systemd/system/httpd.service → /usr/lib/systemd/system/apache2.service. Created symlink /etc/systemd/system/apache.service → /usr/lib/systemd/system/apache2.service. Created symlink /etc/systemd/system/multi-user.target.wants/apache2.service → /usr/lib/systemd/system/apache2.service.
- Open ports 80 (http) and 443 (https) in the firewall if needed.
> sudo firewall-cmd --permanent --add-service=http --add-service=https success
- Reload firewall for rule changes to take effect.
> sudo firewall-cmd --reload success
- Add DirectoryIndex file to DocumentRoot folder.
> sudo vi /srv/www/htdocs/index.html
- Make sure DocumentRoot folder has correct ownership.
> sudo chown --recursive wwwrun:wwwrun /srv/www/
- Verify the web server setup by accessing the website.
> curl 127.0.0.1 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Welcome to Apache on SUSE</title> ##### snipped
There's no default DirectoryIndex file in the DocumentRoot folder. The output here depends on the content of the index.html file that you've created in the previous steps.
Mohd Shakir Zakaria is an experienced cloud architect with a strong development and open-source advocacy background. He boasts multiple certifications in AWS, Red Hat, VMware, ITIL, and Linux, underscoring his expertise in cloud architecture and system administration.
Comment anonymously. Login not required.