Basic Ingredients for Installing Drupal on an AWS EC2 Instance
Let's Slice 'n Dice
AWS Linux Instance
First you need to launch a new EC2 instance and select an operating system. What we're going to use on this project is a light weight linux distro compiled by Amazon. As of this writing, the latest we have is Amazon Linux AMI 2018.03.0 (HVM), SSD Volume Type - ami-0b2c2a754d5b4da22. We chose this distribution because it already has the basic items we need, although we still need to update them later.
Proceed with the rest of the launch process until you are able to connect to the server through ssh. Log-on to the server and update the Operating system by running the below command.
is an application that turns your EC2 instance into a web server. This means you will be able to serve websites from your instance. Apache may already be installed and updated with the above shell command but if you are not sure, verify that Apache is running using the below shell command.
If the response is other than : "httpd (pid xxxx) is running...", then you may need to install/reinstall Apache. Run the below command to install Apache.
Apache does not run automatically after installation so you need the command :
By default, port 80 is already enabled with a firewall in this AWS AMI. To make sure that this is true, run the below command :
This command will list all the network addresses from this host and are space separated. Alternatively, you can also use curl to your localhost or from another instance within your VPC. There are more advanced things you can do depending on your application needs which we will not discuss in this article. To list a few, you may need to :
- Manage Apache Process - This is where you setup when Apache stops and starts as well as adding custom logging methods.
- Setup Virtual Hosts - Apache can run more than 1 virtual host much like IIS for windows
- Adjusting Linux Permissions for Virtual Hosts - Depending on the hosts, you may need to enable some special ports and adjust other components
The next instructions will be based on a local MySQL setup for simple website. If you are planning to create a website for a corporate application then you may want to consider using a separate MySQL server using EC2 or another AWS service called RDS.
The MySQL version we are installing is version 8 which is stable as of the time of this writing. If you need a different version you may want to visit here.
Since we already performed the system update earlier we can just proceed with the below commands.
Download the preferred installer :
Prepare the repository for installation :
We can proceed with the next steps once the update and download completes. Below are the installation steps.
Read carefully the prompts as the version you are installing might have different requirements. If you are installing the same version then you can just simply type "Y" and pressing the enter key at each question.
Finally you can start the MySQL service and create your own database.
This is the server side scripting that powers Drupal. Drupal works on all supported PHP versions but the recommended version is the best choice because. they will remain supported longer. In this tutorial we will installing PHP 7.4 because of its improvement in speed and caching.
The version we are installing is RPM and is in the remi-php74 repository for CentOS 7. If you do not have the required repositories yet, add them with the following command.
You may need to do cleanup of old PHP version if you haven't done so. To know the existing PHP version run :
This will show you the current version. Run the next command if it outputs an older version where "xx" is the version number.
Next install the new PHP version of your choice using the below command.
Accept on all the prompts and that's it. You may need to install additional PHP packages depending on your purpose. Some Drupal solutions require packages like php-bcmath for an e-commerce module perhaps. To install additional packages, you can use the below methods :
Single package installation
Multiple package installation example :
That's it! You can move on to installation of Drupal. But as bonus, we will add composer and drush. You can run Drupal without these but we found it handy in many instances.
This is a dependency management tool in PHP. You use this t0 declare libraries needed for your project and it will do the install/update for you. This is used in Drupal specially by modules which has 3rd party libraries.
Installing composer is pretty easy. Since we already performed local repository updates earlier we can go directly to the installation. But if you got here just for composer, make sure you update the local repository first before installing the composer dependencies.
Next, download the composer installer script.
It is best to verify the integrity of the downloaded script. Use the below commands to verify.
Then, use the following script to compare the official hash against the one we just downloaded.
After the verifying the installer, it's time for the actual installation process.
Once you get the successful install message, you can then verify if composer is already available using the below command.
You got the composer version? Now it's time to remove the installer script.
This is a scripting interface used in Drupal. This comes in handy especially with AWS EC2 instances wherein you only have access to the shell interface.
We will be using composer to install drush and this should be very quick.
The above will install the main components and below is installing the drush launcher.
That's it! You're all set now for an exciting Drupal development experience.