Close Menu
  • Home
  • Life style
    • Beauty tips
    • Exercise & Training
    • Fashion
    • Healthline
  • Exploration
    • Celebrities
    • Business
    • Travel guides
    • Technology
  • Web tutorials
    • Hosting & Servers
    • Blogger guides
    • WordPress guides
  • English
    • Tiếng Việt
    • Hmong
    • English
Facebook YouTube X (Twitter) Instagram
Trending
  • Search Profile or Preferred Sources: Choose the Right Tool for Your Website
  • Set Up Brevo for WordPress: Verify Senders and Test SMTP Email
  • Samsung Galaxy S27 Ultra: 5,700mAh Battery, 60W Charging and Open Questions
  • How to Create a Better-Looking Blogger Comment Box with CSS
  • Amazfit’s Lactate Threshold Update: Use the Data to Run at the Right Effort
  • How to Check Whether Yandex Has Indexed an Article
  • Set Yandex Site Region and Check How Your Website Appears
  • What to Prepare Before Connecting a Website to Yandex Webmaster
Facebook YouTube X (Twitter) Instagram
SaibABCSaibABC
Chú thích cho quảng cáo
  • Home
  • Life style
    1. Beauty tips
    2. Exercise & Training
    3. Fashion
    4. Healthline
    5. View All

    Build a Simple Skincare Routine Without Buying Too Many Products

    30/08/2026

    How to choose mineral sunscreen that does not leave a white cast

    30/08/2026

    What Does PDRN in Cosmetics Do? How to Read Advertising

    30/08/2026

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

    30/08/2026

    Running in Hot Weather: Read WBGT and Know When to Stop

    19/09/2026

    Exercise With Atrial Fibrillation: How to Start and Progress Safely

    19/09/2026

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

    30/08/2026

    Strengthen Your Core with 12 Exercises from Beginner to Advanced

    30/08/2026

    Fashion Digital Product Passport: What Can You Read?

    30/08/2026

    Build a Minimalist Wardrobe in 2026: Buy Less, Wear Longer

    30/08/2026

    Winter Travel Fashion: Stylish Outfits for Men and Women

    22/12/2023

    Amazfit’s Lactate Threshold Update: Use the Data to Run at the Right Effort

    28/09/2026

    Running in Hot Weather: Read WBGT and Know When to Stop

    19/09/2026

    Exercise With Atrial Fibrillation: How to Start and Progress Safely

    19/09/2026

    Suunto Run Heart-Rate Tracking After an Update: Check Your Zones Before Running

    19/09/2026

    Amazfit’s Lactate Threshold Update: Use the Data to Run at the Right Effort

    28/09/2026

    Running in Hot Weather: Read WBGT and Know When to Stop

    19/09/2026

    Exercise With Atrial Fibrillation: How to Start and Progress Safely

    19/09/2026

    Suunto Run Heart-Rate Tracking After an Update: Check Your Zones Before Running

    19/09/2026
  • Exploration
    1. Celebrities
    2. Business
    3. Travel guides
    4. Technology
    Featured

    Samsung Galaxy S27 Ultra: 5,700mAh Battery, 60W Charging and Open Questions

    By Nuj Coom29/09/2026
    Recent

    Samsung Galaxy S27 Ultra: 5,700mAh Battery, 60W Charging and Open Questions

    29/09/2026

    Samsung Galaxy S26 Ultra Review: What Makes It Worth Buying—and What Doesn’t

    16/09/2026

    iPhone 18 Pro Max vs Galaxy S26 Ultra: Which One Should You Choose?

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

    Let’s Encrypt on Vultr: Enable HTTPS and Automatic Renewal

    09/09/2026

    Install WordPress on Vultr Manually: From Ubuntu to HTTPS

    08/09/2026

    Point Your Domain to a Vultr VPS and Verify the DNS Connection

    08/09/2026

    Set Up an Ubuntu VPS on Vultr: From Account Creation to SSH

    07/09/2026

    How to Create a Better-Looking Blogger Comment Box with CSS

    28/09/2026

    A 90-Day Blog Growth Plan: Write, Measure, and Improve

    26/09/2026

    Blogspot Maintenance: Fix Broken Links, Images, and Slow Pages

    26/09/2026

    How Does Google Find a Blog? The 3 Key Stages Explained

    26/09/2026

    Set Up Brevo for WordPress: Verify Senders and Test SMTP Email

    29/09/2026

    How to Check Whether Yandex Has Indexed an Article

    26/09/2026

    Set Yandex Site Region and Check How Your Website Appears

    26/09/2026

    What to Prepare Before Connecting a Website to Yandex Webmaster

    26/09/2026

    Search Profile or Preferred Sources: Choose the Right Tool for Your Website

    14/10/2026

    Set Up Brevo for WordPress: Verify Senders and Test SMTP Email

    29/09/2026

    How to Create a Better-Looking Blogger Comment Box with CSS

    28/09/2026

    How to Check Whether Yandex Has Indexed an Article

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

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

