Home  >  Article  >  Backend Development  >  What should I do if ubuntu apache2 cannot open php?

What should I do if ubuntu apache2 cannot open php?

藏色散人
藏色散人Original
2021-12-09 10:05:073164browse

ubuntu apache2 cannot open php solution: 1. Open the configuration file httpd.conf; 2. Modify the content to "AddType application/x-httpd-php .php..."; 3. Install apache Expansion pack is enough.

What should I do if ubuntu apache2 cannot open php?

The operating environment of this article: ubuntu 16.04 system, PHP5 version, Dell G3 computer.

ubuntu apache2 What should I do if I cannot open php?

Solution to the problem of Apache not parsing PHP under Ubuntu

In the past two days, the author encountered a very fucking problem-Apache cannot parse PHP code. It has been used well before. , suddenly hung up, and then I was frantically looking for solutions on the Internet, but most of them were version php5, but I was version 7, so I will post the solution for version 5 first:

Modify apache's configuration file httpd.conf

Found in httpd.conf:
AddType application/x-gzip .gz .tgz
Add below this line
AddType application/x-httpd-php .php

Look and continue to find:
DirectoryIndex index.html,
put this line Change it to
DirectoryIndex index.html index.htm index.php

and then find:
#ServerName www.example.com:80
Change to
ServerName localhost:80

However, Apache under Ubuntu does not have the configuration file httpd.conf, but refers to each configuration file through an apache2.conf Part of the configuration file, it is not easy to find that configuration in a configuration package, and I haven't found it yet. . .

However, Huangtian paid off and finally found a solution:

sudo apt-get install libapache2-mod-php

In this step, the apache expansion pack is installed, which can be used to parse php. I think it does not matter whether it is version 7 or version 5. All can be applied.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What should I do if ubuntu apache2 cannot open php?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn