Installation of LAMP on Ubuntu 24.04

LAMP stands for Linux, Apache, MySQL (or MariaDB), and PHP, a widely used stack for hosting dynamic websites and web applications. On Ubuntu 24.04, setting up a LAMP stack involves installing these components to enable web hosting capabilities:

  1. Linux: The foundation of the stack, providing the operating system.
  2. Apache: A robust and scalable web server to handle HTTP requests.
  3. MySQL: A database management system for storing and managing data.
  4. PHP: A server-side scripting language to process dynamic content.

This guide explains how to install and configure each component of the LAMP stack on Ubuntu 24.04. Once complete, your system will be capable of serving web applications, handling databases, and delivering dynamic web pages.

Apache Installation

sudo apt install apache2

Apache Configuration (Optional)

By default, Ubuntu does not allow access through the web browser to any file outside of those located in /var/www, public_html directories (when enabled) and /usr/share (for web applications). If your site is using a web document root located elsewhere, you may need to whitelist your document root directory.

Use a Different Folder for Apache

Update the 000-default.conf file to change directory

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /home/anurag/in2eco
    ServerName localhost

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <Directory /home/anurag/in2eco>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Update apache2.conf for granting permission for updated directory

<Directory /home/*>
    AllowOverride None
    Require all granted
</Directory>

Assign permissions for access

sudo chown -R www-data:www-data /home/user/project
sudo chmod -R 755 /home/user/project

Grant execute permissions for www-data user on all parent directories

sudo chmod +x /home
sudo chmod +x /home/user
sudo chmod +x /home/user/project
#Allow Rewrite Engine
sudo a2enmod rewrite
sudo systemctl restart apache2

Check Apache Logs

sudo tail -f /var/log/apache2/error.log

Install PHP-XML

sudo apt update
sudo apt install php-xml

MySQL Installation

sudo apt install mysql-server

MySQL Configuration

Create a Database

CREATE DATABASE mynewdatabase;

Add New User

CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'userpassword';

Grant Privileges to a User for a Database

GRANT ALL PRIVILEGES ON mynewdatabase.* TO 'newuser'@'localhost';
FLUSH PRIVILEGES;

PHP Installation

sudo apt install php libapache2-mod-php php-mysql

PHP Configuration

Switch Between Different PHP Versions
sudo a2dismod php8.3
sudo a2enmod php7.4
sudo service apache2 restart

PostgreSQL Instatallation

sudo apt install postgresql

PhpPGAdmin Installation

Reference

https://www.digitalocean.com/community/tutorials/how-to-install-lamp-stack-on-ubuntu

Author

Anurag Gupta is an M.S. graduate in Electrical and Computer Engineering from Cornell University. He also holds an M.Tech degree in Systems and Control Engineering and a B.Tech degree in Electrical Engineering from the Indian Institute of Technology, Bombay.


Comment

* Required information
1000
Drag & drop images (max 3)
Captcha Image
Powered by Commentics

Past Comments

No comments yet. Be the first!

Similar content