Home  >  Article  >  Operation and Maintenance  >  How to solve the problem that php is not parsed under linux

How to solve the problem that php is not parsed under linux

王林
王林forward
2023-05-15 13:07:061214browse

When using a Linux system to deploy web applications, many people will encounter a very strange problem: the PHP file cannot be downloaded, but the PHP code is directly displayed. This kind of problem usually occurs in some older Linux systems, in which the PHP version is lower, or the PHP file processing module is not installed correctly.

On the one hand, the occurrence of this problem will affect the normal operation of the Web application, and on the other hand, it also involves the security issues of the Web application. Therefore, we need to solve this problem to ensure the normal operation of the system and the security of the application.

Here are some solutions:

  1. Check if PHP is installed correctly

In Linux systems, PHP is usually installed through Installed by a package manager such as yum or apt-get. If PHP did not install correctly, reinstall PHP and make sure all dependencies are installed as well.

  1. Check whether the Web server is correctly configured

The Web server needs to correctly configure the PHP interpreter so that it can run PHP code normally. For Apache servers, PHP can be configured by editing the httpd.conf file. Open the httpd.conf file and add the following code at the end of the file:

<IfModule php5_module>
  AddHandler application/x-httpd-php .php
  AddType application/x-httpd-php .php .html
  AddType application/x-httpd-php-source .phps
</IfModule>

This configuration will tell the Apache server to parse .php files into PHP script files and set the file type to application/x-httpd-php.

  1. Check whether the PHP module is enabled

In Linux systems, the PHP module needs to be manually enabled to work correctly. You can check whether the PHP module is enabled by executing the following command:

php -m

If the required module is not listed, edit the php.ini file and enable the corresponding module, for example:

extension=mysql.so
  1. Check PHP file permissions

When using a Linux system, ensure that the PHP file has sufficient permissions to run correctly. File permissions can be checked using the following command:

ls -l filename.php

If the file permissions are incorrect, use the following command to change the permissions:

chmod 644 filename.php

This will set the correct read and write permissions for the PHP file to ensure The file works fine.

The above is the detailed content of How to solve the problem that php is not parsed under linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete