Tiny PHP Script runs fine on dev server, fails on hosted server - php

Im pretty new to php, Ive got a linux server running php 5.5.9 , and all I want it to do is take whatever is sent to it in an http post, and dump it to a file.
Currently the code I have is this
<?php
file_put_contents("outputfile.txt", file_get_contents('php://input'));
It works 100%, does exactly what I want when its on my own server.
When I upload it to my web server (HostGator) it gets a 500 error. The web server is running php 5.4, Im not sure if thats the issue.
Basically what Im trying to learn is why doesnt this work, and how do I fix it, its a pretty simple script.

John and Louis pointed me to the right answer, it was entirely the permissions on the folder the files were in. The folder was 777 for some reason, and switching it to 755 like the files were fixed it.
I had no idea that could even cause a 500 error

Related

Problem in nginx server not running php files suddenly

I have a dynamic website developed by native PHP on a server using NGINX which was functioning normally, but suddenly it broke down such that the PHP files no longer run and just download automatically to the client with the code whole source when he tries to excute that files. I don't know why it happened, and is it because of a hacking or an internal server problem. When I contact the web host, he says that a php file that is causing this problem, knowing that I haven't changed anything at last time.
Please clarify the cause of this problem if you have an idea !! Thank you in advance.
There is no idea yet ? I add that the last time, the host re-initialized the configuration of the VPS, and the website is now running well. It is clear that the problem was in the configuration! But I ask the same question, why did this failure happen? I want to know the reason: if the problem comes from PHP files or from the server itself !!

xampp does not run php, browser asks what to do with file

I just installed xampp from www.apachefriends.org.
Per the instructions I ran
sudo ./xampp-linux-*-installer.run
Then xampp started and I saw the gui control panel. Everything great so far.
I verified it works by going to localhost in Firefox. I saw the welcome screen.
Then,I navigate to my test html. It is a contact which runs a php file when clicking submit.
Then firefox sends a message what to do with my php script, sendeail (save or select an application). sendeail is a no-brainer php script for email which I found on the internet years ago. It works when running from my server and has been for ages. Just now running locally with xampp started, Firefox doesn't know what to do with it.
What should Firefox do with this file?
Do I have to configure xampp somehow?
I couldn't test in Opera or Chrom(ium), the submit form doesn't appear for some reason on my local computer, but whose browsers work fine when accessing the page on the server.
I am running in Linux Ubuntu 16.4 LTS, Firefox 65.0.1 64-bit
--- edit ---
Specifically, the question is that the web browswer sees the .php file and tries to open it, what must I do for the web browser to be passed the code within the .php file, instead?
.apachefriends.org has no explanation of this. I found another page which explains, https://www.fayazmiraz.com/how-to-run-your-first-php-code/.
One has to put their php code into /etc/xampp/htdocs
That's so counter-intuitive!!! OMG why can't I keep my files in my development directory. Yeah, I can test this way, but I'll have to keep updating that directory whenever I have a program change! Thank you

phpmyadmin display source code on Chrome

On VPS I have phpmyadmin on Apache2.
On every computer and IE n my computer works fine, but on Chrome on my computer it shows the source code of phpmyadmin index. Why? Is there any settings or what?
This is just happening only on this page on Chrome on my PC.
The error "shows the source code of phpmyadmin index" you are describing implies that your apache cannot run the php file. This can be happen for 3 reasons
You are pointing your web browser to the folder something/ and apache does not know that it has to search for the index.php file. Fix your apache configuration or point directly your web browser to this file something/index.php
Your apache is not configured to use the php interpeter
You don't have php installed to your machine
Think that found solution, but don't know what cause it.
I used CCleaner to clean all Chrome browser data
- the simplest solution xD

php - Script Not Working After Being Uploaded To Live Server

I am developing a php script locally using XAMPP, it is working on my local server, but after being uploaded to the linux live server, there are many things those won't work. Most of the problems are caused by file path writing.
For example:
require('inc/config.php') working in XAMPP but it does not work on live server or vice versa. So I need to change it to require('config.php') in order to make it able to be called on live server.
That seem like ruining the whole of my works and make the times I invested become useless.
My question:
What's the common solution can I use to prevent that kind of problem? Is using full path to call a file the best practice?
Is there any local development environment for Windows like XAMPP that able to simulate linux server structure, so there will be nothing need to be fixed after finishing development on local server then upload it to linux live server?
Please somebody help..
Best Regards
You don't need to change anything, just in the index.php give your script proper path to your scripts using set_include_path().

Debugging 500 Internal Server Error on PHP running on IIS7 cluster

Recently my ISP switched our website to an IIS7.0 high availibility cluster. The website is running on PHP5.2.1 and I can only upload files (so no registry tweaks). I had tested the website before and everything seemed to be working, but now the checkout page fails with:
500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed.
As error messages go, this isn't very informative. I've tried:
ini_set('display_errors', 1);
ini_set('error_log', $file_php_can_write_to );
but both don't seem to do anything.
Anyone know how to get better debugging output?
Edit : Looks like we have a similar question in serverfault. Check it out
Turning off IIS7 custom errors will allow error responses from your application to be sent to remote clients without being censored by the IIS7’s custom errors module.
You can do this from the IIS7 Admin tool by running “Start>Run>inetmgr.exe”, selecting your website/application/virtual directory in the left-hand tree view, clicking on the “Error Pages” icon, clicking “Edit Feature Settings” action, and then selecting “Detailed Errors”
Source
It's very common when you change server you cannot load your apps. I have solved this problem running php.exe instead of loading your apps on the browser:
1) Run it using the Command line > C:\php\php.exe OR
2) Run Windows Explorer, look for it, and double click on c:\php\php.exe.
3) You are gonna see what DLL's are having conflicts and causing the 500 error.
4) Solve the conflicts finding the right DLL's for your windows version and you should be able to see your apps through the browser.
The best of the lucks.
IIS does this, it's really annoying and I could not find a fix, which is what caused me to switch to an Apache server for my local machine. Unfortunately, if you don't have control over your server, the best you can do is either test it locally on an apache set up or ask your host to allow the error messages.
I did some googling, thisthis looks like what you need. Wish that was around when I was trying to get IIS running.

Categories