PHP files will not open in the browser - only download. What do I need to change for it to work correctly?

I tried reinstalling PHP. PHP works and Apache2 works. I do not know why it does not open in the browser and displays normally.

Just so you know - my httpd.conf is empty - and instead, I have everything in apache2.conf. This is because I use Ubuntu.

Could you help me? I know this is simple, but I cannot find the answer.

+4
source share
8 answers

Do you have a virtual host in this project?

Do you open the php file with http: //localhost/file.php or directly as the file: //...../file.php?

+8
source

In my case, there was a modification of / etc / apache 2 / mods-enabled / php5.conf modulo userdir

<IfModule mod_php5.c> <FilesMatch "\.ph(p3?|tml)$"> SetHandler application/x-httpd-php </FilesMatch> <FilesMatch "\.phps$"> SetHandler application/x-httpd-php-source </FilesMatch> # To re-enable php in user directories comment the following lines # (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it # prevents .htaccess files from disabling it. <IfModule mod_userdir.c> <Directory /home/*/public_html> php_admin_value engine Off </Directory> </IfModule> </IfModule> 

The solution is inside the configuration file, just comment out the lines from <IfModule mod_userdir> to </IfModule> .

+5
source

In your apache conf:

 <FilesMatch \.php$> SetHandler application/x-httpd-php </FilesMatch> 

Remember to restart apache. Let me know how this happens.

+4
source

Try

 sudo a2enmod php5 

in the terminal. Assuming you are using php 5 :)

+2
source

If you are using php5 then the complete solution would be

 sudo apt-get install libapache2-mod-php5 

Then

 sudo a2enmod php5 
+2
source

I recently had this problem, but only when accessing the root of my site (for example, http://example.com ) - it worked as expected when accessing index.php explicitly (for example, http://example.com/index.php ).

The problem was that before creating index.php , I had the index.html file in the root directory of the website, but then I renamed it to index.html.bak to "move it to the side." Unfortunately, this does not stop it. For some reason, Apache will serve this file with the MIME type application/x-trash .
(Since the file /etc/mime.types contains a line reading " application/x-trash ~ % bak old sik ")

Maybe this will help someone else who scratches his head the way I was.

+1
source

In addition, when you move the site and you come across this, make sure that your .htaccess file does not specify a different method handler for php. We were faced with this move of the wordpress site for the client.

+1
source

Had the same problem - and it was in the .htaccess file that I accidentally downloaded from the server. Once you delete the .htaccess file, you need to clear the cache in order to download the .php file in the browser via http: //

0
source

Source: https://habr.com/ru/post/1344831/


All Articles