How to setup PHP7.1, Apache 2.2 on Amazon Linux

05-Apr-2018

OK I had no plan to make this post but recently I spent quite a few time to figure it out so thought to make it as a post for self and others who come across issue to deal with this simply thing otherwise.

Alright, let’s proceed!

Below is the details of my Amazon Distro:

Repo setting

Before we proceed, first make sure that you are downloading stuff from the right repository. Remove all irrelevant repos, specially remi-safe.

You can see list of available repos, if all goes well you should see something like below:

Alright, we now have correct repo setup, it’s time to install things

Apache 2.2 Installation

yum install http httpd-devel

Make sure it’s Apache2.2. I tried Apache2.4 but it gives error:

/etc/httpd/conf/httpd.conf: Syntax error on line 6 of /etc/httpd/conf.d/php.conf: Cannot load modules/libphp7.so

So I rather will settle with Apache 2.2

Check whether httpd is up or not:

sudo service httpd restart

PHP 7.1 Installation

Two different PHP Packages need to be installed:

  • PHP Module for Apache so that php based websites can work
  • PHP CLI for executing scripts from command line. It’s needed for php artisan.

sudo yum install --enablerepo=webtatic php71w

If installed well you should be able to execute PHP. In my case phpinfo() shows:

PHP7.1 with Apache

Now, we need to install PHP CLI:

sudo yum install --enablerepo=webtatic php71w-cli

and if all installed well:

OK before I quit, we gotta install PDO and MySQL libraries:

sudo yum install php71w-pdo
sudo yum install php71w-mysqlnd

By doing php-m it should show PDO available.

Conclusion

In this post I tried to make your life easier by making this quick and short post so that others don’t waste hours to figure things out.

If you like this post then you should subscribe to my blog for future updates.

* indicates required




If you like my work then you can donate me in bitcoins