Which file to adjust to allow .php files to display (not download) - php

I'm having some trouble with .php files which seem to download when I open them in the browser.
I've googled around and have found this is because the server doesn't know how to parse the file, and that I need to add something to make this work.
I've read around and it seems I need to add something to a .htcaccess file, but I'm not sure where this is or where I should create it.
Below is a screenshot of the directories on my server if anyone can help me.

You mean something like
AddHandler x-httpd-php5 .php
...this should already be in place in the master Apache file (or the appropriate .conf include - in some distributions, configuration directives may be parceled between several configuration files) if PHP is properly installed.

you dont need to generate a htaccess file for this issue, if you installed a web server and php and configured them properly.

Related

Bypass htaccess file restriction

So, I was trying to upload PHP files into Apache server, and whenever I browse the file I get 403 error due to htaccess limitations. It turns out that the server only accepts certain files such as "gif|jpg|png|mp4" and other image files.
Is there any way to bypass this?
NOTE **: I tried the old ways,**PHP, Phtml .. it didn't work.
Is there any way to bypass this?
Not unless you edit the .htaccess file or find a vulnerability in Apache.
Note that simply uploading a PHP file doesn't mean the server can execute it. The server needs to have the right software installed and Apache needs to be configured to handle PHP files. You can't just drop a PHP file in there and expect it to work, regardless of what the .htaccess file says.

Apache not executing index.php as php code when accessed as the folder

So on our website we have a folder, let's say its called (webroot)/foo
Inside this folder, there is a php file, index.php, that contains php code
When you go to website.name/foo/index.php, it works fine. However, when you just go to website.name/foo/, the php code contained in the file is not executed, and remains plain text. On some computers (but not others), the file also gets downloaded for some reason.
Note, I am not sure what files to show you, so tell me what files you need :) Also, I haven't really changed anything in any files.
Easy fix is adding DirectoryIndex index.php to a .htaccess of that directory but we should try to avoid using .htaccess and prefer httpd.conf
So check the conf file to make sure that index.php is present :
DirectoryIndex index.html index.php
Restart apache2.
Matter slightly depends on server OS and what packages installed. Ubuntu needed one package more for PHP for proper functioning.

Apache: Inline PHP not working on Linux

I am having trouble getting my PHP to work for my Apache server. I am running Oracle Linux, and used yum install php + yum install httpd to get my PHP and Apache. I have scoured the internet and done a couple of things:
Firstly, I have gone into my httpd.conf file and added LoadModule php5_module modules/libphp5.so. I have chosen to use the one in my php.conf file, which is the exact same one. Furthermore, I have done AddType application/x-http-php .php, so now my .php files are loading fine.
Secondly, I have tried to run my Apache server, and it works fine. It displays my index.html file, which I set with DirectoryIndex. However, when I tried to put php code into it, it got automatically commented out, which I assume is because I haven't set it to properly execute on the server side.
Now, with all that said, I am wondering what else I may be missing. I have two set-ups, one where I have a .php file, and one where the php is inline with the html.
index.html
<!DOCTYPE html>
<body>
<?php echo "Hello everybody."; ?>
</body>
</html>
index.php
<?php phpinfo(); ?>
The index.php file loads fine, but the index.html doesn't run the php code. How do I get the inlined version of php to work?
Note: I have set-up my Mac OS to work fine with .php files, but it is also having trouble with inline php within an Html file. What am I missing?
SOLUTION: Html files themselves cannot include php. Instead, the file must be a .php extension, and within a .php file, you can have text, html, and JavaScript.
I do not think .html files are run through php at all so the <? ... ?> is treated as a normal tag which is invisible.
Change the extension to .php.
Php can contain html.
Edit:
There exists an option to configure for example Apache to parse html files as if they are php if you for some reason cannot or do not want to use php endings.
This, in my opinion, is not a good solution as it hides the fact that the page is dynamic to a future maintainer.
There is a similar question which has a similar problem:
PHP code is not being executed, instead code shows on the page
You might want to check out points 2 to 5 in the accepted answer:
LoadModule (It seems, that you have configured that properly)
Set Apache to run PHP files (this is the third point, and it seems that
you didn't configure that). Add the following line to your httpd.conf file: AddType application/x-httpd-php .php
Make sure, that you have the file ending with the .php extension (after you have configured Apache to run PHP files, see the previous point)
Change your code to use the long PHP opening tag (<?php instead of just <?)
You need to set short_open_tag = On in your php.ini file

PHP not working on html anymore

I have a website consisting mostly of html webpages. In order to allow me to use php in them, in my .htaccess file I added a bit of parsing code. A few days ago the php somehow stopped being executed and I'm still not sure why. I googled a few things and tried a few different types of parsing code but nothing seems to work. At the moment I have this line in my .htaccess file:
AddType application/x-httpd-php .html .htm
I have noticed one thing though, the php works fine at http://turkishbasics.com (my site's home page) but doesn't work at all for any other directories like http://turkishbasics.com/index.html or /contact.html
I contacted the hosting company, the guy mentioned something about Apache.?
Just how do I solve this problem?
Thanks
If you havent yet heard of Apache then this might be a bit above you. Skip out the AddType decleration and just save your files with a .php extension instead of html
To excute php code you need to write it in a php file (.php). Then execute the file in server.
You can not execute php code from html file (.html)
I guess when you execute http://turkishbasics.com it takes from http://turkishbasics.com/index.php

Browser ask me to download php file

I am a new guy in web programming who still learning new stuff.
I am creating a web form that consist of one INPUT. I connected the form in the HTML file to the php file. I am using a localhost MAMP that I recently installed on my MacBook.
The Problem : When I open the HTML file on a webpage and type something on the input box and hit submit, the browser ask me to download the php file rather processing it.
I don’t think the problem is related to mysql or apache since when I run the MAMP it give me green signs next to the apache and mysql.
Do anyone know how I can fix this problem and the let the php file open and transfer inputs to the database?
You'll want to make sure that Apache has been told that .php files should be treated as PHP scripts. That means one of the following:
LoadModule php5_module modules/libphp5.so # on windows, this'd be a .dll instead
AddHandler php5-script php
and/or
AddType application/x-httpd-php php
in your httpd.conf file.
open your file from virtual web-server, not filesystem.
you have to type something like
http://localhost/form.html
in your browser's address bar
Did you checked out http://www.mamp.info/en/documentation/faq.html#q8 ?
Maybe you didn't put your site into the folder "htdocs"?
PHP won't be parsed unless it is located in that folder or a subfolder.
That would explain the fact that your browser downloads the php file instead of getting the parsed php from apache.
This error is not only about php but general. The file that the browser suggets to down load is simply the script name, php or not.

Categories