LAMP is a term used to describe a set of open source software that, when combined, are used to support high-performance web applications, and its arguably one of the most widely used stacks for this purpose. It’s an acronym for Linux, Apache, MariaDB/MySQL, and PHP. It comprises three components (the Apache web server, MariaDB or MySQL relational database, and the PHP scripting language) residing on an operating system (Linux). Learn more about MySQL LDAP integration (and other databases) with Jumpcloud.
In this guide, we will demonstrate how to install the LAMP stack server on Amazon Linux 2.
Before getting started, here is what you need:
- An Amazon Linux 2 EC instance already launched and running.
- A security group configured to allow ports 22 and 80.
- SSH access to the EC2 instance from the terminal or using PuTTY SSH client.
Step 1: Install Apache Web Server
When you are connected to the EC2 instance using SSH, you should see the prompt shown below.
To get started with the installation of Apache, be sure to update all the packages to their latest versions as follows:
$ sudo yum update
The output displayed shows all the packages that were updated, including the Linux kernel.
To install Apache web server, run the command:
$ sudo yum install httpd
By default, the Apache service does not automatically start upon installation. To start the service, run the following command:
$ sudo systemctl start httpd
In addition, consider enabling the Apache web server to automatically start on reboot or system startup.
$ sudo systemctl enable httpd
Next, verify that Apache is running:
$ sudo systemctl status httpd
The output above confirms that, indeed, Apache is running. If you’d like, you can take additional steps to harden the security of Apache. You can also confirm that Apache is working as expected by browsing the public IP of the Amazon Linux 2 EC2 instance as follows:
Please note that AWS walks you through additional steps, prompting you to restrict admin access to specific IP addresses (among other potential security configurations) to secure EC2 instances. It is recommended that you read through their access control options carefully and understand their intention and impact on your specific use case before moving on.
With the installation of Apache out of the way, let’s head over to the next step.
Step 2: Install MariaDB Database Server
MariaDB is a hugely popular open source relational database that is a fork of MySQL. It was developed by the original developers of MySQL right after Oracle expressed its interest in acquiring MySQL — which it did in 2010. Although MySQL does remain a popular choice by many, this tutorial has opted to follow the MariaDB route.
The MariaDB database is built to provide stability, reliability, and the latest security features required in production workloads. Some of the cool features that ship with MariaDB include advanced clustering with Galera Cluster 4, high-performance storage engines such as InnoDB, seamless scaling, and support for big data analytics.
To install MariaDB, run the command:
$ sudo yum install mariadb-server
The command installs the MariaDB server alongside other Perl dependencies that are required for it to function as expected.
Once installed, start the MariaDB service.
$ sudo systemctl start mariadb
And like the Apache web server, enable it to start on boot.
$ sudo systemctl enable mariadb
Now, check to confirm that MariaDB is running.
$ sudo systemctl status mariadb
The default settings that come with MariaDB are not secure and the database engine is prone to breaches. As such, you need to take an extra step to harden it.
To harden MariaDB and tighten its security, run the following script:
$ sudo mysql_secure_installation
By default, MariaDB allows you to log in as root without providing a password — which is risky for obvious reasons. To remediate this, be sure to set a root password for MariaDB.
For the remaining prompts, press “Y” to remove anonymous users, drop remote root login requests, and remove the test database which makes the database server prone to cyberattacks. Finally, reload the privilege tables to apply the changes.
Once that is finalized, now try logging into MariaDB and provide the root user password you just configured.
$ sudo mysql -u root -p
This ushers you to the MariaDB shell. From here, you can perform database operations such as running queries and updating tables.
Step 3: Install PHP and PHP Extensions
The remaining component of the LAMP stack that we need to install is PHP. PHP is a popular server-side scripting language that supports dynamic and static web pages.
We are going to install PHP 7.4 and then additional PHP packages.
With PHP 7.4, you also need to install the
amazon-linux-extras package, which provides the latest software packages for Amazon Linux. So, run the following command to install
amazon-linux-extras and PHP 7.4:
$ sudo yum install amazon-linux-extras php7.4
This also installs other PHP packages such as php-cli, php-fpm, php-json, php-mysqlnd, and php-pdo.
Once the installation is complete, you will get a summary of all the installed packages.
At this point, you can proceed and install your preferred additional packages as follows:
$ sudo yum install php-curl php-mbstring php-intl php-opcache php-soap php-gd php-xml php-mysqli
Once again, you will get a summary of all the installed PHP packages.
To confirm the version of PHP installed, run the command:
$ php –version
Alternatively, you can get information about the PHP version and other PHP modules on your server by creating a test
phpinfo file in the webroot directory.
$ sudo vim /var/www/html/info.php
Then paste the following lines:
phpinfo() function provides information about the PHP configuration and settings on your Amazon Linux 2 instance.
Save the changes and exit the file. Then restart the Apache web server.
$ sudo systemctl restart httpd
Now, launch your browser and visit the following URL:
You should get the following webpage displaying your PHP version and a host of other PHP-related information. Note that PHP should always be kept current to ensure security and performance.
Now that you have the LAMP stack installed on your Amazon Linux 2 instance, how do you go about managing your system? Fortunately, the JumpCloud Directory Platform enables simplified server access management from a single cloud-based console.
With our cloud directory platform in place, IT admins can secure and manage:
- LTS Amazon Linux, RHEL, CentOS, Debian, and Ubuntu instances
- Cloud RADIUS and LDAP servers
- AWS, GCP, Azure, and other providers
- Automated API processes, commands, and policies
- User provisioning plus 2FA auth and SSH keys
- And much more
Whether you’re interested in exploring JumpCloud’s integration with AWS Single Sign-On (SSO) or the ability to manage Windows, Mac, and Linux systems with a single platform, the best way to test out our capabilities is to use the platform for yourself. Sign up for JumpCloud Free today and manage up to 10 users and 10 systems for free, for as long as you need until you scale to more.