Many instructions for PHP and AWS PHP SDK installation and configuration
assume deep knowledge of PHP and ability to locate configuration files.
To get the AWS PHP SDK, you first need to get PHP running on Mac. PHP comes preinstalled but not running, here
is how to get it running:
1. Modify https.conf in directory /private/etc/apache2.
2. To change this file, you need to have access as root or super
user. I attempted to su - root and sudo
vi but this did not work as not supported on Mac. I had to sudo su as specified
here: http://serverfault.com/questions/43362/su-not-working-on-mac-os-x
3. Change httpd.conf as listed here: http://jason.pureconcepts.net/2012/10/install-apache-php-mysql-mac-os-x/
4. Test if PHP is running.
a. First need to create php.info file in eh DocumentRoot directotoy. The default directory (DocumentRoot) on the
Mac is "/Library/WebServer/Documents". You can always check:
/private/etc/apache2/httd.conf to find the DocumentRoot directory.
The php.info looks like:
<php phpinfo(); ?>
Some good information here: http://www.php.net/manual/en/install.macosx.bundled.php
b. Test using this in browser: http://localhost/info.php
6. Install AWS PHP SDK using Composer. The instructions are here: http://docs.aws.amazon.com/aws-sdk-php/guide/latest/installation.html
Follow these instructuions with these caveats/changes.
WARNING: Be careful where you run the install from. I ran from
/private/etc and my AWS SDK was installed in /private/key/vendor. So my AWS
PHP SDK is here: /private/etc/vendor/aws/aws-sdk-php
a. During this step- curl -sS
https://getcomposer.org/installer | php,
you will get this error.
#!/usr/bin/env php
Some settings on your machine make Composer unable to work properly.
Make sure that you fix the issues listed below and run this script
again:
The detect_unicode setting must be disabled.
Add the following to the end of your `php.ini`:
detect_unicode
= Off
A php.ini file does not exist. You will have to create one.
The file is in /private/etc/php.ini. You can copy /private/etc/php.ini.default to
/private/etc/php.ini and then modify php.ini to add detect_unicode
= Off.
Note: You need to be su and also need to chmod 666 to the php.ini
file to be able to edit it.
b. If you try this command "php composer.phar install", you
will probably get this error unless you did the first step. So do the
first step, if not done. It does not tell you this in instructions
but file needs to be here: /private/etc
The instructions for testing the installation are here:
http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/SettingUpTestingSDKPHP.html. I did the test for DynamoDB as this what I
was going to be using.
1.The
following is an example of such a configuration file, named config.php:
This file can be placed anywhere. I decided to put it here: /private/etc/vendor/aws/aws-sdk-php
1. The instructions tell you to execute these
commands (it may appear as thought they need to be issued from the command
prompt, this is not the case):
use Aws\DynamoDb\DynamoDbClient;
// Instantiate the client with your AWS access
keys
$aws = Aws\Common\Aws::factory('./config.php');
$client = $aws->get('dynamodb');
This actually needs to be in a php file:
<?php
use Aws\DynamoDb\DynamoDbClient;
// Instantiate the client with your AWS access
keys
$aws =
Aws\Common\Aws::factory('/private/etc/vendor/aws/aws-sdk-php/config.php');
$client = $aws->get('dynamodb');
?>
When you run the test php fle (“php test.php”,
or whatever you called it), you will get the error: PHP Fatal error: Class 'Aws\Common\Aws' not found in
/private/etc/vendor/aws/aws-sdk-php/dynamodb/test.php on line
You need to add this line to all you php files:
1.require '/private/etc/vendor/autoload.php';
This is actually
documented here but unless you know PHP makes no sense:
http://docs.aws.amazon.com/aws-sdk-php/guide/latest/installation.html
Your updated test.php file will look like this:
<?php
require
'/private/etc/vendor/autoload.php';
use
Aws\DynamoDb\DynamoDbClient;
// Instantiate the client
with your AWS access keys
$aws =
Aws\Common\Aws::factory('/private/etc/vendor/aws/aws-sdk-php/config.php');
$client =
$aws->get('dynamodb');
?>
2. Also change line “$aws =
Aws\Common\Aws::factory("./config.php");” to point to location of
configuration file. In my case, you can
see the change made above:
Aws\Common\Aws::factory('/private/etc/vendor/aws/aws-sdk-php/config.php');
It’s interesting to read content. I appreciate your blog AWS online Training Hyderabad
ReplyDelete