How to setup PHP 7.1 in Amazon Linux 1

You are currently viewing How to setup PHP 7.1 in Amazon Linux 1

What is PHP?

According to Wikipedia, PHP is a general-purpose scripting language especially suited to web development. It was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1994; the PHP reference implementation is now produced by The PHP Group. 

install php 7.1 in amazon linux server

Why do you want to install PHP on your server?

So now you know what is PHP, it’s important to know why do you want to install PHP on your web server? There can be couple of reasons to install PHP on your web server.

First of all, you want to install WordPress blog on your server, but then WordPress requires PHP to be preinstalled to function properly. It’s better to use PHP 7+ version for your WordPress site so that, you get a faster and secure blog.

Next, you might want to run a web application is which is developed using Laravel framework. Then you must install a latest PHP version into your server so that, Laravel application functions properly.

Lastly, you build a custom application which is developed using PHP language. So then you must have to install PHP on your web server.

So may be whatever your reason is, if you decided to install PHP on your server, then I can help you to setup that. This example assumes that you want to install PHP 7.1 in Amazon Linux 1, which is a CentOS 6 based Linux distribution.

First, create an ec2 instance by following the instructions given in my other article. After you have created the instance, now connect to it via putty or terminal.

To install PHP 7.1 in Amazon Linux 1, run the following commands in your terminal.

#!/bin/bash
sudo yum update -y
sudo yum install -y httpd24 php71  php71-mysqlnd php71-mbstring
sudo yum install -y php71-mcrypt php71-zip php71-intl php71-gd
sudo service httpd start
sudo chkconfig httpd on
sudo groupadd www
sudo usermod -a -G www ec2-user
sudo usermod -a -G www apache
sudo chown -R ec2-user /var/www
sudo chgrp -R www /var/www
sudo chmod 2775 /var/www
find /var/www -type d -exec sudo chmod 2775 {} +
find /var/www -type f -exec sudo chmod 0664 {} +
sudo chmod 0777 /var/lib/php/7.1/session
sudo service httpd restart

If you have successfully run all those commands without any error, then I assume you have installed PHP 7.1. You should probably see a landing page like this.

After you installed PHP 7.1, then please make change to the following settings,

Change php memory limit

First, edit this file

sudo vi /etc/php-7.1.ini

Then search for the settings memory_limit, and then put the value to 256M

After you have changed the memory limit, search for this settings date.timezone and the change date.timezone to Europe/Amsterdam or any timezone that you belong to. The list of all possible timezones can be found here.

If you have php 5.6 already installed and now want to upgrade to PHP 7.1 then run the following command.

sudo alternatives --set php /usr/bin/php-7.1

Conclusion

PHP is one the most popular language in this planet when it comes to web development. All top CMS like WordPress, Joomla, Magento or Drupal run on PHP. It’s really fast and easy to install. Due to this popularity of PHP, I suggest you should know how to install PHP on your EC2 instance. In this article, I have shown how you can install PHP 7.1 on Amazon Linux, which will definitely help you to grow on your devops journey. If you found any issue while you trying these commands, I suggest please put your issue in the comment section so that, I can look and help you out. 

 

Atiqur Rahman

I am MD. Atiqur Rahman graduated from BUET and is an AWS-certified solutions architect. I have successfully achieved 6 certifications from AWS including Cloud Practitioner, Solutions Architect, SysOps Administrator, and Developer Associate. I have more than 8 years of working experience as a DevOps engineer designing complex SAAS applications.

Leave a Reply