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
Normally you should see,
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
The process might take couple of minutes. Then remove any existing PHP packages.
[root@ip-172-31-30-164 environment]# yum remove php*
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*
[root@ip-172-31-30-164 environment]# yum install httpd24
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
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
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
Let's say we want to have PHP 7.2
And here you have it..
You can easily work with PHP 7 on AWS now.
Top comments (2)
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!
I bet you can go threw the same steps and update to a different version of PHP, such as 8.0.0