How to install Mautic in AWS with EC2, RDS and SES
Tags: mautic, aws, ec2, rds
Published: 2021-11-11 19:05:15

Follow this article to install Mautic on AWS EC2

<br/><br/>

### Start EC2 Instance

[Launch an instance](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EC2_GetStarted.html#ec2-launch-instance) with a recommended configuration of (2 CPU – 4GB RAM). 

To get more details about mautic hardware requirements [read this article](https://mauteam.org/infrastructure/mautic-installation-mautic-hardware-requirements/) 

You must also have configured your security group to allow SSH (port 22), HTTP (port 80), and HTTPS (port 443) connections.

To get more details about AWS Security Group [read this article](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/authorizing-access-to-an-instance.html)

<br/><br/>

### Connect to EC2 instance with SSH

Run this command, if necessary, to ensure your key is not publicly viewable.

    chmod 400 <certificate_name>.pem

Connect to your instance using its Public DNS

    ssh -i <certificate_name>.pem ec2-user@public_dns

<br/><br/>

### Install Apache Server

To ensure that all of your software packages are up to date, perform a quick software update on your instance.

    sudo yum update -y

Use the **yum install** command to install Apache web server

    sudo yum install -y httpd

Start the Apache web server.

    sudo systemctl start httpd

Use the **systemctl** command to configure the Apache web server to start at each system boot.

    sudo systemctl enable httpd


You can verify that  **httpd**  is on by running the following command:

    sudo systemctl is-enabled httpd


Now if open the public IPv4 address inside a browser you can see Apache home page


![Apache Home Page](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/images/apache_test_page_al2_2.4.png)


#### Setup Apache Permissions

Apache **httpd** serves files that are kept in a directory called the Apache document root. The Amazon Linux Apache document root is `/var/www/html`, which by default is owned by root.

To allow the `ec2-user` account to manipulate files in this directory, you must modify the ownership and permissions of the directory.

Add user (in this case, `ec2-user`) to the `apache` group.

    sudo usermod -a -G apache ec2-user

Log out and then log back in again to pick up the new group, and then verify your membership.

Change the group ownership of `/var/www` and its contents to the `apache` group.

    sudo chown -R ec2-user:apache /var/www

To add group write permissions and to set the group ID on future subdirectories, change the directory permissions of `/var/www` and its subdirectories.

    sudo chmod 2775 /var/www && find /var/www -type d -exec sudo chmod 2775 {} \;

To add group write permissions, recursively change the file permissions of `/var/www` and its subdirectories:

    find /var/www -type f -exec sudo chmod 0664 {} \;

<br/><br/>

### Install PHP

For installing Mautic 3 you need to install atleast php7.2 as per the time of writing this article

you can get current requirements [here](https://www.mautic.org/download/requirements)

you can use **amazon-linux-extras** commands to install php

    sudo amazon-linux-extras install -y php7.2

To test PHP, create a PHP file in the Apache document root.

    echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php

In a web browser, type the URL of the file that you just created. This URL is the public DNS address of your instance followed by a forward slash and the file name. For example:

    http://`my.public.dns.amazonaws.com`/phpinfo.php