I'm trying to set up a basic Stripe Checkout page example on an EC2 instance but I can't seem to get any response from files that reference other PHP files. I'm following this example on GitHub.
I have a directory set up at /var/www/html/ that contains all my PHP files and another directory below this (at /var/www/html/stripe/) that contains the Stripe library. I can successfully run phpinfo.php and other PHP files but whenever I try to run anything from another file it won't respond.
Here's my files:
checkout.php
<?php require_once('./config.php'); ?>
<form action="charge.php" method="post">
<script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="<?php echo $stripe['publishable_key']; ?>"
data-amount="5000" data-description="One year's subscription"></script>
</form>
config.php
<?php
require_once('./stripe/lib/Stripe.php');
$stripe = array(
"secret_key" => "sk_test_mykey",
"publishable_key" => "pk_test_mykey"
);
Stripe::setApiKey($stripe['secret_key']);
?>
charge.php
<?php
require_once(dirname(__FILE__) . '/config.php');
$token = $_POST['stripeToken'];
$customer = Stripe_Customer::create(array(
'email' => 'customer@example.com',
'card' => $token
));
$charge = Stripe_Charge::create(array(
'customer' => $customer->id,
'amount' => 5000,
'currency' => 'usd'
));
echo '<h1>Successfully charged $50.00!</h1>';
?>
I've tried changing the relative file references (e.g. from './charge.php' to 'charge.php' which seems logical) but I haven't got anywhere.
I'm fairly new to PHP outside of a local environment and I'm not that experienced with Linux. Seems like maybe I have a permissions problem or that I'm not referencing files correctly. Any help much appreciated!
I had a similar issue with EC2 and image permissions where they would show up with the broken image icon, although the paths were correct. I realized that when FTPed to the server, the default chmod permissions were 600 if I recall correctly. I needed to change them to 700 in Transmit (great FTP GUI) for them to be executable. In your case you will need some sort of executable permission to allow that file to be run.
In addition, I would recommend adding ini_set('display_errors', 'On');
in your file to see if its a code error or not and deduce what your errors could be from there.
Hope this helps.