Custom error pages in Apache allow administrators to replace default responses with visually consistent designs, ensuring an integrated user experience when unexpected issues occur. These pages can address various HTTP status codes, including 404 (Not Found) and 500 (Internal Server Error), among others.
These customized pages are typically stored in web-compatible formats like HTML and can include helpful information, branding, or navigation links to guide visitors. The ErrorDocument directive in Apache configuration files directs incoming error requests to these tailored responses.
Administrators can define these custom responses on a per-site basis or configure them server-wide, providing consistent error handling across multiple domains. The capability to present a unified style during errors reduces confusion and maintains a professional appearance.
Steps to configure custom error pages in Apache:
- Launch terminal.
- Open the Apache configuration file using your preferred text editor.
$ sudo vi /etc/apache2/sites-available/000-mysite.conf
- Add the ErrorDocument directive followed by the path to the custom error page.
ErrorDocument 404 /custom_404.html
This could be within a specific <VirtualHost> block if you want the custom pages to apply to a particular site, or outside of those blocks to apply server-wide.
- Repeat the above step for any other error codes and sites you want to customize.
- Save the configuration file and exit the text editor.
- Check the configuration syntax to ensure there are no errors.
$ sudo apache2ctl configtest
- Restart the Apache service to apply the changes.
$ sudo systemctl restart apache2
- Test by accessing a page that triggers an error.

Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
Comment anonymously. Login not required.