Due to space limitations, the following is a short article:
Apache2 is a commonly used web server software, while PHP is a widely used server-side script language. In the process of building a website, sometimes you encounter the problem that Apache2 cannot correctly parse the PHP file, causing the PHP code to fail to execute.
This kind of problem is usually caused by Apache2 not configuring the PHP module correctly, or the PHP module is incompatible with the version of Apache2. There are generally two ways to solve this problem, one is by modifying the configuration file of Apache2, and the other is by installing the missing PHP module.
The following uses the Ubuntu operating system as an example to illustrate the specific processing method:
sudo apt-get install libapache2-mod-php
This command will install Apache2 and PHP modules at the same time to ensure that PHP can be parsed correctly.
sudo nano /etc/apache2/apache2.conf
Find the following line in the file:
<FilesMatch .php$> SetHandler application/x-httpd-php </FilesMatch>
Make sure this The code segment exists and is not commented out. After saving and closing the file, restart the Apache2 service:
sudo systemctl restart apache2
<?php phpinfo(); ?>
Place the test.php file in the root directory of Apache2 (usually /var/www/html/), and then access http://localhost/test.php in the browser. If the PHP information can be displayed normally, it means that the PHP parsing has been completed. Configure correctly.
Through the above steps, you should be able to solve the problem of Apache2 not being able to correctly parse PHP files. Make sure to update the Apache2 and PHP versions in a timely manner to ensure the security and stability of the server. Hope the above code examples are helpful to you.
The above is the detailed content of Apache2 cannot correctly parse PHP files. For more information, please follow other related articles on the PHP Chinese website!