Retrieve instance metadata using PHP for IMDSv2


# Update the system
apt update && apt upgrade -y

# Install Apache and PHP
apt install -y apache2 php libapache2-mod-php

# Enable and start Apache service
systemctl enable apache2
systemctl start apache2

cat <<EOF > /var/www/html/index.php

$token_url = '';
$internal_ip_url = '';
$public_ip_url = '';

// Create a stream for token
$opts = [
    "http" => [
        "method" => "PUT",
        "header" => "X-aws-ec2-metadata-token-ttl-seconds: 21600",

// DOCS:
$context = stream_context_create($opts);
$token = file_get_contents($token_url, false, $context);

// Create a stream for internal and public IP
$opts_ip = [
    "http" => [
        "method" => "GET",
        "header" => "X-aws-ec2-metadata-token: $token",

$context_ip = stream_context_create($opts_ip);
$internal_ip = file_get_contents($internal_ip_url, false, $context_ip);
$public_ip = file_get_contents($public_ip_url, false, $context_ip);

echo "<h1>EC2 Instance IP Addresses</h1>";
echo "<p>Internal IP: " . $internal_ip . "</p>";
echo "<p>Public IP: " . $public_ip . "</p>";


# Set proper permissions
chown apache:apache /var/www/html/index.php

Authentication for multiple subdomain in CakePHP


Let say you have subdomain and

If you login to and when you access you notice that you already authenticate althought the subdomain is different.

So how you want to differentiate the session after you login since the default setup of CakePHP will consider you on the same site ?

Edit your bootstrap.php in app / config and try to put this line .

ini_set(‘session.cookie_domain’, env(“HTTP_HOST”));

You can validate your cookie by installing Firebug in Firefox and installing an extension for firebug which is call ‘Firecookie‘.

Cheers ~!

jQuery Multiple File Upload Plugin


i’m using this plugin

If you are using it with cakephp , dont just rely on the form helper .. u need to add something to make it work.

<?php echo $this->Form->file(‘attachments’ , array(‘class’ => “multi max-2” , ‘name’ => “data[Attachment][]”)); ?>

notice the [] and also need to overwrite the name because if you dont , it will only upload the latest file that u select even if have already select more than 1 .