Close Menu
  • Home
  • Life style
    • Celebrities
    • Exercise & Training
    • Healthline
  • Exploration
    • Beauty tips
    • Business
    • Travel guides
    • Fashion
    • Technology
  • Web tutorials
    • Hosting & Servers
    • Blogger guides
    • WordPress guides
  • English
    • Tiếng Việt
    • Hmoob
    • English
Facebook YouTube X (Twitter) Instagram
Trending
  • Late-Summer Travel in Vietnam 2026: Plan a Less Crowded, Less Rainy Itinerary
  • Protecting WordPress Against AI Bots and Unknown Crawlers
  • Install Let’s Encrypt SSL on Ubuntu with OpenLiteSpeed and Automatic Renewal
  • AI-Powered Operational Optimization for Small Businesses: A 30-Day Testing Framework
  • Optimizing a Blog for Google AI Overviews and AI Mode
  • Diagnosis and Treatment of Severe Pneumonia: CAP, HAP, VAP, and Aspiration Pneumonia
  • How to Build a Newsletter for Your Blog: WordPress, Substack, or an Email Platform?
  • Repurposing Blog Content: Turn One Article into 5 Formats
Facebook YouTube X (Twitter) Instagram
SaibABCSaibABC
Chú thích cho quảng cáo
  • Home
  • Life style
    1. Celebrities
    2. Exercise & Training
    3. Healthline
    4. View All

    Comparing Lionel Messi and Cristiano Ronaldo: Their Complete Careers

    30/08/2026

    Celebrities Move to Video Podcasts: The New Era of Talk Shows

    30/08/2026

    Taylor Swift Protects Her Voice Against AI: The Fight Against Deepfakes

    30/08/2026

    15 Most Popular Celebrities in the World of All Time

    30/08/2026

    Five-Minute Office Exercises: A Snack-Sized Movement Schedule

    30/08/2026

    Best Exercises to Strengthen Your Core: From Beginner to Advanced

    30/08/2026

    Diagnosis and Treatment of Severe Pneumonia: CAP, HAP, VAP, and Aspiration Pneumonia

    30/08/2026

    Preventing Dengue at Home: A Mosquito Control and Severe Symptom Checklist

    30/08/2026

    Self-Directed Health with Wearables: Use Data Correctly, Do Not Self-Diagnose

    30/08/2026

    Empowering Health: Prioritize Early Cancer Screenings for Better Well-being

    30/08/2026

    Diagnosis and Treatment of Severe Pneumonia: CAP, HAP, VAP, and Aspiration Pneumonia

    30/08/2026

    Preventing Dengue at Home: A Mosquito Control and Severe Symptom Checklist

    30/08/2026

    Preparing for the Business Peak Season: Capacity, Staffing, and Cash Flow Spreadsheet

    30/08/2026

    Comparing Lionel Messi and Cristiano Ronaldo: Their Complete Careers

    30/08/2026
  • Exploration
    1. Beauty tips
    2. Business
    3. Travel guides
    4. Fashion
    5. Technology
    Featured

    Late-Summer Travel in Vietnam 2026: Plan a Less Crowded, Less Rainy Itinerary

    By Nuj Coom30/08/2026
    Recent

    Late-Summer Travel in Vietnam 2026: Plan a Less Crowded, Less Rainy Itinerary

    30/08/2026

    AI-Powered Operational Optimization for Small Businesses: A 30-Day Testing Framework

    30/08/2026

    How to Block OTA Updates on iPhone and iPad Using Block OTA

    30/08/2026
  • Web tutorials
    1. Hosting & Servers
    2. Blogger guides
    3. WordPress guides
    4. View All

    Install Let’s Encrypt SSL on Ubuntu with OpenLiteSpeed and Automatic Renewal

    30/08/2026

    How to Install the LAMP Stack: Linux, Apache, MySQL, and PHP on Ubuntu

    30/08/2026

    How to secure Apache with Let’s Encrypt on Ubuntu

    30/08/2026

    What Is LAMP Stack? Discover the Power of LAMP Stack

    30/08/2026

    Optimizing a Blog for Google AI Overviews and AI Mode

    30/08/2026

    Repurposing Blog Content: Turn One Article into 5 Formats

    30/08/2026

    12 Best AI Content Writing Tools for Bloggers in 2026

    30/08/2026

    How to Get Your Blog Into Google Discover After the Google Discover Core Update 2026

    30/08/2026

    Protecting WordPress Against AI Bots and Unknown Crawlers

    30/08/2026

    How to Install the LAMP Stack: Linux, Apache, MySQL, and PHP on Ubuntu

    30/08/2026

    12 Best AI Content Writing Tools for Bloggers in 2026

    30/08/2026

    Check WordPress Plugins Before Updating: A 24-Hour Process

    30/08/2026

    Protecting WordPress Against AI Bots and Unknown Crawlers

    30/08/2026

    Install Let’s Encrypt SSL on Ubuntu with OpenLiteSpeed and Automatic Renewal

    30/08/2026

    Optimizing a Blog for Google AI Overviews and AI Mode

    30/08/2026

    How to Build a Newsletter for Your Blog: WordPress, Substack, or an Email Platform?

    30/08/2026
  • English
    • Tiếng Việt
    • Hmoob
    • English
