Skip to main content

LAMP (Latest Version) – Ubuntu 22.04

Overview​

Category: Frameworks
Supported OS: Ubuntu 22.04

Quickly deploy a cloud server with Apache, MySQL, and PHP pre-installed—the foundation for hosting robust web applications. The LAMP stack is widely used for hosting websites and web apps, offering a flexible, scalable, and open-source environment.


Software Included​

  • Apache: 2.4.41
  • MySQL: 8.0.30
  • PHP: 8.1
  • Fail2ban: 0.11.1
  • Postfix: 3.4.13
  • Certbot: 0.40.0

Getting Started After Deployment​

1. Firewall Configuration​

Allow only SSH (port 22, rate limited), HTTP (port 80), and HTTPS (port 443) for security and web access.


2. Deployment Message​

During deployment, you will be logged out and see the following message:

Please wait until the installation is completed....
Connection to $IPADDRESS closed.

Do not log in for at least 2 minutes after the instance is created to allow the setup to complete.


3. First Login Steps​

  • View your LAMP instance by visiting its IP address in your browser.

  • Log in as the ubuntu user (using the password or SSH key you set during creation).

  • Switch to the root user without a password:

    sudo su -
  • The MySQL root password is stored under:

    /root/.mysql_root_password
  • Log in to MySQL with:

    mysql -u root -p <password from the above file>
  • The web root directory is:

    /var/www/html

4. Securing Your Instance​

To secure your connection, configure a registered domain for your instance.

Apache Virtual Hosts (for Multi-site Hosting)​

  • Create a directory in /var/www for each domain.
  • Create a virtual host config in /etc/apache2/sites-available for each domain.
  • Enable your new virtual host with:
    a2ensite <your-domain-config>
    systemctl reload apache2

SSL Setup with Certbot​

  • Ensure DNS A records are set for your domain and www subdomain.

  • The ServerName directive in your virtual host should match the domain.

  • Generate an SSL certificate:

    certbot --apache -d example.com -d www.example.com
  • After setting up HTTPS, optionally deny HTTP traffic on port 80 for better security.


5. Setting up Postfix​

  • Set a valid hostname:

    hostnamectl set-hostname $HOSTNAME

    Replace $HOSTNAME with your desired hostname and ensure it has a proper A record. The instance IP must have a valid PTR record.

  • Configure the hostname in /etc/postfix/main.cf:

    myhostname = $hostname
  • Restart Postfix:

    systemctl restart postfix
  • Test outgoing email:

    echo "Postfix test" | mail -s "Subject" test@gmail.com

Note: Initial emails may be delivered to the spam folder. As your server’s reputation builds, emails will be delivered to inboxes.