Install AWS SDK for PHP on AWS EC2 (PHP7.2 + Apache2.4.41 + OPCashe + Composer)

The flow of saving data in DynamoDB by hitting the API with AmazonLinuxEC2, I wanted to do it with PHP, so I tried to include AWSSDK for PHP.

However, various issues occurred, so I will transcribe it as a memorandum for myself. I hope it helps.

Amazon Linux version

$ cat /etc/system-release
Amazon Linux release 2 (Karoo)

Install PHP7.2 with AmazonLinux2 Extras Library

$ sudo amazon-linux-extras install php7.2
$ sudo yum install php php-mbstring

$ sudo yum list installed | grep php
php-cli.x86_64                        7.2.30-1.amzn2                 @amzn2extra-php7.2
php-common.x86_64                     7.2.30-1.amzn2                 @amzn2extra-php7.2
php-fpm.x86_64                        7.2.30-1.amzn2                 @amzn2extra-php7.2
php-json.x86_64                       7.2.30-1.amzn2                 @amzn2extra-php7.2
php-mysqlnd.x86_64                    7.2.30-1.amzn2                 @amzn2extra-php7.2
php-pdo.x86_64                        7.2.30-1.amzn2                 @amzn2extra-php7.2

Reference: https://qiita.com/owlbeck/items/20f3e5402cb782f6291e

Install Apache

$ sudo yum install httpd
$ systemctl start httpd
$ systemctl status httpd
● httpd.service - The Apache HTTP Server
   Active: active (running) 

Install OPCashe

sudo yum install php-opcache

Install Composer

$ curl -sS https://getcomposer.org/installer | php
$ ls
composer.phar

$ php composer.phar
$ mv composer.phar /usr/local/bin/composer
$ composer

The last two lines just moved to a place where PATH is available. Now you can display a cool logo. Reference: https://getcomposer.org/doc/00-intro.md Reference: https://qiita.com/kakijin/items/02364adacf36410f449e

Started using AWS SDK for PHP

Do it in the root folder of your project.

$ sudo -i
$ cd /usr/local/bin/composer
$ vi composer.json //Write to json

composer.json


{
    "require": {
        "aws/aws-sdk-php": "3.*"
    }
}

The AWS SDK for PHP3 series is compatible with PHP7.2 series.

$ php composer.phar install
$ composer require aws/aws-sdk-php

Write to php file and finish


require '/path/to/sdk/vendor/autoload.php';

End

Recommended Posts

Install AWS SDK for PHP on AWS EC2 (PHP7.2 + Apache2.4.41 + OPCashe + Composer)
[2020 version] How to install Python3 on AWS EC2
(For myself) AWS_Flask_3 (Install / Run Flask on AWS)
Install Docker on AWS
Execute python3 system with PHP exec () on AWS EC2
[AWS EC2] How to install Maven on Amazon Linux 2
Run AWS IoT Device SDK for Python on Raspberry Pi
[AWS] Install node.js on EC2 instance and execute sample program
Python --Install MySQLDB on EC2
Summary of yum packages required for pip install on EC2
Install pyenv on EC2 (Amazon Linux)
boto3 (AWS SDK for Python) Note
Install confluent-kafka for Python on Ubuntu
I easily built an operating environment for Python3 + Tornado on AWS EC2.
(For myself) Flask_AWS_1 (Install PHP, MySQL, phpMyAdmin, Python in AWS virtual environment)
How to install Apache (httpd) on CentOS7
How to install php7.4 on Linux (Ubuntu)
How to install Apache (httpd) on CentOS8
Install Python 3.8, Pip 3.8 on EC2 (Amazon Linux 2)
Try running TensorFlow's LeNet-5 MNIST, AlexNet MNIST on AWS EC2 t2.micro (for free tier)