sysautomation
asked on
Apache is downloading php files instead of displaying them
OS and server information:
CentOS 6.4 (Final)
Apache 2.2.15
PHP 5.5.1
I previously had php 5.3.x installed but decided to upgrade. I first uninstalled the php 5.3.x and then installed php 5.5.1 but after the installation completed apache did not parse the php files it just downloaded them. I
For the record I have the following lines in my httpd.conf and php.conf that should make php work but don't:
AddHandler application/x-httpd-php .php5 .php4 .php .php3 .php2 .phtml
AddType application/x-httpd-php .php5 .php4 .php .php3 .php2 .phtml
AddType application/x-httpd-php-so urce .phps
AddHandler php5-script .php
<IfModule !worker.c>
LoadModule php5_module modules/libphp5.so
</IfModule>
<IfModule worker.c>
LoadModule php5_module modules/libphp5-zts.so
</IfModule>
but no luck.
CentOS 6.4 (Final)
Apache 2.2.15
PHP 5.5.1
I previously had php 5.3.x installed but decided to upgrade. I first uninstalled the php 5.3.x and then installed php 5.5.1 but after the installation completed apache did not parse the php files it just downloaded them. I
For the record I have the following lines in my httpd.conf and php.conf that should make php work but don't:
AddHandler application/x-httpd-php .php5 .php4 .php .php3 .php2 .phtml
AddType application/x-httpd-php .php5 .php4 .php .php3 .php2 .phtml
AddType application/x-httpd-php-so
AddHandler php5-script .php
<IfModule !worker.c>
LoadModule php5_module modules/libphp5.so
</IfModule>
<IfModule worker.c>
LoadModule php5_module modules/libphp5-zts.so
</IfModule>
but no luck.
How did you install PHP 5.5.1?
On my CentOS 6.7 system, 'libphp5.so' is in '/usr/lib/httpd/modules' (the 'modules' directory in 'httpd' is a link to '/usr/lib/httpd/modules'). I don't have any of those other lines in my 'httpd.conf'.
I do have 'php.conf' in '/etc/httpd/conf.d'.
ASKER
I also have libphp5.so in /etc/httpd/modules
I also have php.conf in /etc/httpd/conf.d
I also have php.conf in /etc/httpd/conf.d
So how did you install PHP 5.5.1? It's not in the repositories for CentOS 6. Only PHP 5.3.3 is there and that is the only version that CentOS 6 supports.
No points for this, please, but PHP 5.3 is no longer supported at all, not even for security issues. The current version is PHP 7+ and there are a couple of PHP 5 branches that still get support. You can find the currently supported versions on the upper right side of http://php.net. PHP 5.5.34 and PHP 5.6.20 are current.
Well, Ray the problem with is that the different Linux distributions do Not support the newer versions. If you want the newer versions on CentOS and Ubuntu, you have to compile them yourself which is a non-trivial task. CentOS and Ubuntu don't even put things in the same directories so you really have to know what you are doing.
The current version of CentOS 7 comes with PHP 5.4.16. http://distrowatch.com/table.php?distribution=centos
The current version of Ubuntu 15.10 comes with PHP 5.6.11. http://distrowatch.com/table.php?distribution=ubuntu
The current version of CentOS 7 comes with PHP 5.4.16. http://distrowatch.com/table.php?distribution=centos
The current version of Ubuntu 15.10 comes with PHP 5.6.11. http://distrowatch.com/table.php?distribution=ubuntu
This is your problem: in php.conf
AddType application/x-httpd-php .php5 .php4 .php .php3 .php2 .phtml
change all those to
AddType text/html .php .php4 .php3 .php2 .php5 .phtml
Now if you have all those variances for extension, add them to the handler so that when it is seen apache will preprocess them with PHP.
php5-script is where you would add all those extensions.
The handler will preprocess them and output will be seen/treated as text/html.
If you want to maintain the current configuration, double check what content-type: your PHP code outputs ?
defining an extension as an application means when apache sees the extension, it will not try to process it it will offer it to the user as the application/.. stream
Where did you see that as the configuration option?
AddType application/x-httpd-php .php5 .php4 .php .php3 .php2 .phtml
change all those to
AddType text/html .php .php4 .php3 .php2 .php5 .phtml
Now if you have all those variances for extension, add them to the handler so that when it is seen apache will preprocess them with PHP.
php5-script is where you would add all those extensions.
The handler will preprocess them and output will be seen/treated as text/html.
If you want to maintain the current configuration, double check what content-type: your PHP code outputs ?
defining an extension as an application means when apache sees the extension, it will not try to process it it will offer it to the user as the application/.. stream
Where did you see that as the configuration option?
ASKER
Thanks but I replaced
AddType application/x-httpd-php .php
with
AddType text/html .php .php4 .php3 .php2 .php5 .phtml
But still the same problem.
Sorry I don't know how to add handlers etc.
AddType application/x-httpd-php .php
with
AddType text/html .php .php4 .php3 .php2 .php5 .phtml
But still the same problem.
Sorry I don't know how to add handlers etc.
Do you actually have the various .phpx type files?
You already have the handler defined
AddHandler php5-script .php
Which entries are from which file?
You already have the handler defined
AddHandler php5-script .php
Which entries are from which file?
ASKER
I am actually using RoundCube Webmail and it has index.php and other .php files.
No .php4 .php3 .php2 .php5 files are there.
No .php4 .php3 .php2 .php5 files are there.
After you made the changes suggested earlier, did you reload/restart the Apache webserver?
Double check where and when you have handler/type set
Try the following using a telnet session,
Telnet server 80
Head http://yourdomain/somepage.php http/1.1
Host:
Referrer:
See what the http response is.
Double check where and when you have handler/type set
Try the following using a telnet session,
Telnet server 80
Head http://yourdomain/somepage.php http/1.1
Host:
Referrer:
See what the http response is.
ASKER
Yes I restarted httpd service.
Here's my configuration of this virtualhost
$ telnet myservername 80
Trying 51.255.21.82...
Connected to myservername.
Escape character is '^]'.
Head http://courseboy.com/webmail/index.php http/1.1
Host: courseboy.com
HTTP/1.1 200 OK
Date: Fri, 22 Apr 2016 07:19:53 GMT
Server: Apache/2.2.15
Last-Modified: Wed, 20 Apr 2016 10:33:55 GMT
ETag: "3039-530e8216eaac0"
Accept-Ranges: bytes
Content-Length: 12345
Cache-Control: max-age=2592000
Expires: Sun, 22 May 2016 07:19:53 GMT
Vary: Accept-Encoding
Connection: close
Content-Type: text/html; charset=UTF-8
Connection closed by foreign host.
Here's my configuration of this virtualhost
<VirtualHost 51.255.21.82:443>
SuexecUserGroup "#501" "#502"
ServerName courseboy.com
ServerAlias www.courseboy.com
ServerAlias webmail.courseboy.com
ServerAlias admin.courseboy.com
DocumentRoot /home/courseboy/public_html
ErrorLog /var/log/virtualmin/courseboy.com_error_log
CustomLog /var/log/virtualmin/courseboy.com_access_log combined
ScriptAlias /cgi-bin/ /home/courseboy/cgi-bin/
ScriptAlias /awstats/ /home/courseboy/cgi-bin/
DirectoryIndex index.html index.htm index.php index.php4 index.php5
<Directory /home/courseboy/public_html>
Options -Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch +ExecCGI
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
#AddType application/x-httpd-php .php
AddType text/html .php .php4 .php3 .php2 .php5 .phtml
AddHandler fcgid-script .php
AddHandler fcgid-script .php5
FCGIWrapper /home/courseboy/fcgi-bin/php5.fcgi .php
FCGIWrapper /home/courseboy/fcgi-bin/php5.fcgi .php5
</Directory>
<Directory /home/courseboy/cgi-bin>
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
</Directory>
RewriteEngine on
RewriteCond %{HTTP_HOST} =webmail.courseboy.com
RewriteRule ^(.*) https://courseboy.com:20000/ [R]
RewriteCond %{HTTP_HOST} =admin.courseboy.com
RewriteRule ^(.*) https://courseboy.com:10000/ [R]
RemoveHandler .php
RemoveHandler .php5
php_admin_value engine Off
FcgidMaxRequestLen 1073741824
<Files awstats.pl>
AuthName "courseboy.com statistics"
AuthType Basic
AuthUserFile /home/courseboy/.awstats-htpasswd
require valid-user
</Files>
RedirectMatch /cgi-bin/mailman/([^/\.]*)(.cgi)?(.*) https://courseboy.com:10000/virtualmin-mailman/unauthenticated/$1.cgi$3
RedirectMatch /mailman/([^/\.]*)(.cgi)?(.*) https://courseboy.com:10000/virtualmin-mailman/unauthenticated/$1.cgi$3
Alias /pipermail /var/lib/mailman/archives/public
php_value memory_limit 32M
php_value suhosin.session.encrypt Off
IPCCommTimeout 41
SSLEngine on
SSLCertificateFile /home/courseboy/ssl.cert
SSLCertificateKeyFile /home/courseboy/ssl.key
</VirtualHost>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I am unable to follow further as not getting time. Therefore closing this question.