Amazon Linux will end support on December 31, 2020, so You now need to migrate to the successor OS, Amazon Linux 2.
I couldn't simply update the OS, so I created a new instance of Amazon Linux 2 and re-installed the middleware.
I thought that I would like to save the trouble of those who do the same thing later, so I summarized it. I hope it helps you, "I want to run PHP on EC2 for the time being !!!": pray:
■ It will be smooth if you finish the preparation of VPC and subnet first. (Because it is linked when creating an EC instance)
If you like, please refer to the following articles! ・ Procedure from creating VPC to creating public / private subnet ① ・ Procedure from creating VPC to creating public / private subnet (2)
■ I will not touch on the construction procedure using CloudFormation this time.
mb
modulephp-xml
modulephp.ini
** ▼ Reference: Procedure to create EC2 instance from AWS console **
When you install the LAMP environment, you need to ssh to your EC2 instance.
Be sure to select Select an existing key pair
or Create a new key pair
when creating an EC2 instance.
** ▼ Command to ssh to EC2 instance: **
ssh -i [Key pair path] ec2-user@[Public IPv4 address]
sudo cp /usr/share/zoneinfo/Japan /etc/localtime
sudo vi /etc/sysconfig/clock
/etc/sysconfig/clock
#ZONE="UTC"
ZONE="Asia/Tokyo"
UTC=true
sudo vi /etc/sysconfig/i18n
/etc/sysconfig/i18n
LANG=ja_JP.UTF-8
sudo hostnamectl set-hostname <hostname>
** ▼ Reference: Rename Amazon Linux Instance Hostname --Amazon Elastic Compute Cloud **
It is difficult to understand if you keep the default, so it is recommended to change the host name to something that is easy to understand.
sudo vi /etc/cloud/cloud.cfg
Add preserve_hostname: true
to the end
** ▼ Reference: How to fix the host name when booting from a custom AMI on Amazon Linux 2 | Developers.IO **
Get a custom AMI → When I started a new instance from the custom AMI, the host name setting was disabled, so it is a setting to keep it enabled.
** ▼ Reference: Tutorial: Installing a LAMP Web Server on Amazon Linux 2-Amazon Elastic Compute Cloud **
mb
module** ▼ Reference: Using mbstring with php on Amazon Linux-Qiita **
PHP has a variety of functions for working with multibyte strings. (Example: mb_substr
)
If you don't install the mb
module, you will get a Fatal error
when you run PHP.
php-xml
modulesudo yum install --enablerepo=remi,remi-php70 php-xml
sudo systemctl restart httpd
You can check that it is installed without any problem with the following command.
[ec2-user@XXXXXX ~]$ yum list installed | grep php-xml
php-xml.x86_64 7.2.34-1.amzn2 @amzn2extra-php7.2
[ec2-user@XXXXXX ~]$
I got a PHP error Fatal error: Class'DOMDocument' not found
because I didn't have the php-xml
module installed: japanese_goblin:
php.ini
** ▼ Reference: [PHP] Settings you want to do after installing PHP --Qiita **
If you copy the initial state /etc/php.ini
, make a backup, and then change the settings, you can restore it in case something goes wrong, so you can rest assured.
The session.hash_function
etc. described as" security settings "in the above article have been removed from PHP 7.1.0
, so no settings are required.
--Rename Amazon Linux Instance Hostname --Amazon Elastic Compute Cloud -How to fix the host name when booting from a custom AMI on Amazon Linux 2 | Developers.IO -Tutorial: Install LAMP Web Server on Amazon Linux 2-Amazon Elastic Compute Cloud --Using mbstring with php on Amazon Linux --Qiita -[PHP] Settings you want to do after installing PHP-Qiita -PHP: Runtime Settings --Manual
Recommended Posts