How to SetUp PHP 7.3 with Apache 2.4 in Amazon Linux 1

In this article, I will show you how you can install PHP 7.3 with Apache 2.4 in Amazon Linux 1, which will help you to start your blog site or custom PHP project. But before that, let’s discuss what is PHP and Apache.

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.

So, PHP is a widely used language for writing web-based applications. A lot of widely used CMS is built on PHP which includes, WordPress, Joomla, Drupal, Magento, and many more. There are many Frameworks of PHP available like Laravel, Symphony, CodeIgniter, etc., which are used to build scalable web applications. So if you planning to become a web developer then chances are you need to know PHP a lot. And also as a DevOps, you need to ensure that your server environment is ready for the correct version of PHP according to your application.

Next comes on Apache, The Apache HTTP Server, colloquially called Apache, is a free and open-source cross-platform web server software, released under the terms of Apache License 2.0. Apache is developed and maintained by an open community of developers under the auspices of the Apache Software Foundation.

So apache is a web server that really works well with PHP and it’s optimized for PHP. So if you are building an application with PHP then chances are that its web server will be Apache. In this example below, we will show how can we install PHP7.3 with Apache 2.4 in Amazon Linux 1. Our whole example here is based on an assumption is that we are using Amazon Linux 1 as the operating system. If you are something else like Ubuntu / CentOS / Redhat, then please check out our other articles.

How to Install PHP 7.3 with Apache 2.4

First you create an EC2 instance by following our other article here. After that please connect to the instance using Putty or Terminal.

After you have connected to the instance, please run the following commands.

sudo yum update -y
sudo yum install httpd24
sudo yum install php73 php73-mysql php73-mbstring
sudo service httpd start
sudo chkconfig httpd on

Explanation of the each line is given below

1. sudo yum update -y

YUM (Yellowdog Updater Modified) is an open-source command-line as well as graphical based package management tool for RPM (RedHat Package Manager) based Linux systems. It allows users and system administrators to easily install, update, remove, or search software packages on a system. So sudo yum update -y basically updates all packages to its the latest version from a repository list which is managed by Amazon for Amazon Linux 1. This is always a good practice to run “yum update” first before you install any software.

2. sudo yum install httpd24

This basically installs Apache 2.4 on your Linux machine. So there any many variants of Apache available at the moment when I am writing, but we want to be specific on a version of 2.4, so that’s why we run this command.

3. sudo yum install php73 php73-mysql php73-mbstring

This single line of code actually installs PHP version 7.3 along with some useful PHP extensions like MySQL, mbstring, and other common PHP extensions. Here we also applied the same strategy to fix a version of 7.3 in the installation time. If your application requires a different version then go check out our other articles where we have shown how you can install a different PHP version.


4. sudo service httpd start

This single line of command starts the Apache server on your machine, and now if you browse your IP address then you might see the default Apache page, which means that you have successfully installed Apache and it’s running properly. If you don’t see the Apache default page but rather you an error page of ‘Connection timeout’ then something is wrong and please go through the process again. Also, check out the ‘security group’ settings and see if PORT 80 and PORT 443 are open for all or not. You need to open port 80/443 publicly to have viewed view the pages that Apache delivers.


5. sudo chkconfig httpd on

This command actually sets Apache to start automatically when the server reboots. This is really important to remember otherwise you need to manually start your Apache server when the system reboots.

A video tutorial of what I have explained above is given below, which you can view and practice.

Conclusion

In summary, I can say that PHP is one of the most popular languages when it comes to web development. It’s super-fast, secure, and easy to use. With a combination of PHP and Apache, it’s unbeatable in terms of performance. Many many popular CMS is written on PHP for this reason and if you want to set up a blog or e-commerce site then chances are that it’s already developed in PHP. So learning how to install PHP with Apache in AWS can be really handy and I would definitely suggest practicing this by yourself so that you can become an expert on it.

Leave a Comment

Your email address will not be published.