AMAZON LINUX 2023: LAMP INSTALLATION
Nova Web Design Penang would like to give a simple tutorial on how to set up your LAMP virtual server using Amazon AWS. For developers who are hungry for fast and reliable performance, and wish to utilise the power of Amazon EC2, this tutorial will guide you step by step on how you could set up Apache, PHP, MariaDb and PhpMyAdmin. But before we even start to talk about the technicality of setup, what is Amazon EC2?
“An EC2 instance is simply a virtual server in Amazon Web Services terminology. With an EC2 instance, AWS subscribers can request and provision a computer server within the AWS cloud.”
Pre-requisite before installing anything:
- Basic Understanding how to set up an instance using Amazon Linux 2023
- Understand what the use of some Linux command such as ‘sudo , cp , ls, cd. vi ‘
To prepare the LAMP server
- Connect to your instance. For more information, see Connecting to instances.
- To ensure that all of your software packages are up to date, perform a quick software update on your instance. This process might take a few minutes, but it is important to make sure that you have the latest security updates and bug fixes.The
-y
option installs the updates without asking for confirmation. If you would like to examine the updates before installing, you can omit this option. Now let’s installa) Apache ” http”
b) Php * all the dependancies
c) MariaDB -
[ec2-user ~]$
sudo dnf update -y
-
[ec2-user ~]$
sudo dnf install -y httpd wget php-fpm php-mysqli php-json php php-devel
-
[ec2-user ~]$
sudo dnf install mariadb105-server - Start the Apache web server.
[ec2-user ~]$
sudo systemctl start httpd
- Use the systemctl command to configure the Apache web server to start at each system boot.
[ec2-user ~]$
sudo systemctl enable httpd
You can verify that httpd is on by running the following command:
[ec2-user ~]$
sudo systemctl is-enabled httpd
- Add a security rule to allow inbound HTTP (port 80) connections to your instance if you have not already done so. By default, a launch-wizard-
N
security group was created for your instance during launch. If you did not add additional security group rules, this group contains only a single rule to allow SSH connections.- Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
- In the left navigator, choose Instances, and select your instance.
- On the Security tab, view the inbound rules. You should see the following rule:
FILE PERMISSION SETUP
- Add your user (in this case,
ec2-user
) to theapache
group.[ec2-user ~]$
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.
- Log out (use the exit command or close the terminal window):
[ec2-user ~]$
exit
- To verify your membership in the
apache
group, reconnect to your instance, and then run the following command:[ec2-user ~]$
groups
- Log out (use the exit command or close the terminal window):
- Change the group ownership of
/var/www
and its contents to theapache
group.[ec2-user ~]$
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.[ec2-user ~]$
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:[ec2-user ~]$
find /var/www -type f -exec sudo chmod 0664 {} \;
Now, ec2-user
(and any future members of the apache
group) can add, delete, and edit files in the Apache document root, enabling you to add content, such as a static website or a PHP application.
INSTALLING DATABASE (MARIADB)
- Start the MariaDB server.
[ec2-user ~]$
sudo systemctl start mariadb
- Run mysql_secure_installation.
[ec2-user ~]$
sudo mysql_secure_installation
- When prompted, type a password for the root account.
- Type the current root password. PLEASE ENABLE ANS SELECT PASSWORD
- Type
Y
to set a password, and type a secure password twice. For more information about creating a secure password, see https://identitysafe.norton.com/password-generator/. Make sure to store this password in a safe place.Setting a root password for MariaDB is only the most basic measure for securing your database. When you build or install a database-driven application, you typically create a database service user for that application and avoid using the root account for anything but database administration.
- Type
Y
to remove the anonymous user accounts. - Type
Y
to disable the remote root login. - Type
Y
to remove the test database. - Type
Y
to reload the privilege tables and save your changes.
- When prompted, type a password for the root account.
- (Optional) If you do not plan to use the MariaDB server right away, stop it. You can restart it when you need it again.
[ec2-user ~]$
sudo systemctl stop mariadb
- (Optional) If you want the MariaDB server to start at every boot, type the following command.
[ec2-user ~]$
sudo systemctl enable mariadb
PHPMyAdmin INSTALLATION
- Install the required dependencies.
[ec2-user ~]$
sudo dnf install php-mbstring php-xml -y
- Restart Apache.
[ec2-user ~]$
sudo systemctl restart httpd
- Restart
php-fpm
.[ec2-user ~]$
sudo systemctl restart php-fpm
- Navigate to the Apache document root at
/var/www/html
.[ec2-user ~]$
cd /var/www/html
- Select a source package for the latest phpMyAdmin release from https://www.phpmyadmin.net/downloads. To download the file directly to your instance, copy the link and paste it into a wget command, as in this example:
[ec2-user html]$
wget
https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.tar.gz
- Create a
phpMyAdmin
folder and extract the package into it with the following command.[ec2-user html]$
mkdir phpMyAdmin && tar -xvzf
phpMyAdmin-latest-all-languages.tar.gz
-C phpMyAdmin --strip-components 1 - Delete the
phpMyAdmin-latest-all-languages.tar.gz
tarball.[ec2-user html]$
rm
phpMyAdmin-latest-all-languages.tar.gz
- (Optional) If the MySQL server is not running, start it now.
[ec2-user ~]$
sudo systemctl start mariadb
Further configuration for PhpMyAdmin
- Access the PhpMyAdmin Folder
[ec2-user phpMyAdmin]$ sudo cp config.sample.inc.php config.inc.php
- Edit the file by using the vi editor for the config.inc.php
- $cfg[‘blowfish_secret’] = ’32 byte string’ then save
Install Git
Simple installation of Git. You need to install git if you are planning to clone your code from git hub repository
[ec2-user ~]$
sudo dnf install git