Deployment guide

LAMP stack

Overview

The LAMP Stack AMI by SecureAnyCloud is a fully preconfigured Linux, Apache, MySQL and PHP environment, ready to run on Amazon EC2. It is built on AlmaLinux and includes all four core components of the classic LAMP web application stack, so you can deploy dynamic websites and web applications within minutes of launch.

Whether you are hosting a WordPress site, a custom PHP application or a database-driven web service, this AMI gives you a production-ready starting point.

What you get:

  • Linux (AlmaLinux), Apache, MySQL and PHP preinstalled and configured
  • A walkthrough from launching the instance to verifying each component, managing services, working with the filesystem layout and applying security best practices
  • 24/7 SecureAnyCloud support

Visit secureanycloud.com to explore the full catalogue of preconfigured AMIs available on the AWS Marketplace.

Prerequisites

Before you launch the LAMP Stack AMI, make sure you have the following in place.

AWS account: You need an active AWS account with permissions to launch EC2 instances and manage security groups.

EC2 key pair: Create or select an existing EC2 key pair in the region where you plan to launch the instance. SSH authentication requires this key pair.

Security group configuration: Your security group must allow inbound traffic on the following ports:

Protocol Type Port Description

SSH TCP 22 SSH connectivity for remote administration

Custom TCP TCP 80 Apache HTTP web server

Custom TCP TCP 3306 MySQL database listener for remote access

Restrict SSH access to your own IP address or a trusted CIDR range. Open port 3306 only if you need remote database connections. For most deployments, local access from the server itself is sufficient.

Minimum system requirements:

Minimum CPU Minimum RAM Required Disk Space

1 vCPU 1 GB 20 GB

Any EC2 instance type that meets these minimums will work. For production workloads, consider a t3.medium or larger for consistent performance under load.

Step by Step Setup

Step 1: Launch the Instance

  • Open the AWS Marketplace listing for LAMP Stack by SecureAnyCloud.
  • Click Continue to Subscribe, then Continue to Configuration.
  • Select your preferred AWS Region and instance type.
  • On the launch page, choose your VPC and subnet, and assign the security group you prepared above.
  • Select your EC2 key pair and launch the instance.

Step 2: Wait for Status Checks

Wait until the EC2 instance shows 2/2 status checks passed before you connect. The instance runs an initial boot update script that applies the latest operating system patches, so the first boot may take a few minutes longer than usual.

If you connect before both status checks have passed, you may see errors such as:

Permission denied (publickey,gssapi-keyex,gssapi-with-mic). ec2-user@your-instance-ip's password:

This is expected behaviour during early boot. Wait for the status checks to complete, then try again.

Step 3: Connect via SSH

Connect to the instance with your private key:

ssh -i /path/to/your-key.pem ec2-user@<PUBLIC_IP>

Replace <PUBLIC_IP> with the public IP address or public DNS name shown in the EC2 console.

Step 4: Switch to the Root User

Once connected as ec2-user, switch to the root user:

sudo su -

All administrative tasks described in this guide should be performed as root.

Step 5: Retrieve the MySQL Root Password

The MySQL root password is randomly generated at build time and stored in a log file on the server. Read it with:

cat /stage/scripts/mysql_root_password.log

Note this password. You need it to log in to the MySQL command-line client.

Step 6: Verify Apache Is Running

Open a web browser and navigate to:

http://<PUBLIC_IP>:80

The AlmaLinux Test Page confirms that the Apache HTTP Server is operational.

Step 7: Verify PHP Is Running

Navigate to the PHP info page:

http://<PUBLIC_IP>/info.php

The PHP information page shows the installed version and loaded modules. For security, remove this file or restrict access to it before you go into production.

Step 8: Connect to MySQL

From the root shell on the instance, connect to MySQL:

mysql -u root -p

When prompted, enter the password that you retrieved from /stage/scripts/mysql_root_password.log. The root database user is configured for local login only, which is best practice for production environments.

Server Components

