AWS

How to Install PHP on AWS EC2 Windows Instance

PHP may not be used mainly as a programming language, but it sure is used for different frameworks that are working on PHP, like Apache2 and NginX. These frameworks, or more precisely, these web servers, are one of the biggest reasons people use EC2 instances. Because they want to test deploy a server in a safe environment. This post will teach you how to install PHP on an AWS EC2 instance that is running a Windows \ Windows Server operating system.

Pre-req: Setup and Connect to an EC2 Windows Instance

You can skip this step entirely if you already have an EC2 instance set up and connected. If not, then simply visit the AWS Console by clicking here and then under the “Build a solution” section, click on the option that says “Launch a virtual machine”:


From the launch wizard:

    • Give your Virtual Machine a unique name.
    • Choose Windows as its AMI.

 

For the key pair, either create a new one or use an already existing one (If you have it on your PC):


After that, simply click on the Launch button:


This will create the EC2 instance, and the following prompt will be visible on the UI:


After that, you need to make an RDP connection with the newly created EC2 instance, for that, simply head to the EC2 instance dashboard and select your newly created EC2 and right-click and select the “Connect” option:


The next page will contain the login information for an RDP connection, except for the password. To get the password, simply click on the “Get password” link:


On the “Get Password” Page, click on the Upload Private Key File button and upload the key pair that you have associated with the EC2 instance and then click on the “Decrypt password” button:


Doing this will redirect you back to the connection page, which will now contain the password as well:


On your PC, open up “Remote Desktop Connection” software:


And paste the “public dns” from the connection page into the “Computer” field, and the username as “Administrator” and click on the connect button:


After that, you will be prompted to provide the password, so copy the password from the “Connection” page and click on the “Ok” button:


After that, you will be connected to the newly created EC2 instance using the RDP connection:


At this point, you can proceed to the installation of PHP.

Installation of PHP in EC2 Windows Instance

Open up a browser inside the EC2 instance, and head over to the following link:

https://www.php.net/downloads.php

 
From there, select the version that you want and click on “Windows Download”.


After that, select the binary that you want to download and click on the “Zip” option:


Once the download is finished, right-click on the downloaded file and then click on the “Extract All” option:


Set the extraction path to “C:\PHP\” and click on the “Extract” button:


After the extraction, press the “Windows” icon and search for “Env” and open up the following application:


Click on the “Environment Variables” button:


Select “Path” under the user and click on “Edit”:


Add in a new entry with the path being “C\PHP\” and click on the “OK” button:


After that, simply open up a command prompt and type the following command to verify the existence of PHP on the EC2 Windows Instance:

php -v

 
This command will return:


This confirms that PHP was successfully installed on the EC2 instance running on Windows.

Conclusion

Installing PHP on an EC2 instance that is running the Windows Operating system is a simple and easy process. Go over the official website of PHP and download your preferred binaries. Extract the downloaded file in any location of your choice and then add that location to the “Path” of environment variables.

About the author

Abdul Mannan

I am curious about technology and writing and exploring it is my passion. I am interested in learning new skills and improving my knowledge and I hold a bachelor's degree in computer science.