Tuesday, December 1, 2009

Ubuntu and Apache: How to fix the error: "you have chosen to open ... which is a: application/x-httpd-php"

Ubuntu and Apache

How to fix the error: "you have chosen to open ... which is a: application/x-httpd-php"


Edit the Apache configuration file:
sudo nano /etc/apache2/apache2.conf

Find these 2 lines:
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps

Comment them by adding a pound sign in front:
#AddType application/x-httpd-php .php .phtml
#AddType application/x-httpd-php-source .phps

Add the following 2 lines right under the first 2 lines:
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps

Restart Apache:
sudo /etc/init.d/apache2 restart

Close your browser to clear its cache, and access your web page again.

Done.

-----

In a little more detail:

You can telnet to port 80 and view the web page. From the prompt, type:
telnet localhost 80
and then type "GET / HTTP/1.0" without the quotes, and press ENTER two times.
Note that there is a space before the slash and a space after the slash.
The page should then display. Here is an example of before the fix:

root@myfunserver:~# telnet localhost 80
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET / HTTP/1.0

HTTP/1.1 200 OK
Date: Tue, 01 Dec 2009 21:40:03 GMT
Server: Apache/2.2.11 (Ubuntu) PHP/5.2.6-3ubuntu4.4 with Suhosin-Patch
Last-Modified: Fri, 20 Nov 2009 08:18:29 GMT
ETag: "b7a6b-f-478c91ee61f40"
Accept-Ranges: bytes
Content-Length: 15
Connection: close
Content-Type: x-httpd-php

Website works

Connection closed by foreign host.
root@myfunserver:~#

Notice that the Content-Type is: x-httpd-php. Now, after the change:

root@myfunserver:~# telnet localhost 80
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET / HTTP/1.0

HTTP/1.1 200 OK
Date: Tue, 01 Dec 2009 21:40:03 GMT
Server: Apache/2.2.11 (Ubuntu) PHP/5.2.6-3ubuntu4.4 with Suhosin-Patch
Last-Modified: Fri, 20 Nov 2009 08:18:29 GMT
ETag: "b7a6b-f-478c91ee61f40"
Accept-Ranges: bytes
Content-Length: 15
Connection: close
Content-Type: text/html

Website works

Connection closed by foreign host.
root@myfunserver:~#

Notice that the content type is text/html.

No comments:

Post a Comment