AWS LAMP stack install on Red Hat 7.4

In preparation of a webserver and attached backend database migration I have started working on building an AWS base image for this purpose.
I chose RHEL 7.4 (Maipo) as it is Free Tier eligible on AWS.  No hefty bills from the current host – Yay!
As the expected load won’t be too high a micro instance should be sufficient however can scale up/out later bases on demand (more on this on a later post).

Gone through the AWS Launch wizard I connected to the new Red Hat server and started installing the LAMP stack which has gone smooth and dandy up to the MySQL server install.

Upon trying to launch MySQL I ran into a problem. No matter the error was saying the unit was not found.

[ec2-user@ip~]$ sudo service mysqld start
Redirecting to /bin/systemctl start mysqld.service
Failed to start mysqld.service: Unit not found.

A quick reference check it was found that RHEL are using MariaDB as the default DB hence not finding the package as such.
Using wget managed to pull the latest repo from MySQL.com and then installed successfully replacing MariaDB.

[ec2-user@ip~]$ sudo yum install wget
[ec2-user@ip~]$ wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm                    
[ec2-user@ip~]$ sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
[ec2-user@ip~]$ sudo yum install -y mysql-server

###
Installed:
 mysql-community-client.x86_64 0:5.6.37-2.el7
 mysql-community-libs.x86_64 0:5.6.37-2.el7
 mysql-community-server.x86_64 0:5.6.37-2.el7

Dependency Installed:
 libaio.x86_64 0:0.3.109-13.el7
 mysql-community-common.x86_64 0:5.6.37-2.el7
 perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7
 perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7
 perl-DBI.x86_64 0:1.627-4.el7
 perl-Data-Dumper.x86_64 0:2.145-3.el7
 perl-IO-Compress.noarch 0:2.061-2.el7
 perl-Net-Daemon.noarch 0:0.48-5.el7
 perl-PlRPC.noarch 0:0.2020-14.el7

Replaced:
  mariadb.x86_64 1:5.5.56-2.el7        mariadb-libs.x86_64 1:5.5.56-2.el7

###

Only one thing remained was to start both Apache and MySQL and set them to start at boot.

[ec2-user@ip~]$ sudo systemctl enable httpd && sudo systemctl enable mysqld
[ec2-user@ip~]$ sudo systemctl start mysqld && sudo systemctl start httpd

To test Apache created a simple website in HTML using touch and vim

[ec2-user@ip html]$ sudo touch index.html
[ec2-user@ip html]$ sudo vi index.html

Once happy with the site, restarted the server and checked whether Apache and MySQL started at boot.

Both started successfully!

To bootstrap the server the following bash script can be used:

#!/bin/bash
sudo yum update -y
sudo yum install -y httpd php php-mysql wget
sudo wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
sudo yum install mysql-server
sudo systemctl enable httpd && sudo systemctl enable mysqld
sudo systemctl start mysqld && sudo systemctl start httpd

If you found this helpful leave a comment or drop me a message. Thanks!

Disclaimer here!

Leave a Reply

Your email address will not be published. Required fields are marked *