PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, March 1, 2022

[FIXED] PHP file permissions issue with Stripe payments on Amazon EC2

 March 01, 2022     amazon-ec2, lamp, php, stripe-payments     No comments   

Issue

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!


Solution

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.



Answered By - cpk
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing