PHP
AWS
EC2
Composer

[AWS]EC2にPHPとComposerを一発でインストールするスクリプトを作った


下記のファイルをEC2(Amazon Linux 2)に置く


install.php.sh

# Install PHP

if which php > /dev/null 2>&1; then
echo 'PHP has already installed'
else
echo 'Install PHP'
sudo amazon-linux-extras install php7.2
sudo yum install -y php-mbstring php-xml
echo 'PHP installed'
fi

# Install Composer
if which composer > /dev/null 2>&1; then
echo 'Composer has already installed'
else
echo 'Install Composer'
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '93b54496392c062774670ac18b134c3b3a95e5a5e5c8f1a9f115f203b75bf9a129d5daa8ba6a13e2cc8a1da0806388a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
sudo mv composer.phar /usr/local/bin/composer
echo 'Composer installed'
fi



実行権限を付与

[ec2-user]$ chmod +x install.php.sh

[ec2-user]$ ls -ll
-rwxr-xr-x 1 ec2-user ec2-user 325 Nov 01 10:39 install.php.sh


ファイルを実行

[ec2-user]$ ./docker.php.sh

Composer!

[ec2-user]$ composer

______
/ ____/___ ____ ___ ____ ____ ________ _____
/ / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
/_/
Composer version 1.7.2 2018-08-16 16:57:12


インストール済みの場合

下記の文字列が表示される。

[ec2-user]$ ./install.php.sh

PHP has already installed
Composer has already installed

ご自由にお使いください。


姉妹編

[AWS]EC2にDockerとDocker Composeを一発でインストールするスクリプトを作った