Would you like to learn how to enable HTTPONLY and SECURE flags on the Apache server? In this tutorial, we are going to show you how to protect your website Cookies by adding the HTTPONLY and SECURE headers on the apache server.

• Ubuntu 20
• Ubuntu 19
• Ubuntu 18
• Apache 2.4.41

In our example, the Apache server is hosting the website WWW.GAMEKING.TIPS

Equipment list

The following section presents the list of equipment used to create this tutorial.

As an Amazon Associate, I earn from qualifying purchases.

Tutorial Apache – Enable the HttpOnly and Secure flag

Install the Apache server.

Copy to Clipboard

Enable the required Apache modules.

Copy to Clipboard

Edit the Apache configuration file for the website.

Copy to Clipboard

If your website supports only HTTP, Add the following lines at the end of the file.

Copy to Clipboard

If your website supports only HTTPS, Add the following lines at the end of the file.

Copy to Clipboard

Restart the Apache service.

Copy to Clipboard

The HTTPONLY flag increases the COOKIE’s protection, by not allowing access through client-side scripts.

The SECURE flag increases the security even further, by allowing only COOKIE requests through an HTTPS connection.

Create a PHP file to test the HTTPONLY configuration.

Copy to Clipboard

Here is the file content.

Copy to Clipboard

This test requires that your Apache server supports PHP.

From a remote Linux computer, try to access this page.

Copy to Clipboard

Here is the command output with the flag HTTPONLY enabled.

Copy to Clipboard

Here is the command output with the flags HTTPONLY and SECURE enabled.

Copy to Clipboard

Congratulations! You are able to enable the flags HTTPONLY and SECURE on the Apache server.