SaibABCSaibABC
Home»Web tutorials»Hosting & Servers»How to Install the LAMP Stack: Linux, Apache, MySQL, and PHP on Ubuntu
Hosting & Servers 7 Mins ReadNo Comments

How to Install the LAMP Stack: Linux, Apache, MySQL, and PHP on Ubuntu

Nuj CoomBy Nuj Coom
Facebook Twitter Pinterest LinkedIn Tumblr Email
Chú thích cho quảng cáo

Contents

  1. Introduction to the LAMP Stack
  2. Prerequisites
  3. Step 1 — Install Apache and Update the Firewall
    1. Meaning of the UFW Profiles
    2. How to Find the Server's Public IP Address
  4. Step 2 — Install MySQL
    1. Create a separate MySQL database and account
  5. Step 3 — Install PHP
  6. Step 4 — Create a Virtual Host for the Website
  7. Step 5 — Test PHP with Apache
  8. Step 6 — Next Steps
  9. References

Introduction to the LAMP Stack

LAMP Stack is a group of open-source software commonly installed together so that a server can host websites and dynamic web applications written in PHP. The name is an acronym for Linux, the web server Apache, the database MySQL, and the server-side processing language PHP.

If you are new and want to deploy a server quickly, you can use a one-click installation service from a provider VPS. However, installing it yourself will help you understand the system configuration and give you more control during operation.

In this guide, you will set up the LAMP Stack on an Ubuntu 22.04 server. The Apache, MySQL, and PHP installation commands still use Ubuntu's official software repositories; the specific versions may vary depending on the Ubuntu release and when the commands are run (according to the Ubuntu Apache documentation and Ubuntu MySQL documentation).

Prerequisites

To complete this guide, you need an Ubuntu 22.04 server with a non- root root user account sudowith sudo privileges, along with a basic firewall. You can refer to the initial Ubuntu Server setup guide.

Log in via SSH using an account with sudo privileges sudo and update the package lists before you begin:

Chú thích cho quảng cáo
sudo apt update
sudo apt upgrade

Step 1 — Install Apache and Update the Firewall

Apache is one of the most popular web servers on Linux, with extensive documentation and broad support. Ubuntu provides the apache2 package in the official software repository (according to ubuntu.com).

Install Apache with APT:

sudo apt install apache2

When prompted for confirmation, enter Y Y ENTERand press Enter. Then, check the service status:

sudo systemctl status apache2

If you are using UFW, list the available application profiles:

sudo ufw app list
Output
Available applications:
  Apache
  Apache Full
  Apache Secure
  OpenSSH

Meaning of the UFW Profiles

  • Apache: opens only port 80 for HTTP.
  • Apache Full: opens ports 80 and 443 for HTTP and HTTPS.
  • Apache Secure: opens only port 443 for HTTPS.

If you have not configured a TLS certificate yet, you can allow only HTTP for initial testing:

sudo ufw allow in "Apache"
sudo ufw status

Once the website has a TLS certificate and needs to serve HTTPS, use the Apache Full configuration or open the HTTPS port according to your network design. Do not enable additional services unless necessary.

Open the server's public IP address in a browser:

http://your_server_ip

If you see the default Apache page, the web server has been installed and is accessible through the firewall.

Apache default page on Ubuntu

How to Find the Server's Public IP Address

Typically, this is the address used to connect via SSH. You can check the local network addresses with:

ip addr

To see the public address identified by an external service, you can use:

curl https://icanhazip.com

If the server is behind NAT or uses a cloud network, also check the Public IP address in the provider's control panel. Not every address shown in ip addr can be accessed directly from the Internet.

Step 2 — Install MySQL

MySQL handles data storage and management for the website. Install the MySQL server with:

sudo apt install mysql-server

The service usually starts automatically after installation. Check its status with:

sudo systemctl status mysql

If the service is not running, restart it with:

sudo systemctl restart mysql

On Ubuntu, the default local MySQL account root usually authenticates through the system socket. Therefore, you can access MySQL with:

sudo mysql

Ubuntu currently recommends creating a separate account with appropriate privileges instead of using the root account for applications (according to the Ubuntu MySQL configuration documentation). Exit the MySQL interface:

exit;

On some Ubuntu versions or MySQL packages, you can also run the interactive security checker:

sudo mysql_secure_installation

The questions and options may vary by version. Read each prompt carefully; you should generally remove anonymous accounts, restrict root remote logins, and remove the test database if the system offers these options. Do not mechanically apply answers from older versions.

Create a separate MySQL database and account

The example below creates a separate database and user for the application. Replace the sample values with your own names and a strong password:

sudo mysql
CREATE DATABASE app_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'app_user'@'localhost' IDENTIFIED BY 'ThayBangMatKhauManh';
GRANT ALL PRIVILEGES ON app_db.* TO 'app_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Ubuntu recommends using the modern password authentication method provided by the MySQL version. Use the legacy method only when the application genuinely requires it and you have checked compatibility (according to the Ubuntu MySQL account documentation).

