I am experiencing an issue with Apache not displaying my PHP code. I have Apache and PHP installed on my system, and I was using them without issue until I created a PHP file. When I tried to open the file with Apache, it did not work.
I searched online and learned that I needed to install PHP (I am used to using Linux, so I had not needed to do this before). I followed some tutorials, but none of them resolved the issue.
I have checked several things to try and troubleshoot the problem:
- I made sure that the file has a .php extension and that the ini file is configured to read .php files.
- I modified the Apache httpd.conf file to include the correct PHP module and AddType directive.
- I confirmed that both Apache and PHP are running properly.
- I uncommented the PHP ini file as instructed in one of the tutorials.
- I added the environment route to my system.
Despite these efforts, I am still having issues with Apache not displaying my PHP code. When I use the PHP function
phpinfo(), it shows a blank page. I have tried using a different version of PHP, but the issue persists.
I have also tried adding various directives to the httpd.conf file and checking for syntax issues, but none of these actions have resolved the issue. When I start Apache and load the localhost page with my PHP script, the logs seem normal.
The versions I am using are PHP 7.3.9 and Apache 2.4.41.
Apache is a popular web server that is widely used for hosting websites and web applications. PHP, on the other hand, is a popular server-side scripting language that is used to create dynamic web pages. When Apache is configured to work with PHP, it can execute PHP code and generate dynamic content. However, sometimes users may encounter issues with Apache not displaying PHP code. In this blog post, we will discuss one such issue where Apache 2.4 does not support PHP 7 on Windows and how to resolve it.
As mentioned earlier, Apache is a web server, and PHP is a server-side scripting language. Apache can be configured to work with PHP by installing the PHP module and configuring the Apache httpd.conf file. However, there are some compatibility issues between different versions of Apache and PHP, especially on Windows. One such issue is that Apache 2.4 does not support PHP 7 on Windows.
The issue is that when Apache is configured to work with PHP 7 on Windows, it does not display PHP code. Instead, it shows the PHP code as plain text in the browser. This issue can occur even if all the necessary configurations are in place, such as the PHP module is installed, and the httpd.conf file is configured correctly.
The solution to this issue is to use a version of PHP that is compatible with Apache 2.4 on Windows. The recommended version of PHP to use with Apache 2.4 on Windows is PHP 5.6 or PHP 7.1. You can download the compatible version of PHP from the official PHP website.
Once you have downloaded the compatible version of PHP, follow the steps below to configure Apache to work with PHP:
Step 1: Install PHP
Install the downloaded version of PHP on your system. Make sure to select the correct version that is compatible with Apache 2.4 on Windows.
Step 2: Configure Apache
Open the Apache httpd.conf file and add the following lines of code at the end of the file:
LoadModule php7_module "C:/php/php7apache2_4.dll" AddHandler application/x-httpd-php .php PHPIniDir "C:/php"
Make sure to replace the path to the PHP module and PHPIniDir with the correct path on your system.
Step 3: Restart Apache
Restart Apache to apply the changes. You can do this by opening the Apache monitor and clicking on the restart button.
Step 4: Test PHP
Create a PHP file with the following code:
<?php phpinfo(); ?>
Save the file in the Apache htdocs directory and name it phpinfo.php. Open your web browser and navigate to http://localhost/phpinfo.php. If everything is configured correctly, you should see the PHP information page.
In this blog post, we discussed an issue where Apache 2.4 does not support PHP 7 on Windows and how to resolve it. We recommended using a version of PHP that is compatible with Apache 2.4 on Windows, such as PHP 5.6 or PHP 7.1. We also provided step-by-step instructions on how to configure Apache to work with PHP. By following these steps, you should be able to resolve the issue and start using PHP with Apache on your Windows system.
It sounds like you have done a lot of troubleshooting already, but there are a few more things you could try to resolve the issue.
- Check the Apache error log to see if there are any clues about the issue. The error log is usually located at
- Make sure that you have the correct version of the PHP module for your version of Apache. For Apache 2.4, you should be using the
- Check that the PHP module is loaded by Apache. You can check the list of loaded modules by running the
httpd -Mcommand. If the PHP module is not listed, you may need to update the
LoadModuledirective in your
- Check the permissions on your PHP file. Apache may not have permission to read the file if the permissions are set incorrectly.
- If you are using a local development environment such as XAMPP, make sure that you have enabled PHP in the control panel.
I hope these suggestions help you resolve the issue. If you are still having trouble, it may be helpful to provide more details about the error messages you are seeing and any other steps you have taken to troubleshoot the problem.
It may be worth verifying that the versions of PHP and Apache you are using are compatible. This could involve checking that:
- Both PHP and Apache were compiled with compatible compilers.
- Both were compiled in the same 32-bit or 64-bit format.
- You are using a Thread Safe (TS) version of PHP.
- If you are using an early version of PHP 7.4 (up to and including 7.4.0beta2), you may need to downgrade or switch versions.
According to the log information you provided, you are using an Apache Lounge build of Apache, which is compatible with PHP 7.3.9.
If you are still experiencing issues with your PHP code not being displayed, it is possible that there are syntax errors present. In your original post, you mentioned that you ran the PHP code
<?php phpinfo(); ?>, but this should actually be written as
<?php phpinfo(); ?>. When this code was run on a known, working PHP installation (Apache Lounge Apache v2.4.41 VS16 x32 with PHP 7.3.9 VC15 TS x32), it produced a blank page. It is possible that a similar issue is occurring on your system.