My Journey Migrating from IPv4 to IPv6 on AWS

As cloud hosting costs continue to evolve, it’s essential to review and optimize our infrastructure. Recently, I embarked on a journey to transition from IPv4 to IPv6 on my AWS-hosted website, primarily to eliminate the cost associated with AWS Elastic IPs. Here’s a recap of my experience, challenges, and ultimate success.


Why Migrate to IPv6?

AWS charges for Elastic IPs (EIP) even when they are associated with a running EC2 instance, making it a recurring cost that can be avoided. By adopting IPv6, I aimed to:

  • Reduce expenses: Stop paying for Elastic IPs.
  • Modernize the infrastructure: Future-proof my website’s networking.
  • Enhance accessibility: Ensure the website is reachable over both IPv4 and IPv6 as more networks adopt the newer protocol.

Initial Setup: My AWS Environment

My website, hosted on an AWS EC2 instance, runs a LAMP stack on Amazon Linux 2. The setup includes Apache, MariaDB, and PHP, supporting a WordPress-based site. Before the migration, the site was accessible only via IPv4, with an AWS Elastic IP attached.


The Migration Process

Here’s a step-by-step breakdown of how I migrated to IPv6:

  1. Enable IPv6 in the VPC
    • I started by adding an IPv6 CIDR block to the VPC associated with my EC2 instance. AWS offers multiple options, but for simplicity, I chose an Amazon-provided IPv6 CIDR block.
  2. Configure the Subnet for IPv6
    • Next, I allocated an IPv6 CIDR block to the subnet where my instance resides. This assignment allowed the EC2 instance to obtain an IPv6 address.
  3. Update the Routing Table
    • One key step was updating the VPC’s routing table. I added a route for ::/0 with the Internet Gateway as the target. While there was already a route for 0.0.0.0/0 (IPv4), the IPv6 traffic required this new route.
  4. Modify Apache Configuration for IPv6
    • I adjusted the Apache httpd.conf settings:
      • Replaced Listen 80 with Listen [::]:80
      • Replaced Listen 443 with Listen [::]:443
    • However, I retained the <VirtualHost *:80> and <VirtualHost *:443> blocks, as they worked fine for both IPv4 and IPv6 connections.
  5. Update DNS Settings
    • I added an AAAA record in my DNS configuration to ensure that the domain resolves to the server’s IPv6 address. This step was crucial for making the website accessible over IPv6.
  6. Restart Apache
    • After making these changes, I restarted the Apache service. Everything was configured properly, and the web server could now handle requests over IPv6!

Challenges Faced and Lessons Learned

  1. Routing Table Misconfiguration
    • Initially, the IPv6 setup didn’t work. I realized I had missed adding the ::/0 route in the routing table, which is crucial for directing IPv6 traffic to the Internet Gateway.
  2. Firewall and Security Group Settings
    • Ensuring security groups allowed IPv6 traffic on ports 80 (HTTP) and 443 (HTTPS) was another important task. Always double-check inbound and outbound rules when dealing with new protocols.
  3. Understanding Apache’s Dual-Stack Configuration
    • Although I only needed to add Listen [::]:80 and Listen [::]:443, I was initially unsure if I needed to update <VirtualHost> settings for IPv6. Fortunately, the existing configuration worked without modification.

The Result: Cost Savings and Modernization

With everything set up correctly, my website is now accessible over both IPv4 and IPv6. More importantly, I no longer need to pay for an AWS Elastic IP, leading to tangible cost savings. The transition has made my website’s networking stack future-proof while ensuring broader accessibility as more users move to IPv6.


Conclusion

Migrating from IPv4 to IPv6 may seem daunting, but with a clear objective, proper planning, and attention to details like routing and DNS configuration, the process is smooth and rewarding. If you’re looking to cut down on cloud costs or modernize your setup, I highly recommend considering an IPv6 migration.

Amazon Linux 2 – PHP 7.4 upgrade to PHP 8.0

A client’s machine installed with PHP 7.4 needs to be upgraded to PHP 8.0 sooner as the former is reaching “End of Life” support (until November 28, 2022). Here’s a link about it: https://www.php.net/supported-versions.php

These are the steps made to complete the upgrade procedure:

#1. On the client’s Amazon Linux 2 Virtual Machine, list the PHP versions available.

[root@ip-172-31-84-24 html]# amazon-linux-extras | grep php
42 php7.4=latest enabled [ =stable ]
_ php8.0 available [ =stable ]

#2. Disable php 7.4.

[root@ip-172-31-84-24 html]# amazon-linux-extras disable php7.4
Beware that disabling topics is not supported after they are installed.
. . . .
. . . .
42 php7.4 available [ =stable ]
. . . .
51 php8.0 available [ =stable ]
. . . .

#3. Check PHP list again.