The LAMP Stack AMI includes the following preconfigured components. Versions may be updated on first boot when the initial update script runs.

Component Configuration File Description

MySQL /etc/my.cnf Relational database server for dynamic data storage

Apache HTTP /etc/httpd or /etc/apache2 Web server handling HTTP requests on port 80

PHP /etc/php.ini Server side scripting language for dynamic content

MySQL is the database backend. It starts automatically on boot and listens on port 3306. For security, the root user is restricted to local connections only.

Apache HTTP Server handles all incoming web requests. The document root is /var/www/html, where you place your website files, virtual host configurations and static assets.

PHP is integrated with Apache through the PHP module. Its configuration is in /etc/php.ini, and additional module configuration files are in /etc/php.d/.

Filesystem Layout

The AMI uses dedicated mount points to separate system files, database data and web content, for better performance and manageability.

Mount Point Description

/ Root filesystem containing the operating system

/boot Operating system kernel files

/var/lib/mysql MySQL data directory on a dedicated volume

/var/www/html Apache document root on a dedicated volume

Key directories and their purposes:

Path Purpose

/var/www/html Place your website files, PHP scripts, and static assets here

/var/lib/mysql All MySQL databases and table data are stored here

/etc/httpd Apache configuration files including virtual hosts

/etc/php.ini Main PHP configuration file

/etc/php.d/ Additional PHP module configuration files

/stage/scripts SecureAnyCloud provisioning scripts and log files

Because /var/lib/mysql and /var/www/html are on their own volumes, you can resize storage for the database or the web content independently, without affecting the root filesystem.

Managing Services

You manage all services on the LAMP Stack AMI with standard Linux service commands. Each service starts automatically on boot.

MySQL Service

# Check the MySQL service status service mysqld status
# Stop the MySQL service service mysqld stop
# Start the MySQL service service mysqld start
# Restart the MySQL service service mysqld restart

Apache HTTP Service

On Red Hat-based systems, including this AlmaLinux AMI, the service is named httpd:

# Check the Apache service status systemctl status httpd
# Stop the Apache service systemctl stop httpd
# Start the Apache service systemctl start httpd
# Restart the Apache service systemctl restart httpd

PHP

PHP runs as a module within Apache, so there is no separate PHP service to manage. Restarting Apache reloads any changes to the PHP configuration.

# Check the installed PHP version php -v
# Test PHP configuration for syntax errors php -i

After making changes to /etc/php.ini, restart Apache to apply them:

systemctl restart httpd

Scripts and Log Files

The AMI includes several scripts and log files that SecureAnyCloud created to streamline first-boot provisioning and administration.

Script or Log Path Description

initial_boot_update.sh /stage/scripts Updates the operating system with the latest available patches on first boot

initial_boot_update.log /stage/scripts Output log from the initial boot update script

mysql_root_password.log /stage/scripts Contains the randomly generated MySQL root password

Disabling the Initial Boot Update Script

The OS update script runs automatically on every reboot through crontab. If you prefer to manage updates manually, disable it:

rm -f /stage/scripts/initial_boot_update.sh crontab -e
# DELETE THE BELOW LINE, SAVE AND EXIT THE FILE: @reboot /stage/scripts/initial_boot_update.sh

This stops the automatic update from running on later reboots and keeps the log files for reference.

Deploying Your Application

Uploading Website Files

Place your PHP application files in the Apache document root:

