Introduction
In this guide, we’ll go through installing the LAPP stack—Apache, PostgreSQL, and PHP—on a fresh Ubuntu Studio 24.04.4 installation. This setup is perfect for hosting dynamic websites and web apps, leveraging PostgreSQL as a powerful relational database management system.
1. Update the System
Begin by updating your system to ensure all packages are up-to-date.
sudo apt update && sudo apt upgrade -y
2. Install Apache
Apache is a popular and reliable web server that will serve your PHP files.
- Install Apache:
sudo apt install apache2 -y - Start and Enable Apache:
sudo systemctl start apache2 sudo systemctl enable apache2 - Test Apache Installation:
Open a browser and go tohttp://localhostor your server’s IP. If Apache is running, you’ll see its default welcome page.
3. Install PostgreSQL
Instead of MySQL, we’ll use PostgreSQL for this setup, which offers strong data integrity and robustness.
- Install PostgreSQL:
sudo apt install postgresql postgresql-contrib -y - Start and Enable PostgreSQL:
sudo systemctl start postgresql sudo systemctl enable postgresql - Secure PostgreSQL:
By default, PostgreSQL has a secure configuration, but we’ll change the password for the defaultpostgresuser.sudo -i -u postgres psqlAt the PostgreSQL prompt, enter:\password postgresEnter a secure password when prompted, then type\qto quit PostgreSQL andexitto return to your regular user.
4. Install PHP and Required Modules
PHP will enable dynamic scripting capabilities on your server.
- Install PHP and Modules:
We’ll install PHP along with necessary extensions for PostgreSQL.sudo apt install php libapache2-mod-php php-pgsql php-xml php-mbstring php-curl php-gd php-zip -y - Check PHP Version:
Verify PHP is installed correctly by checking its version:bash php -v
5. Configure Apache to Prioritize PHP
To configure Apache to serve PHP files as the default file type:
- Open Apache’s Configuration:
sudo nano /etc/apache2/mods-enabled/dir.conf - Update Directory Index:
Placeindex.phpat the start of the list:<IfModule mod_dir.c> DirectoryIndex index.php index.html </IfModule> - Restart Apache:
bash sudo systemctl restart apache2
6. Set Up a Sample PHP Page
To confirm PHP is working correctly, create a sample PHP file in your web directory.
- Create a PHP Test File:
sudo nano /var/www/html/test.php - Add Custom ASCII Art Text:
Copy the code below into yourtest.phpfile to display ASCII text on the page.<?php header('Content-Type: text/plain; charset=UTF-8'); echo " ██████╗ ██╗ ██╗ ██╗ █████╗ ███╗ ██╗ ██╔══██╗██║ ██║ ██║██╔══██╗████╗ ██║ ██║ ██║██║ ██║ █╗ ██║███████║██╔██╗ ██║ ██║ ██║██║ ██║███╗██║██╔══██║██║╚██╗██║ ██████╔╝███████╗ ╚███╔███╔╝██║ ██║██║ ╚████║ ╚═════╝ ╚══════╝ ╚══╝╚══╝ ╚═╝ ╚═╝╚═╝ ╚═══╝ CW-AI Thats You! "; ?> - Access the Test File:
Open your browser and go tohttp://localhost/test.php. You should see the ASCII art displaying “CW-AI Thats You!”
Final Steps: Firewall Configuration (Optional)
To ensure security, configure the firewall to allow HTTP and HTTPS traffic.
- Allow Apache through UFW:
bash sudo ufw allow in "Apache Full" sudo ufw enable
Conclusion
You now have a fully functional LAPP stack on Ubuntu Studio 24.04.4 with PostgreSQL. This setup provides a robust foundation for dynamic websites and applications, especially with PostgreSQL’s performance and reliability.