Nuj CoomBy Nuj CoomUpdated:11/09/2026
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. Reference source

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 commands for installing Apache, MySQL, and PHP use Ubuntu’s software repositories, so the exact versions may vary depending on the Ubuntu release, available updates, and when the commands are run. Ubuntu’s documentation is currently maintained for the latest LTS release, while noting differences from older LTS releases where necessary (according to the Ubuntu Server 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 a widely used web server on Linux. 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, start it with:

sudo systemctl start mysql

On Ubuntu, the default local MySQL account root locally typically authenticates through auth_socket. You can therefore access MySQL with:

sudo mysql -u root

Do not use the root account for applications. Ubuntu recommends creating a separate account with appropriate privileges for each database (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 from remote access and remove the test database if the system presents these options. Do not apply answers from older versions mechanically.

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 -u root
CREATE DATABASE app_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'app_user'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'ThayBangMatKhauManh';
GRANT ALL PRIVILEGES ON app_db.* TO 'app_user'@'localhost';
EXIT;

The example above uses the authentication method caching_sha2_password documented by Ubuntu. Choose a different method only when the application genuinely requires it and you have verified 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 software repository. After installation, check the actual PHP version with:

php -v

Do not hard-code a specific version in the guide, because the version depends on the Ubuntu release, available updates, and the time of installation. As of the article update on September 2, 2026, PHP 8.5 and PHP 8.4 remained supported branches; PHP 8.3 will receive security fixes only through December 31, 2027, while PHP 8.2 will receive them through December 31, 2026 (according to the PHP.net). Prefer the version provided by the Ubuntu repository and verify application 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 .htaccess; otherwise, 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.

Related reading: Install WordPress on Vultr Manually: From Ubuntu to HTTPS.

Reference source

  • Ubuntu Server documentation
  • Ubuntu documentation: installing Apache2
  • Ubuntu documentation: installing and configuring MySQL
  • PHP: Supported Versions
  • 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 ArticleConfigure HTTPS for Apache with Let’s Encrypt on Ubuntu
Next Article Messi vs Ronaldo: Compare Their Careers, Trophies, and Playing Styles
Nuj Coom
  • Website
  • Facebook
  • X (Twitter)
  • Instagram

I'm a doctor, for sure. But I also love writing and sharing knowledge, life experiences, web tricks, and useful lectures. Let's cheer for your passion.

Related Posts

Set Up Brevo for WordPress: Verify Senders and Test SMTP Email

29/09/2026

How to Check Whether Yandex Has Indexed an Article

26/09/2026

Set Yandex Site Region and Check How Your Website Appears

26/09/2026
Add A Comment
Leave A Reply Cancel Reply

Latest posts

Fashion Digital Product Passport: What Can You Read?

Which Blogspot Monetization Model Fits Your Content and Readers?

15 of the World’s Most Popular Celebrities of All Time

What Is Yandex Webmaster—and When Should Your Website Use It?

WHOOP Strength Training Detection: When to Trust It and When to Edit It?

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
  • Hmong

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