Sometimes Apache web server displays PHP files without actually executing the code in them. In this case, users don’t see the result of executed PHP but the underlying code. It can pose security risks to expose your website’s code to visitors. This is a common problem especially if you are using Apache/PHP for the first time. In this article, we will look at how to fix Apache not executing PHP files.
How to Fix Apache Not Executing PHP Files
Here are the steps to get Apache to execute PHP files.
1. Update Apache configuration file
Open terminal and open Apache configuration file.
$ sudo vi /etc/apache2/apache2.conf
Add the following lines to the bottom of your file.
<FilesMatch \.php$> SetHandler application/x-httpd-php </FilesMatch>
Save and exit the file.
Also read : How to Uninstall NGINX in CentOS
2. Disable & Enable modules
To get PHP execution working properly, you need to disable and then enable mpm_event_module, and enable mpm_prefork and php7 modules.
$ sudo a2dismod mpm_event && sudo a2enmod mpm_prefork && sudo a2enmod php7.0
Also read : How to Set UTF-8 Encoding in Tomcat Server
3. Restart Apache Server
Restart Apache Server to apply changes.
$ sudo service apache2 restart
That’s it. Now open your browser and go to your website. You should see PHP code being executed properly. Apache is a powerful web server that offers plenty of useful features.
Also read : How to Use NGINX try_files