LAMP Stack
The LAMP stack (Linux, Apache, MariaDB, and PHP) is the classic combination for hosting web applications and dynamic websites. This image ships all four components pre-installed and configured to work together, ready for you to deploy your application.
Software included
Section titled “Software included”| Component | Version |
|---|---|
| Apache | 2.4.x |
| MariaDB | Latest stable |
| PHP | 8.3 |
| PHP extensions | cli, mysql, curl, gd, mbstring, xml, zip, bcmath, intl |
| Ubuntu | 24.04 LTS |
Getting started
Section titled “Getting started”1. Connect to your VM
Section titled “1. Connect to your VM”ssh ubuntu@<your-vm-ip>2. Verify services are running
Section titled “2. Verify services are running”There is no first-boot configuration. All services start immediately.
systemctl status apache2systemctl status mariadbphp --version3. Access the default web page
Section titled “3. Access the default web page”Open a browser and navigate to:
http://<your-vm-ip>4. Deploy your application
Section titled “4. Deploy your application”Place your application files in the web root:
sudo cp -r my-app/* /var/www/html/sudo chown -R www-data:www-data /var/www/html/5. Set up a database
Section titled “5. Set up a database”On a fresh install, no password is required. Authentication uses the system socket. Connect as root:
sudo mariadbCreate a database and user for your application:
CREATE DATABASE myapp CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;CREATE USER 'myapp'@'localhost' IDENTIFIED BY '<strong-password>';GRANT ALL PRIVILEGES ON myapp.* TO 'myapp'@'localhost';FLUSH PRIVILEGES;EXIT;Managing the LAMP stack
Section titled “Managing the LAMP stack”# Restart Apachesudo systemctl restart apache2
# Restart MariaDBsudo systemctl restart mariadb
# View Apache logssudo tail -f /var/log/apache2/error.log
# View MariaDB logssudo journalctl -u mariadb -fKey directories and files:
| Path | Purpose |
|---|---|
/var/www/html/ | Default web root |
/etc/apache2/sites-available/ | Apache virtual hosts |
/etc/php/8.3/apache2/php.ini | PHP configuration for Apache |
/etc/mysql/mariadb.conf.d/ | MariaDB configuration |
To create a virtual host for a domain, add a configuration file to
/etc/apache2/sites-available/ and enable it:
sudo a2ensite myapp.confsudo systemctl reload apache2Security
Section titled “Security”Port 80 is open by default. UFW is enabled.
After setting up HTTPS, restrict HTTP traffic:
sudo ufw allow 443/tcpsudo ufw delete allow 80/tcp