OpenShift PHP with .html Extension - php

As we know, it is easy to get Apache to handle .html pages as PHP pages by adding the following line to http.conf:
AddHandler application/x-httpd-php .php .html
How can this be done in OpenShift?
How can I edit http.conf in OpenShift?
Or is there another way?

Have you tried using a .htaccess file? Try the answer from this stackoverflow question, but use php instead of perl/python: perl on php application on openshift

It's easy, just add the following line to your .htaccess in any folders that it is required: AddHandler application/x-httpd-php .php .html

Related

Apache runs php files with or without .php extension

My apache runs php files with or without .php extension, How can I disable this and force apache to run php files only with .php extension. I don't want to use .htaccess, this might be an apache config. does anyone know how to disable this option?
Thanks for the answer but using Addtype as you mentioned did not ever work for me, all by itself, even in PHP 5..
Here's what I've tried that DOESN'T work with this version of PHP:
Options +ExecCGI
AddType application/x-httpd-php .php .nusuffix
AddHandler x-httpd-php5 .php .nusuffix
This worked for PHP 5. Now, does not.
This is for a hosted account, so I must do this via .haccess.
You can check your httpd.conf what extensions are configured, it need need to be following. if there is change in your file you can change it to following and restart the apache
AddType application/x-httpd-php .php
more details : https://wiki.archlinux.org/index.php/Apache_HTTP_Server
please add if anything is missing

what code do i put in .htacess to use php?

Just wanted to know what code I have to put in my .htaccess file so my html pages read php that im going to put in there, (just a contact form), I did find it once but can't remember, sorry and thanks.
You have to convert your html files to php
put this line in your .htaccess if you're using apache2
AddType application/x-httpd-php .html .htm
but make sure that your .htaccess file is in the root directory of the website
If you want PHP in HTML files to be interpreted just add this line to your .htaccess file:
AddType application/x-httpd-php .html .htm
HTML Pages don't read your PHP. Instead Apache is reading your file and executes it with a PHP interpreter if some PHP is in there.
Just in case you have a debian server with apache2 you can apt-get install php5. But there is a lot more work to do, for example FCGI and so on.

Adding Handler to htaccess causes file to download, removing Add Handler directive causes internal server error

I'm stuck trying to figure out what directives my htaccess file for a directory needs. To give a little background, I was messing around with AddType and AddHandler to try to get html files to run php in them. I was adding directives like:
AddType application/x-httpd-php .php .html
and
AddType application/x-httpd-php5 .php .html
That didn't work, so I tried adding handlers as well:
AddHandler x-httpd-php .php .html
and
AddHandler application/x-httpd-php .php .html
That still didn't give me what I wanted so I tried many combinations, like:
AddType application/x-httpd-php .php .html
AddHandler php-script .php .html
I even tried combinations with SetHandler
AddType application/x-httpd-php .php .html
AddHandler php-script .php .html
SetHandler application/x-httpd-php .php html
I tried every imaginable combination of AddType and AddHandler found on the web.
!===== This is important ======!
I realized that its not good practice to have php run your html files just so you can run php in the html. I am no longer trying to do that. The only reason I'm posting this part above is to give you an idea on some things I've changed. These changes were made to the htaccess file at a directory above the root.
!==============================!
Now that I'm no longer trying to run my php in html files I cleared the AddType, AddHandler, and SetHandler directives from the htaccess file. But now I get an internal server error when trying to run php files.
So I tried putting some stuff back. If I had a handle, the browser now downloads the php instead of running it.
I should note that any php running below the directory I changed works fine. But everything in that directory or subdirectory of that directory has this same problem with php files.
I have tried deleting the htaccess file in that directory, but that does not work, I get an internal error.
If I turn Override off, I get an internal error.
Something I changed is persisting in that directory and I'm wondering how to either
a. turn it off
b. add the correct handler to that htaccess file so that php files are run again (like they are on the rest of the server)
I did have the exact same issue so I deleted all the content of .htaccess and started trying only with handlers until I figured it out. My local .htaccess copy had the following SetHandler:
AddHandler x-httpd-php5-3 .php
In my case it worked after changing it to:
AddHandler application/x-httpd-php5 .php
It seems the whole trick is only the handler, I tried this solution in 2 different servers with different configurations and in both cases just changing AddHandler worked. If this doesn't work for you try a different handler for php.
Hope it helps.
Just realized I left this up unanswered after I solved the problem. If someone has a similar problem and is reading this : Check the permissions on all associated folders. I can't remember the specifics but one of the directories involved (I believe it was the htaccess directory) had permissions that persisted after changing some things and then changing them back.

Can I change the accepted extensions by PHP?

I'd like to accept other type of files that contains PHP code. For example, it would be nice to read an .aspx file by PHP as if it were .php.
Add this to your .htaccess file in Apache to make html parse as PHP:
AddType application/x-httpd-php .html
You can extrapolate what you need to do from there. :-)
Use this htaccess rule:
AddType application/x-httpd-php .php .aspx
Yes, this is done in your Apache configuration. You tell apache what kind of files you want it to send to the PHP engine. You can do this configuration the same way you do other apache configuration - in the main config file, per site, or in .htaccess files.

Apache AddHandler: Run ASP code as PHP

I'm running XAMPP.
Is there a line I can add to .htaccess or http.conf to make ASP be parsed and handled as PHP pages?
I had it setup before but can't remember how to do it. What I've tried so far hasn't worked.
Edit: None of these solutions are working, I've tried everything.
If none of the solution above is ok with you, check your Server API with phpinfo(); method.
If Server API is CGI or FAST CGI change it to Apache 2.0 Handler.You can do it using Plesk Panel or CPanel.
Another option is not to change Server API but .htaccess or httpd.conf : http://avinashsing.sunkur.com/2012/04/19/how-to-map-another-file-extension-to-the-php-parser-through-htaccess/.
But I have solved my problem with the first one.
Maybe try this:
AddHandler php5-script .php .asp .aspx .ascx .ashx .asmx
AddType text/html .php .asp .aspx .ascx .ashx .asmx
Add this to your httpd.conf
AddType application/x-httpd-php .asp .aspx .ascx .ashx
Try adding this line to .htaccess;
AddHandler application/x-httpd-php .asp
Apparently it is not as efficient as adding the equivalent to http.conf but it works even when you don't have access to http.conf.
Adding this line in .htaccess enabled me to execute PHP code written in .asp pages:
AddHandler php5-script .php .asp
Apache does not have a module for ASP processing. You have to use IIS for that. Modern IIS can run PHP so you may do it the other way around, use IIS and plug PHP into it.

Categories