[root@ip-172-31-84-24 html]# amazon-linux-extras |grep php
42 php7.4 available [ =stable ]
51 php8.0 available [ =stable ]

#4. Enable PHP 8.0.

[root@ip-172-31-84-24 html]# amazon-linux-extras enable php8.0
. . . .
41 postgresql11 available [ =11 =stable ]
_ php7.4 available [ =stable ]
. . . .
51 php8.0=latest enabled [ =stable ]
. . . .
Now you can install:
# yum clean metadata
# yum install php-cli php-pdo php-fpm php-mysqlnd

#5. Clean metadata.

[root@ip-172-31-84-24 html]# yum clean metadata
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Cleaning repos: amzn2-core amzn2extra-docker amzn2extra-epel amzn2extra-kernel-5.10 amzn2extra-php8.0 epel epel-debuginfo epel-source epel-testing epel-testing-debuginfo epel-testing-source
52 metadata files removed
20 sqlite files removed
0 metadata files removed

#6. Now check available php installation.

[root@ip-172-31-84-24 html]# yum info php
. . . .
232 packages excluded due to repository priority protections
. . . .
Available Packages
Name : php
Arch : x86_64
Version : 8.0.20
Release : 1.amzn2
Size : 3.3 M
Repo : amzn2extra-php8.0/2/x86_64

#7. Running the command in #4 as suggested gives an error

[root@ip-172-31-84-24 html]# yum install php-cli php-pdo php-fpm php-mysqlnd
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
232 packages excluded due to repository priority protections
Resolving Dependencies
–> Running transaction check
. . . .
–> Processing Dependency: php-common(x86-64) = 8.0.20-1.amzn2 for package: php-cli-8.0.20-1.amzn2.x86_64
. . . .
–> Finished Dependency Resolution
Error: Package: php-json-7.4.26-1.amzn2.x86_64 (@amzn2extra-php7.4)
Requires: php-common(x86-64) = 7.4.26-1.amzn2
Removing: php-common-7.4.26-1.amzn2.x86_64 (@amzn2extra-php7.4)
. . . .
You could try using –skip-broken to work around the problem
You could try running: rpm -Va –nofiles –nodigest

#8. Remove the php-json* package

[root@ip-172-31-84-24 html]# yum remove php-json
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Resolving Dependencies
–> Running transaction check
—> Package php-json.x86_64 0:7.4.26-1.amzn2 will be erased
–> Processing Dependency: php-json(x86-64) = 7.4.26-1.amzn2 for package: php-common-7.4.26-1.amzn2.x86_64
–> Running transaction check
. . . .
. . . .
–> Finished Dependency Resolution
Removed:
php-json.x86_64 0:7.4.26-1.amzn2
Dependency Removed:
php-cli.x86_64 0:7.4.26-1.amzn2 php-common.x86_64 0:7.4.26-1.amzn2 php-fpm.x86_64 0:7.4.26-1.amzn2 php-mbstring.x86_64 0:7.4.26-1.amzn2 php-mysqlnd.x86_64 0:7.4.26-1.amzn2 php-pdo.x86_64 0:7.4.26-1.amzn2
php-xml.x86_64 0:7.4.26-1.amzn2
Complete!

#9. Install PHP and other dependencies

[root@ip-172-31-84-24 html]# yum install php php-{pear,cgi,common,curl,mbstring,gd,mysqlnd,gettext,bcmath,json,xml,fpm,intl,zip}
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
232 packages excluded due to repository priority protections
Resolving Dependencies
–> Running transaction check
. . . .
Installed:
php.x86_64 0:8.0.20-1.amzn2 php-bcmath.x86_64 0:8.0.20-1.amzn2 php-cli.x86_64 0:8.0.20-1.amzn2 php-common.x86_64 0:8.0.20-1.amzn2 php-fpm.x86_64 0:8.0.20-1.amzn2 php-gd.x86_64 0:8.0.20-1.amzn2
php-intl.x86_64 0:8.0.20-1.amzn2 php-mbstring.x86_64 0:8.0.20-1.amzn2 php-mysqlnd.x86_64 0:8.0.20-1.amzn2 php-pear.noarch 1:1.10.12-9.amzn2 php-xml.x86_64 0:8.0.20-1.amzn2
Dependency Installed:
php-pdo.x86_64 0:8.0.20-1.amzn2 php-process.x86_64 0:8.0.20-1.amzn2
Complete!

#10. A continuation the output in #9 installation message. Just disregard this.


php-json is available in Amazon Linux Extra topic “php7.4”

To use, run
# sudo amazon-linux-extras install php7.4

#11. Now check PHP version

[root@ip-172-31-84-24 ~]# php -v
PHP 8.0.20 (cli) (built: Jun 23 2022 20:34:07) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.20, Copyright (c) Zend Technologies