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:
- Linux: The foundation of the stack, providing the operating system.
- Apache: A robust and scalable web server to handle HTTP requests.
- MySQL: A database management system for storing and managing data.
- 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 Versionssudo a2dismod php8.3
sudo a2enmod php7.4
sudo service apache2 restart
PostgreSQL Instatallation
sudo apt install postgresql
PhpPGAdmin Installation
- Download package from github https://github.com/phppgadmin/phppgadmin/
- Edit configuration in conf/config.inc.php-dist and renam the file to conf/config.inc.php-dist
- Install missing libraries such as php-pgsql and php-mbstring
Reference
https://www.digitalocean.com/community/tutorials/how-to-install-lamp-stack-on-ubuntuAuthor
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
This policy contains information about your privacy. By posting, you are declaring that you understand this policy:
- Your name, rating, website address, town, country, state and comment will be publicly displayed if entered.
- Aside from the data entered into these form fields, other stored data about your comment will include:
- Your IP address (not displayed)
- The time/date of your submission (displayed)
- Your email address will not be shared. It is collected for only two reasons:
- Administrative purposes, should a need to contact you arise.
- To inform you of new comments, should you subscribe to receive notifications.
- A cookie may be set on your computer. This is used to remember your inputs. It will expire by itself.
This policy is subject to change at any time and without notice.
These terms and conditions contain rules about posting comments. By submitting a comment, you are declaring that you agree with these rules:
- Although the administrator will attempt to moderate comments, it is impossible for every comment to have been moderated at any given time.
- You acknowledge that all comments express the views and opinions of the original author and not those of the administrator.
- You agree not to post any material which is knowingly false, obscene, hateful, threatening, harassing or invasive of a person's privacy.
- The administrator has the right to edit, move or remove any comment for any reason and without notice.
Failure to comply with these rules may result in being banned from submitting further comments.
These terms and conditions are subject to change at any time and without notice.
Similar content
Past Comments