The MySQL server is now installed and basically configured. Next, install PHP.

Step 3 — Install PHP

Apache delivers content, MySQL stores data, and PHP processes dynamic code. To enable Apache to run PHP and PHP to connect to MySQL, install the required packages:

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

Ubuntu provides the php, the PHP module for Apache, and php-mysql in the official documentation (according to the Ubuntu PHP installation documentation).

Check the actual PHP version installed from the Ubuntu repositories:

php -v

Do not hard-code a result such as PHP 8.1.2 in the guide, because the version depends on the Ubuntu release, update repositories, and installation date. As of August 23, 2026, the PHP 8.5 branch is actively supported; PHP 8.4 is still within its support period, while PHP 8.2 receives only security fixes until December 31, 2026 (according to PHP.net). Prioritize the version provided by your Ubuntu repositories and check your application's compatibility.

Restart Apache to ensure that the new module and configuration are loaded:

sudo systemctl restart apache2

Step 4 — Create a Virtual Host for the Website

Apache allows you to create multiple Virtual Hosts to host multiple domains on the same server. In this example, replace your_domain with your actual domain name and ensure that the DNS record points to the server's IP address.

You can also view the guide to pointing a domain to a server.

Instead of using the default directory directly, /var/www/htmlcreate a separate directory for the website:

sudo mkdir -p /var/www/your_domain
sudo chown -R "$USER":"$USER" /var/www/your_domain

Create the Virtual Host configuration file:

sudo nano /etc/apache2/sites-available/your_domain.conf

Add the following basic configuration:

<VirtualHost *:80>
    ServerName your_domain
    ServerAlias www.your_domain
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/your_domain

    <Directory /var/www/your_domain>
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/your_domain_error.log
    CustomLog ${APACHE_LOG_DIR}/your_domain_access.log combined
</VirtualHost>

Save the file and exit nano with CTRL+X, press Y and ENTER. Enable only AllowOverride All if you need to use the .htaccessfile; otherwise, you can omit the Directory block or use a more restrictive configuration.

Enable the Virtual Host, check the syntax, and reload Apache:

sudo a2ensite your_domain.conf
sudo apache2ctl configtest
sudo systemctl reload apache2

If you do not need Apache's default page, you can disable the default site:

sudo a2dissite 000-default.conf
sudo apache2ctl configtest
sudo systemctl reload apache2

If you do not yet have a domain name, keep the default site or create a separate test configuration. When using a real domain name, check DNS and open the correct ports on the firewall before accessing it.

Step 5 — Test PHP with Apache

Create a PHP test file in the website directory:

nano /var/www/your_domain/info.php
<?php
phpinfo();

Open http://your_domain/info.php in a browser. If the PHP information page appears, Apache has successfully processed the PHP file.

After testing, delete this file because it displays extensive configuration information that could help attackers:

rm /var/www/your_domain/info.php

Step 6 — Next Steps

  • Configure HTTPS with a valid TLS certificate before putting the website into production.
  • Open only the ports required on UFW, and do not allow MySQL access from the Internet unless the application requires it.
  • Use a separate MySQL account for each application, with the minimum permissions required.
  • Set up database backups and periodically test your ability to restore them.
  • Update Ubuntu, Apache, MySQL, and PHP according to your maintenance procedures.

You have completed the core components of the LAMP Stack on Ubuntu: Apache serves the website, MySQL manages data, and PHP processes dynamic content.

References

  • Ubuntu documentation: installing Apache2
  • Ubuntu documentation: installing and configuring MySQL
  • Ubuntu documentation: installing and configuring PHP
  • PHP.net: supported PHP versions
  • PHP.net: PHP releases

Chú thích cho quảng cáo
Apache LAMP Stack Linux Server MySQL PHP Ubuntu VPS
Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
Previous ArticleHow to secure Apache with Let’s Encrypt on Ubuntu
Next Article Comparing Lionel Messi and Cristiano Ronaldo: Their Complete Careers
Nuj Coom
  • Website
  • Facebook
  • X (Twitter)
  • Instagram

Related Posts

Protecting WordPress Against AI Bots and Unknown Crawlers

30/08/2026

Install Let’s Encrypt SSL on Ubuntu with OpenLiteSpeed and Automatic Renewal

30/08/2026

How to secure Apache with Let’s Encrypt on Ubuntu

30/08/2026
Add A Comment
Leave A Reply Cancel Reply

Latest posts

Skincare While Losing Weight: Keep Skin More Hydrated, Healthy, and Firm

What Is LAMP Stack? Discover the Power of LAMP Stack

Improve INP for a Blog: Measure and Fix It with PageSpeed Insights and Chrome DevTools

Check WordPress Plugins Before Updating: A 24-Hour Process

2025 E-Commerce Law: Compliance Checklist

Advertisement
Chú thích cho quảng cáo

SUBSCRIBE TO UPDATES

Get the latest creative news from SaibABC.Com on web tips, design, and business.

Copyright © 2024. Designed by NujCoom.
  • Home
  • Contact
  • Privacy
  • Tiếng Việt
  • Hmoob

Type above and press Enter to search. Press Esc to cancel.