# Copy files from your local machine scp -i /path/to/your-key.pem -r ./my-app/* ec2-user@<PUBLIC_IP>:/tmp/
# Then on the server, move them into place
sudo cp -r /tmp/my-app/* /var/www/html/
sudo chown -R apache:apache /var/www/html/

Creating a MySQL Database

Connect to MySQL as root and create a database for your application:

mysql -u root -p CREATE DATABASE myapp; CREATE USER 'myappuser'@'localhost' IDENTIFIED BY 'your_secure_password'; GRANT ALL PRIVILEGES ON myapp.* TO 'myappuser'@'localhost'; FLUSH PRIVILEGES; EXIT;

Configuring Virtual Hosts

To host multiple websites, create virtual host configuration files:

vi /etc/httpd/conf.d/mysite.conf

Add a configuration block like the following:

<VirtualHost *:80> ServerName www.example.com DocumentRoot /var/www/html/mysite <Directory /var/www/html/mysite> AllowOverride All Require all granted </Directory> ErrorLog /var/log/httpd/mysite-error.log CustomLog /var/log/httpd/mysite-access.log combined </VirtualHost>

Restart Apache to apply the new virtual host:

systemctl restart httpd

Troubleshooting

Cannot connect via SSH

  • Confirm that the instance has reached 2/2 status checks in the EC2 console.
  • Verify that your security group allows inbound TCP traffic on port 22 from your IP address.
  • Make sure you are using the correct key pair and connecting as ec2-user.
  • Check that the key file permissions are set correctly: chmod 400 /path/to/your-key.pem.

Apache is not serving pages

  • Check the Apache service status: systemctl status httpd.
  • Review the error log: cat /var/log/httpd/error_log.
  • Confirm that your security group allows inbound traffic on port 80.
  • Verify that files exist in /var/www/html and have the correct ownership (apache:apache).

Cannot connect to MySQL

  • Check the MySQL service status: service mysqld status.
  • Verify that you are using the correct password from /stage/scripts/mysql_root_password.log.
  • If you connect remotely, make sure port 3306 is open in your security group and MySQL accepts remote connections in /etc/my.cnf.

PHP pages display as plain text

  • Make sure the PHP module is loaded in Apache: httpd -M | grep php.
  • Verify that the file has a .php extension.
  • Restart Apache after any configuration change: systemctl restart httpd.

Initial boot update is taking a long time

  • The first boot runs a full OS update. It can take several minutes, depending on the instance type and available bandwidth.
  • Monitor progress by tailing the update log: tail -f /stage/scripts/initial_boot_update.log.

Security Recommendations

Remove the PHP Info Page

The info.php file exposes detailed server configuration. Remove it once you have verified that PHP works:

rm -f /var/www/html/info.php

Restrict MySQL Remote Access

By default, the MySQL root user is configured for local access only. Keep it that way in production. If your application runs on the same server, use localhost as the database host.

Enable HTTPS with TLS

For production deployments, configure Apache with a TLS certificate. You can use Let's Encrypt with Certbot:

yum install -y certbot python3-certbot-apache certbot --apache -d yourdomain.com

Apply Security Updates Regularly

Keep the operating system and all packages up to date:

yum update -y

Restrict Security Group Rules

  • Limit SSH (port 22) to specific trusted IP addresses.
  • Open port 3306 only if you need remote database access.
  • Consider a bastion host or AWS Systems Manager Session Manager for SSH access, instead of exposing port 22 to the internet.

Configure a Firewall

In addition to AWS security groups, consider enabling the local firewall:

firewall-cmd --permanent --add-service=http firewall-cmd --permanent --add-service=ssh firewall-cmd --reload

Back Up Your Data

Back up the MySQL data directory and the web content regularly. Use AWS EBS snapshots for volume-level backups, or mysqldump for logical database backups:

mysqldump -u root -p --all-databases > /tmp/all-databases-backup.sql

Support

If you run into an issue that this guide does not cover, or need further help, the SecureAnyCloud support team is available 24/7.

Email: sales@secureanycloud.com Phone: (+44) 02045382725 Website: secureanycloud.com Address: 3rd Floor, 86 90 Paul Street, London, EC2A 4NE

When you contact support, include your EC2 instance ID, the AWS region, a description of the issue and any relevant log output.

Deploy on AWS

Launch LAMP Stack with 24/7 support from SecureAnyCloud.

View on Marketplace

Need Help?

Our support team is available 24/7.

sales@secureanycloud.com

Deploy on AWS

Launch LAMP Stack with 24/7 support from SecureAnyCloud.

View on Marketplace

Need Help?

Our support team is available 24/7.

sales@secureanycloud.com