DEV Community

Cover image for PHP 7 on Amazon Web Services (AWS) Cloud9
fadilxcoder
fadilxcoder

Posted on

PHP 7 on Amazon Web Services (AWS) Cloud9

Hello guys,

On thing that I've noticed when working with AWS cloud9 is that by default, it has PHP 5 installed. My question was what if I want to use PHP 7 for development ?

So in this post, I will explain to you how to setup your PHP 7 environement on AWS.

I am assuming that your AWS settings are as follows :

  • Environment type : EC2
  • Platform : Amazon Linux

Let's get started.

In your bash terminal on AWS, check your current PHP version,

ec2-user:~/environment $ php -v
Enter fullscreen mode Exit fullscreen mode

Normally you should see,

PHP version
PHP version

In order to do these changes, you will need to connect as root, so just type sudo su followed by yum update :

ec2-user:~/environment $ sudo su
[root@ip-172-31-30-164 environment]# yum update
Enter fullscreen mode Exit fullscreen mode

Update packages

Update packages

The process might take couple of minutes. Then remove any existing PHP packages.

[root@ip-172-31-30-164 environment]# yum remove php*
Enter fullscreen mode Exit fullscreen mode

PHP packages removal

PHP packages removal

Note : If you already have Apache 2.4, you don't need to remove your web server but if you have an older version, then remove it and install Apache 2.4,

[root@ip-172-31-30-164 environment]# yum remove httpd*
Enter fullscreen mode Exit fullscreen mode
[root@ip-172-31-30-164 environment]# yum install httpd24
Enter fullscreen mode Exit fullscreen mode

If everything is working fine till now, you did a great job.

Now it's time to install PHP 7. As you know, there are multiple versions, i.e : php7.0, php7.1, php7.2...

Below are the command for different php version you want to install.

PHP 7.0

[root@ip-172-31-30-164 environment]# yum install php70 php70-mysqlnd php70-imap php70-pecl-memcache php70-pecl-apcu php70-gd
Enter fullscreen mode Exit fullscreen mode

PHP 7.1

[root@ip-172-31-30-164 environment]# yum install php71 php71-mysqlnd php71-imap php71-pecl-memcache php71-pecl-apcu php71-gd
Enter fullscreen mode Exit fullscreen mode

PHP 7.2

[root@ip-172-31-30-164 environment]# yum install php72 php72-mysqlnd php72-imap php72-pecl-memcache php72-pecl-apcu php72-gd
Enter fullscreen mode Exit fullscreen mode

Let's say we want to have PHP 7.2

PHP 7.2

PHP 7.2

And here you have it..

PHP version

PHP version

You can easily work with PHP 7 on AWS now.

We did it

Top comments (2)

Collapse
 
leslieeeee profile image
Leslie

If you are a macOS user, ServBay.dev is worth to try. You don't need to spend some time or couple of days to setup anything. Just download it and you can use it immediately. You can run multiple PHP versions simultaneously and switch between them effortlessly.
Honestly, this tool has greatly simplified my PHP development and is definitely worth trying!

Collapse
 
codeflarelisa profile image
Lisa Lenhart

I bet you can go threw the same steps and update to a different version of PHP, such as 8.0.0