Before You Begin
This tutorial provides instructions for installing the Apache web server and enabling it on Oracle Linux 8.
Apache has been in active development since 1993 and over time has become one of the most popular web servers in the world. The Apache web server is a key component of the "LAMP" (Linux, Apache, Oracle MySQL and Perl/PHP) software stack and continues to be widely used today.
The Apache web server is directly available from the Oracle Linux 8 Application Streams repository and is simple to deploy and configure.
What Do You Need?
- Any system with Oracle Linux 8 installed
Install the httpd package
The following command installs the
httpd package and all of its dependencies.
$ sudo dnf install httpd
Enable and start the httpd service
To enable and start the
httpd service for immediate access and make the service start automatically after a reboot, run the following command:
$ sudo systemctl enable --now httpd.service
The service starts a web server that listens on TCP port 80 by default. To check the status of the service, run this command:
$ sudo systemctl status httpd
Configure firewall rules (Optional)
If you are using a custom firewall profile or an Oracle Cloud Infrastructure instance, open the firewall port for the Apache web service (80).
These commands enable the firewall port for the Apache web service and reload the default firewall service:
$ sudo firewall-cmd --add-service=http --permanent $ sudo firewall-cmd --reload
Test your deployment
With your web browser, go to the domain name or IP address of your system.
The Apache web server opens the default test page.
Edit the Apache configuration
To change the root path for your web server, do not edit the
/etc/httpd/conf/httpd.conf directly. Instead, as a preferred method, create a site-specific configuration in the
Create virtual hosts
Create the file
populate it with the following content:
Listen *:80 <VirtualHost *:80> ServerName example.com ServerAlias www.example.com DocumentRoot /var/www/example.com/html/ ErrorLog /var/log/httpd/example.com_error.log CustomLog /var/log/httpd/example.com_access.log combined </VirtualHost>
values with the hostnames, domain names, or IP addresses that you
will use to access the service. Replace the
DocumentRoot value with the path to where you intend to host the files for your web site. Replace the
CustomLog values with the
path to where you intend to log activity from the
Create the document root folder
Create a folder to host the web pages that Apache will serve to the browsers, then set the necessary ownership permissions for it.
$ sudo mkdir -p /var/www/example.com/html $ sudo echo "example.com" > /var/www/example.com/html/index.html $ sudo chown -R apache:apache /var/www/example.com/html
On systems where SELinux is enabled in enforcing mode and pages are
not served from within the
/var/www directory, you must
apply the correct security context to the
directory. For example, you would serve web pages from the
/mnt/example.com directory as follows:
$ sudo semanage fcontext -a -t httpd_sys_content_t "/mnt/example.com(/.*)?" $ sudo restorecon -Rv /mnt/example.com/
Apply your configuration
Restart the Apache web service to load the new configuration.
$ sudo systemctl restart httpd
Note that if you are hosting multiple domains, you can specify
VirtualHost values for each configuration
file that you create in the
Configure HTTPS to secure your service
As a best practice, secure all communications between a web browser and your Apache server by using HTTPS. For a secure setup, a TLS certificate is required.
Configure your TLS/SSL certificates
Oracle strongly recommends using an TLS certificate that has been signed by an external Certificate Authority (CA). See https://docs.oracle.com/en/operating-systems/oracle-linux/certmanage/ for more information.
Install the HTTPS add-on for Apache
Install and enable the
mod_ssl extension for Apache.
$ sudo dnf install mod_ssl $ sudo systemctl restart httpd
Update the Apache configuration
/etc/httpd/conf.d/example.com.conf file in a
text editor and create a new VirtualHost for HTTPS:
Listen *:443 <VirtualHost *:443> ServerName example.com ServerAlias www.example.com SSLEngine on SSLCertificateFile /etc/pki/tls/private/certificate.crt SSLCertificateKeyFile /etc/pki/tls/private/private.key DocumentRoot /var/www/example.com/html/ ErrorLog /var/log/httpd/example.com_error.log CustomLog /var/log/httpd/example.com_access.log combined </VirtualHost>
Redirect HTTP requests to HTTPS
Replace your existing HTTP
with a redirect, as follows:
<VirtualHost *:80> ServerName example.com ServerAlias www.example.com Redirect "/" "https://example.com/" </VirtualHost>
Restart the Apache service to load the new configuration.
$ sudo systemctl restart httpd
Configure the firewall (optional)
Enable the firewall port (443) for the Apache HTTPS web service and reload the default firewall service.
$ sudo firewall-cmd --add-service=https --permanent $ sudo firewall-cmd --reload
Want to Learn More?
Oracle Linux: Install the Apache Web Server
Copyright © 2020, Oracle and/or its affiliates.
This tutorial provides instructions to install the Apache web server and enable it in Oracle Linux 8.
This software and related documentation are provided under a license agreement containing restrictions on use and disclosure and are protected by intellectual property laws. Except as expressly permitted in your license agreement or allowed by law, you may not use, copy, reproduce, translate, broadcast, modify, license, transmit, distribute, exhibit, perform, publish, or display any part, in any form, or by any means. Reverse engineering, disassembly, or decompilation of this software, unless required by law for interoperability, is prohibited.
The information contained herein is subject to change without notice and is not warranted to be error-free. If you find any errors, please report them to us in writing.
If this is software or related documentation that is delivered to the U.S. Government or anyone licensing it on behalf of the U.S. Government, then the following notice is applicable:
U.S. GOVERNMENT END USERS: Oracle programs (including any operating system, integrated software, any programs embedded, installed or activated on delivered hardware, and modifications of such programs) and Oracle computer documentation or other Oracle data delivered to or accessed by U.S. Government end users are "commercial computer software" or "commercial computer software documentation" pursuant to the applicable Federal Acquisition Regulation and agency-specific supplemental regulations. As such, the use, reproduction, duplication, release, display, disclosure, modification, preparation of derivative works, and/or adaptation of i) Oracle programs (including any operating system, integrated software, any programs embedded, installed or activated on delivered hardware, and modifications of such programs), ii) Oracle computer documentation and/or iii) other Oracle data, is subject to the rights and limitations specified in the license contained in the applicable contract. The terms governing the U.S. Government's use of Oracle cloud services are defined by the applicable contract for such services. No other rights are granted to the U.S. Government.
This software or hardware is developed for general use in a variety of information management applications. It is not developed or intended for use in any inherently dangerous applications, including applications that may create a risk of personal injury. If you use this software or hardware in dangerous applications, then you shall be responsible to take all appropriate fail-safe, backup, redundancy, and other measures to ensure its safe use. Oracle Corporation and its affiliates disclaim any liability for any damages caused by use of this software or hardware in dangerous applications.
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
Intel and Intel Inside are trademarks or registered trademarks of Intel Corporation. All SPARC trademarks are used under license and are trademarks or registered trademarks of SPARC International, Inc. AMD, Epyc, and the AMD logo are trademarks or registered trademarks of Advanced Micro Devices. UNIX is a registered trademark of The Open Group.
This software or hardware and documentation may provide access to or information about content, products, and services from third parties. Oracle Corporation and its affiliates are not responsible for and expressly disclaim all warranties of any kind with respect to third-party content, products, and services unless otherwise set forth in an applicable agreement between you and Oracle. Oracle Corporation and its affiliates will not be responsible for any loss, costs, or damages incurred due to your access to or use of third-party content, products, or services, except as set forth in an applicable agreement between you and Oracle.