Apache Security Configurations
Apache Security Configurations
Additional security for PHP applications hosted with Apache can be configured either in the main httpd.conf file or through a directory-level .htaccess file.
Configuration Methods
The AllowOverride directive determines what can be placed in .htaccess. When it is set to None, these files are ignored. When set to All, directives with an .htaccess context are allowed.
Set Up Authentication
Generate a password hash
Use an htpasswd tool to generate the hashed password.
Create the password file
Create a plain text file containing the generated username and hash.
Upload the file
Click Config for the Apache server and upload the file to /var/www/webroot/ROOT.
Protect the application
Open /etc/httpd/conf/httpd.conf or the application .htaccess file and add:
AuthName "Restricted area" AuthType Basic AuthBasicProvider file AuthUserFile /var/www/webroot/ROOT/.htpasswd Require valid-user

To protect only one directory, wrap the authentication directives inside a Location block:
<Location /directory_path> AuthName "Restricted area" AuthType Basic AuthBasicProvider file AuthUserFile /var/www/webroot/ROOT/.htpasswd Require valid-user </Location>

Save the changes and restart Apache when editing httpd.conf. Changes in .htaccess take effect immediately because the file is read on every request.

Security through Access Criteria
Apache access can be controlled according to criteria such as a client hostname or IP address by using the Require directive.
Open /etc/httpd/conf/httpd.conf or a target directory’s .htaccess file and add the required policy to the corresponding Directory section.


Configure ModSecurity
ModSecurity provides filtering, URL and Unicode validation, auditing, null-byte attack prevention, upload-memory limits, server-identity masking, chroot support, and other security capabilities.
The module is available by default and is configured through:
/etc/httpd/conf.d/mod_security.conf

Additional rule files can be uploaded to /etc/httpd/modsecurity.d or its activated_rules subdirectory. The default configuration loads them automatically:
Include modsecurity.d/*.conf Include modsecurity.d/activated_rules/*.conf

Hide the Apache Server Version
Exposing the Apache, operating system, or module version can help an attacker identify applicable exploits. The platform adds these directives automatically:
ServerSignature Off ServerTokens Prod
ServerSignature Offprevents Apache version details from appearing on server-generated pages.ServerTokens Prodlimits the HTTP response header toServer: Apache.
Expected Result
The Apache-hosted PHP application can require authentication, enforce hostname or IP-based access policies, use ModSecurity rules, and hide detailed server-version information.
Important Notes
- Restart Apache after changing
httpd.conf. .htaccesschanges take effect immediately when allowed byAllowOverride.- Use HTTPS with Basic authentication so credentials are encrypted in transit.
- Test access policies from both allowed and denied clients.
- Validate custom ModSecurity rules before production use.
