SAM SIN

System Administrator

Systems Support

0

No products in the cart.

SAM SIN

System Administrator

Systems Support

Blog Post

LAMP Stack Installation & Virtual Host on Ubuntu 24.04

June 8, 2026 Uncategorized

LAMP Stack Installation & Virtual Host on Ubuntu 24.04

Install LAMP Stack

Update System

sudo apt update && sudo apt upgrade -y

Install Apache

sudo apt install apache2 -y

sudo systemctl enable apache2

sudo systemctl start apache2

sudo ufw allow in "Apache Full"

Install MySQL

sudo apt install mysql-server -y

sudo systemctl enable mysql

sudo mysql_secure_installation

Install PHP 8.1

sudo apt install software-properties-common -y

sudo add-apt-repository ppa:ondrej/php

sudo apt update

sudo apt install php8.1 php8.1-cli php8.1-common php8.1-opcache \

php8.1-gd php8.1-curl php8.1-mysql php8.1-mbstring php8.1-xml \

php8.1-zip php8.1-bcmath libapache2-mod-php8.1 -y

php -v

Set PHP 8.1 as Default for Apache

sudo a2dismod php8.3

sudo a2enmod php8.1

sudo systemctl restart apache2


Create Virtual Host for example.com

Create Document Root

sudo mkdir -p /var/www/example.com/public_html

sudo chown -R $USER:$USER /var/www/example.com/public_html

sudo chmod -R 755 /var/www/example.com

Virtual Host Config

Create /etc/apache2/sites-available/example.com.conf:


ServerName example.com

ServerAlias www.example.com

ServerAdmin webmaster@example.com

DocumentRoot /var/www/example.com/public_html

Options Indexes FollowSymLinks

AllowOverride All

Require all granted

ErrorLog ${APACHE_LOG_DIR}/example.com_error.log

CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined

Enable Site

sudo a2ensite example.com.conf

sudo a2dissite 000-default.conf

sudo a2enmod rewrite

sudo apache2ctl configtest

sudo systemctl reload apache2

SSL with Let’s Encrypt

sudo apt install certbot python3-certbot-apache -y

sudo certbot --apache -d example.com -d www.example.com


Quick Reference

$cells =

LAMP Stack Installation & Virtual Host on Ubuntu 24.04

Install LAMP Stack

Update System

sudo apt update && sudo apt upgrade -y

Install Apache

sudo apt install apache2 -y

sudo systemctl enable apache2

sudo systemctl start apache2

sudo ufw allow in "Apache Full"

Install MySQL

sudo apt install mysql-server -y

sudo systemctl enable mysql

sudo mysql_secure_installation

Install PHP 8.1

sudo apt install software-properties-common -y

sudo add-apt-repository ppa:ondrej/php

sudo apt update

sudo apt install php8.1 php8.1-cli php8.1-common php8.1-opcache \

php8.1-gd php8.1-curl php8.1-mysql php8.1-mbstring php8.1-xml \

php8.1-zip php8.1-bcmath libapache2-mod-php8.1 -y

php -v

Set PHP 8.1 as Default for Apache

sudo a2dismod php8.3

sudo a2enmod php8.1

sudo systemctl restart apache2


Create Virtual Host for example.com

Create Document Root

sudo mkdir -p /var/www/example.com/public_html

sudo chown -R $USER:$USER /var/www/example.com/public_html

sudo chmod -R 755 /var/www/example.com

Virtual Host Config

Create /etc/apache2/sites-available/example.com.conf:


ServerName example.com

ServerAlias www.example.com

ServerAdmin webmaster@example.com

DocumentRoot /var/www/example.com/public_html

Options Indexes FollowSymLinks

AllowOverride All

Require all granted

ErrorLog ${APACHE_LOG_DIR}/example.com_error.log

CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined

Enable Site

sudo a2ensite example.com.conf

sudo a2dissite 000-default.conf

sudo a2enmod rewrite

sudo apache2ctl configtest

sudo systemctl reload apache2

SSL with Let’s Encrypt

sudo apt install certbot python3-certbot-apache -y

sudo certbot --apache -d example.com -d www.example.com


Quick Reference

| Task | Command |

| Enable site | sudo a2ensite example.com.conf |

| Disable site | sudo a2dissite example.com.conf |

| Test config | sudo apache2ctl configtest |

| Reload Apache | sudo systemctl reload apache2 |

| View error log | sudo tail -f /var/log/apache2/example.com_error.log |

.Groups[1].Value -split ‘\|’

$tds = ($cells | ForEach-Object { “

$(

LAMP Stack Installation & Virtual Host on Ubuntu 24.04

Install LAMP Stack

Update System

sudo apt update && sudo apt upgrade -y

Install Apache

sudo apt install apache2 -y

sudo systemctl enable apache2

sudo systemctl start apache2

sudo ufw allow in "Apache Full"

Install MySQL

sudo apt install mysql-server -y

sudo systemctl enable mysql

sudo mysql_secure_installation

Install PHP 8.1

sudo apt install software-properties-common -y

sudo add-apt-repository ppa:ondrej/php

sudo apt update

sudo apt install php8.1 php8.1-cli php8.1-common php8.1-opcache \

php8.1-gd php8.1-curl php8.1-mysql php8.1-mbstring php8.1-xml \

php8.1-zip php8.1-bcmath libapache2-mod-php8.1 -y

php -v

Set PHP 8.1 as Default for Apache

sudo a2dismod php8.3

sudo a2enmod php8.1

sudo systemctl restart apache2


Create Virtual Host for example.com

Create Document Root

sudo mkdir -p /var/www/example.com/public_html

sudo chown -R $USER:$USER /var/www/example.com/public_html

sudo chmod -R 755 /var/www/example.com

Virtual Host Config

Create /etc/apache2/sites-available/example.com.conf:


ServerName example.com

ServerAlias www.example.com

ServerAdmin webmaster@example.com

DocumentRoot /var/www/example.com/public_html

Options Indexes FollowSymLinks

AllowOverride All

Require all granted

ErrorLog ${APACHE_LOG_DIR}/example.com_error.log

CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined

Enable Site

sudo a2ensite example.com.conf

sudo a2dissite 000-default.conf

sudo a2enmod rewrite

sudo apache2ctl configtest

sudo systemctl reload apache2

SSL with Let’s Encrypt

sudo apt install certbot python3-certbot-apache -y

sudo certbot --apache -d example.com -d www.example.com


Quick Reference

| Task | Command |

| Enable site | sudo a2ensite example.com.conf |

| Disable site | sudo a2dissite example.com.conf |

| Test config | sudo apache2ctl configtest |

| Reload Apache | sudo systemctl reload apache2 |

| View error log | sudo tail -f /var/log/apache2/example.com_error.log |

.Trim())

” }) -join ”

$tds

$cells =

LAMP Stack Installation & Virtual Host on Ubuntu 24.04

Install LAMP Stack

Update System

sudo apt update && sudo apt upgrade -y

Install Apache

sudo apt install apache2 -y

sudo systemctl enable apache2

sudo systemctl start apache2

sudo ufw allow in "Apache Full"

Install MySQL

sudo apt install mysql-server -y

sudo systemctl enable mysql

sudo mysql_secure_installation

Install PHP 8.1

sudo apt install software-properties-common -y

sudo add-apt-repository ppa:ondrej/php

sudo apt update

sudo apt install php8.1 php8.1-cli php8.1-common php8.1-opcache \

php8.1-gd php8.1-curl php8.1-mysql php8.1-mbstring php8.1-xml \

php8.1-zip php8.1-bcmath libapache2-mod-php8.1 -y

php -v

Set PHP 8.1 as Default for Apache

sudo a2dismod php8.3

sudo a2enmod php8.1

sudo systemctl restart apache2


Create Virtual Host for example.com

Create Document Root

sudo mkdir -p /var/www/example.com/public_html

sudo chown -R $USER:$USER /var/www/example.com/public_html

sudo chmod -R 755 /var/www/example.com

Virtual Host Config

Create /etc/apache2/sites-available/example.com.conf:


ServerName example.com

ServerAlias www.example.com

ServerAdmin webmaster@example.com

DocumentRoot /var/www/example.com/public_html

Options Indexes FollowSymLinks

AllowOverride All

Require all granted

ErrorLog ${APACHE_LOG_DIR}/example.com_error.log

CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined

Enable Site

sudo a2ensite example.com.conf

sudo a2dissite 000-default.conf

sudo a2enmod rewrite

sudo apache2ctl configtest

sudo systemctl reload apache2

SSL with Let’s Encrypt

sudo apt install certbot python3-certbot-apache -y

sudo certbot --apache -d example.com -d www.example.com


Quick Reference

| Task | Command |

| Enable site | sudo a2ensite example.com.conf |

| Disable site | sudo a2dissite example.com.conf |

| Test config | sudo apache2ctl configtest |

| Reload Apache | sudo systemctl reload apache2 |

| View error log | sudo tail -f /var/log/apache2/example.com_error.log |

.Groups[1].Value -split ‘\|’

$tds = ($cells | ForEach-Object { “

$(

LAMP Stack Installation & Virtual Host on Ubuntu 24.04

Install LAMP Stack

Update System

sudo apt update && sudo apt upgrade -y

Install Apache

sudo apt install apache2 -y

sudo systemctl enable apache2

sudo systemctl start apache2

sudo ufw allow in "Apache Full"

Install MySQL

sudo apt install mysql-server -y

sudo systemctl enable mysql

sudo mysql_secure_installation

Install PHP 8.1

sudo apt install software-properties-common -y

sudo add-apt-repository ppa:ondrej/php

sudo apt update

sudo apt install php8.1 php8.1-cli php8.1-common php8.1-opcache \

php8.1-gd php8.1-curl php8.1-mysql php8.1-mbstring php8.1-xml \

php8.1-zip php8.1-bcmath libapache2-mod-php8.1 -y

php -v

Set PHP 8.1 as Default for Apache

sudo a2dismod php8.3

sudo a2enmod php8.1

sudo systemctl restart apache2


Create Virtual Host for example.com

Create Document Root

sudo mkdir -p /var/www/example.com/public_html

sudo chown -R $USER:$USER /var/www/example.com/public_html

sudo chmod -R 755 /var/www/example.com

Virtual Host Config

Create /etc/apache2/sites-available/example.com.conf:


ServerName example.com

ServerAlias www.example.com

ServerAdmin webmaster@example.com

DocumentRoot /var/www/example.com/public_html

Options Indexes FollowSymLinks

AllowOverride All

Require all granted

ErrorLog ${APACHE_LOG_DIR}/example.com_error.log

CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined

Enable Site

sudo a2ensite example.com.conf

sudo a2dissite 000-default.conf

sudo a2enmod rewrite

sudo apache2ctl configtest

sudo systemctl reload apache2

SSL with Let’s Encrypt

sudo apt install certbot python3-certbot-apache -y

sudo certbot --apache -d example.com -d www.example.com


Quick Reference

| Task | Command |

| Enable site | sudo a2ensite example.com.conf |

| Disable site | sudo a2dissite example.com.conf |

| Test config | sudo apache2ctl configtest |

| Reload Apache | sudo systemctl reload apache2 |

| View error log | sudo tail -f /var/log/apache2/example.com_error.log |

.Trim())

” }) -join ”

$tds

$cells =

LAMP Stack Installation & Virtual Host on Ubuntu 24.04

Install LAMP Stack

Update System

sudo apt update && sudo apt upgrade -y

Install Apache

sudo apt install apache2 -y

sudo systemctl enable apache2

sudo systemctl start apache2

sudo ufw allow in "Apache Full"

Install MySQL

sudo apt install mysql-server -y

sudo systemctl enable mysql

sudo mysql_secure_installation

Install PHP 8.1

sudo apt install software-properties-common -y

sudo add-apt-repository ppa:ondrej/php

sudo apt update

sudo apt install php8.1 php8.1-cli php8.1-common php8.1-opcache \

php8.1-gd php8.1-curl php8.1-mysql php8.1-mbstring php8.1-xml \

php8.1-zip php8.1-bcmath libapache2-mod-php8.1 -y

php -v

Set PHP 8.1 as Default for Apache

sudo a2dismod php8.3

sudo a2enmod php8.1

sudo systemctl restart apache2


Create Virtual Host for example.com

Create Document Root

sudo mkdir -p /var/www/example.com/public_html

sudo chown -R $USER:$USER /var/www/example.com/public_html

sudo chmod -R 755 /var/www/example.com

Virtual Host Config

Create /etc/apache2/sites-available/example.com.conf:


ServerName example.com

ServerAlias www.example.com

ServerAdmin webmaster@example.com

DocumentRoot /var/www/example.com/public_html

Options Indexes FollowSymLinks

AllowOverride All

Require all granted

ErrorLog ${APACHE_LOG_DIR}/example.com_error.log

CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined

Enable Site

sudo a2ensite example.com.conf

sudo a2dissite 000-default.conf

sudo a2enmod rewrite

sudo apache2ctl configtest

sudo systemctl reload apache2

SSL with Let’s Encrypt

sudo apt install certbot python3-certbot-apache -y

sudo certbot --apache -d example.com -d www.example.com


Quick Reference

| Task | Command |

| Enable site | sudo a2ensite example.com.conf |

| Disable site | sudo a2dissite example.com.conf |

| Test config | sudo apache2ctl configtest |

| Reload Apache | sudo systemctl reload apache2 |

| View error log | sudo tail -f /var/log/apache2/example.com_error.log |

.Groups[1].Value -split ‘\|’

$tds = ($cells | ForEach-Object { “

$(

LAMP Stack Installation & Virtual Host on Ubuntu 24.04

Install LAMP Stack

Update System

sudo apt update && sudo apt upgrade -y

Install Apache

sudo apt install apache2 -y

sudo systemctl enable apache2

sudo systemctl start apache2

sudo ufw allow in "Apache Full"

Install MySQL

sudo apt install mysql-server -y

sudo systemctl enable mysql

sudo mysql_secure_installation

Install PHP 8.1

sudo apt install software-properties-common -y

sudo add-apt-repository ppa:ondrej/php

sudo apt update

sudo apt install php8.1 php8.1-cli php8.1-common php8.1-opcache \

php8.1-gd php8.1-curl php8.1-mysql php8.1-mbstring php8.1-xml \

php8.1-zip php8.1-bcmath libapache2-mod-php8.1 -y

php -v

Set PHP 8.1 as Default for Apache

sudo a2dismod php8.3

sudo a2enmod php8.1

sudo systemctl restart apache2


Create Virtual Host for example.com

Create Document Root

sudo mkdir -p /var/www/example.com/public_html

sudo chown -R $USER:$USER /var/www/example.com/public_html

sudo chmod -R 755 /var/www/example.com

Virtual Host Config

Create /etc/apache2/sites-available/example.com.conf:


ServerName example.com

ServerAlias www.example.com

ServerAdmin webmaster@example.com

DocumentRoot /var/www/example.com/public_html

Options Indexes FollowSymLinks

AllowOverride All

Require all granted

ErrorLog ${APACHE_LOG_DIR}/example.com_error.log

CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined

Enable Site

sudo a2ensite example.com.conf

sudo a2dissite 000-default.conf

sudo a2enmod rewrite

sudo apache2ctl configtest

sudo systemctl reload apache2

SSL with Let’s Encrypt

sudo apt install certbot python3-certbot-apache -y

sudo certbot --apache -d example.com -d www.example.com


Quick Reference

| Task | Command |

| Enable site | sudo a2ensite example.com.conf |

| Disable site | sudo a2dissite example.com.conf |

| Test config | sudo apache2ctl configtest |

| Reload Apache | sudo systemctl reload apache2 |

| View error log | sudo tail -f /var/log/apache2/example.com_error.log |

.Trim())

” }) -join ”

$tds

$cells =

LAMP Stack Installation & Virtual Host on Ubuntu 24.04

Install LAMP Stack

Update System

sudo apt update && sudo apt upgrade -y

Install Apache

sudo apt install apache2 -y

sudo systemctl enable apache2

sudo systemctl start apache2

sudo ufw allow in "Apache Full"

Install MySQL

sudo apt install mysql-server -y

sudo systemctl enable mysql

sudo mysql_secure_installation

Install PHP 8.1

sudo apt install software-properties-common -y

sudo add-apt-repository ppa:ondrej/php

sudo apt update

sudo apt install php8.1 php8.1-cli php8.1-common php8.1-opcache \

php8.1-gd php8.1-curl php8.1-mysql php8.1-mbstring php8.1-xml \

php8.1-zip php8.1-bcmath libapache2-mod-php8.1 -y

php -v

Set PHP 8.1 as Default for Apache

sudo a2dismod php8.3

sudo a2enmod php8.1

sudo systemctl restart apache2


Create Virtual Host for example.com

Create Document Root

sudo mkdir -p /var/www/example.com/public_html

sudo chown -R $USER:$USER /var/www/example.com/public_html

sudo chmod -R 755 /var/www/example.com

Virtual Host Config

Create /etc/apache2/sites-available/example.com.conf:


ServerName example.com

ServerAlias www.example.com

ServerAdmin webmaster@example.com

DocumentRoot /var/www/example.com/public_html

Options Indexes FollowSymLinks

AllowOverride All

Require all granted

ErrorLog ${APACHE_LOG_DIR}/example.com_error.log

CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined

Enable Site

sudo a2ensite example.com.conf

sudo a2dissite 000-default.conf

sudo a2enmod rewrite

sudo apache2ctl configtest

sudo systemctl reload apache2

SSL with Let’s Encrypt

sudo apt install certbot python3-certbot-apache -y

sudo certbot --apache -d example.com -d www.example.com


Quick Reference

| Task | Command |

| Enable site | sudo a2ensite example.com.conf |

| Disable site | sudo a2dissite example.com.conf |

| Test config | sudo apache2ctl configtest |

| Reload Apache | sudo systemctl reload apache2 |

| View error log | sudo tail -f /var/log/apache2/example.com_error.log |

.Groups[1].Value -split ‘\|’

$tds = ($cells | ForEach-Object { “

$(

LAMP Stack Installation & Virtual Host on Ubuntu 24.04

Install LAMP Stack

Update System

sudo apt update && sudo apt upgrade -y

Install Apache

sudo apt install apache2 -y

sudo systemctl enable apache2

sudo systemctl start apache2

sudo ufw allow in "Apache Full"

Install MySQL

sudo apt install mysql-server -y

sudo systemctl enable mysql

sudo mysql_secure_installation

Install PHP 8.1

sudo apt install software-properties-common -y

sudo add-apt-repository ppa:ondrej/php

sudo apt update

sudo apt install php8.1 php8.1-cli php8.1-common php8.1-opcache \

php8.1-gd php8.1-curl php8.1-mysql php8.1-mbstring php8.1-xml \

php8.1-zip php8.1-bcmath libapache2-mod-php8.1 -y

php -v

Set PHP 8.1 as Default for Apache

sudo a2dismod php8.3

sudo a2enmod php8.1

sudo systemctl restart apache2


Create Virtual Host for example.com

Create Document Root

sudo mkdir -p /var/www/example.com/public_html

sudo chown -R $USER:$USER /var/www/example.com/public_html

sudo chmod -R 755 /var/www/example.com

Virtual Host Config

Create /etc/apache2/sites-available/example.com.conf:


ServerName example.com

ServerAlias www.example.com

ServerAdmin webmaster@example.com

DocumentRoot /var/www/example.com/public_html

Options Indexes FollowSymLinks

AllowOverride All

Require all granted

ErrorLog ${APACHE_LOG_DIR}/example.com_error.log

CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined

Enable Site

sudo a2ensite example.com.conf

sudo a2dissite 000-default.conf

sudo a2enmod rewrite

sudo apache2ctl configtest

sudo systemctl reload apache2

SSL with Let’s Encrypt

sudo apt install certbot python3-certbot-apache -y

sudo certbot --apache -d example.com -d www.example.com


Quick Reference

| Task | Command |

| Enable site | sudo a2ensite example.com.conf |

| Disable site | sudo a2dissite example.com.conf |

| Test config | sudo apache2ctl configtest |

| Reload Apache | sudo systemctl reload apache2 |

| View error log | sudo tail -f /var/log/apache2/example.com_error.log |

.Trim())

” }) -join ”

$tds

$cells =

LAMP Stack Installation & Virtual Host on Ubuntu 24.04

Install LAMP Stack

Update System

sudo apt update && sudo apt upgrade -y

Install Apache

sudo apt install apache2 -y

sudo systemctl enable apache2

sudo systemctl start apache2

sudo ufw allow in "Apache Full"

Install MySQL

sudo apt install mysql-server -y

sudo systemctl enable mysql

sudo mysql_secure_installation

Install PHP 8.1

sudo apt install software-properties-common -y

sudo add-apt-repository ppa:ondrej/php

sudo apt update

sudo apt install php8.1 php8.1-cli php8.1-common php8.1-opcache \

php8.1-gd php8.1-curl php8.1-mysql php8.1-mbstring php8.1-xml \

php8.1-zip php8.1-bcmath libapache2-mod-php8.1 -y

php -v

Set PHP 8.1 as Default for Apache

sudo a2dismod php8.3

sudo a2enmod php8.1

sudo systemctl restart apache2


Create Virtual Host for example.com

Create Document Root

sudo mkdir -p /var/www/example.com/public_html

sudo chown -R $USER:$USER /var/www/example.com/public_html

sudo chmod -R 755 /var/www/example.com

Virtual Host Config

Create /etc/apache2/sites-available/example.com.conf:


ServerName example.com

ServerAlias www.example.com

ServerAdmin webmaster@example.com

DocumentRoot /var/www/example.com/public_html

Options Indexes FollowSymLinks

AllowOverride All

Require all granted

ErrorLog ${APACHE_LOG_DIR}/example.com_error.log

CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined

Enable Site

sudo a2ensite example.com.conf

sudo a2dissite 000-default.conf

sudo a2enmod rewrite

sudo apache2ctl configtest

sudo systemctl reload apache2

SSL with Let’s Encrypt

sudo apt install certbot python3-certbot-apache -y

sudo certbot --apache -d example.com -d www.example.com


Quick Reference

| Task | Command |

| Enable site | sudo a2ensite example.com.conf |

| Disable site | sudo a2dissite example.com.conf |

| Test config | sudo apache2ctl configtest |

| Reload Apache | sudo systemctl reload apache2 |

| View error log | sudo tail -f /var/log/apache2/example.com_error.log |

.Groups[1].Value -split ‘\|’

$tds = ($cells | ForEach-Object { “

$(

LAMP Stack Installation & Virtual Host on Ubuntu 24.04

Install LAMP Stack

Update System

sudo apt update && sudo apt upgrade -y

Install Apache

sudo apt install apache2 -y

sudo systemctl enable apache2

sudo systemctl start apache2

sudo ufw allow in "Apache Full"

Install MySQL

sudo apt install mysql-server -y

sudo systemctl enable mysql

sudo mysql_secure_installation

Install PHP 8.1

sudo apt install software-properties-common -y

sudo add-apt-repository ppa:ondrej/php

sudo apt update

sudo apt install php8.1 php8.1-cli php8.1-common php8.1-opcache \

php8.1-gd php8.1-curl php8.1-mysql php8.1-mbstring php8.1-xml \

php8.1-zip php8.1-bcmath libapache2-mod-php8.1 -y

php -v

Set PHP 8.1 as Default for Apache

sudo a2dismod php8.3

sudo a2enmod php8.1

sudo systemctl restart apache2


Create Virtual Host for example.com

Create Document Root

sudo mkdir -p /var/www/example.com/public_html

sudo chown -R $USER:$USER /var/www/example.com/public_html

sudo chmod -R 755 /var/www/example.com

Virtual Host Config

Create /etc/apache2/sites-available/example.com.conf:


ServerName example.com

ServerAlias www.example.com

ServerAdmin webmaster@example.com

DocumentRoot /var/www/example.com/public_html

Options Indexes FollowSymLinks

AllowOverride All

Require all granted

ErrorLog ${APACHE_LOG_DIR}/example.com_error.log

CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined

Enable Site

sudo a2ensite example.com.conf

sudo a2dissite 000-default.conf

sudo a2enmod rewrite

sudo apache2ctl configtest

sudo systemctl reload apache2

SSL with Let’s Encrypt

sudo apt install certbot python3-certbot-apache -y

sudo certbot --apache -d example.com -d www.example.com


Quick Reference

| Task | Command |

| Enable site | sudo a2ensite example.com.conf |

| Disable site | sudo a2dissite example.com.conf |

| Test config | sudo apache2ctl configtest |

| Reload Apache | sudo systemctl reload apache2 |

| View error log | sudo tail -f /var/log/apache2/example.com_error.log |

.Trim())

” }) -join ”

$tds

$cells =

LAMP Stack Installation & Virtual Host on Ubuntu 24.04

Install LAMP Stack

Update System

sudo apt update && sudo apt upgrade -y

Install Apache

sudo apt install apache2 -y

sudo systemctl enable apache2

sudo systemctl start apache2

sudo ufw allow in "Apache Full"

Install MySQL

sudo apt install mysql-server -y

sudo systemctl enable mysql

sudo mysql_secure_installation

Install PHP 8.1

sudo apt install software-properties-common -y

sudo add-apt-repository ppa:ondrej/php

sudo apt update

sudo apt install php8.1 php8.1-cli php8.1-common php8.1-opcache \

php8.1-gd php8.1-curl php8.1-mysql php8.1-mbstring php8.1-xml \

php8.1-zip php8.1-bcmath libapache2-mod-php8.1 -y

php -v

Set PHP 8.1 as Default for Apache

sudo a2dismod php8.3

sudo a2enmod php8.1

sudo systemctl restart apache2


Create Virtual Host for example.com

Create Document Root

sudo mkdir -p /var/www/example.com/public_html

sudo chown -R $USER:$USER /var/www/example.com/public_html

sudo chmod -R 755 /var/www/example.com

Virtual Host Config

Create /etc/apache2/sites-available/example.com.conf:


ServerName example.com

ServerAlias www.example.com

ServerAdmin webmaster@example.com

DocumentRoot /var/www/example.com/public_html

Options Indexes FollowSymLinks

AllowOverride All

Require all granted

ErrorLog ${APACHE_LOG_DIR}/example.com_error.log

CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined

Enable Site

sudo a2ensite example.com.conf

sudo a2dissite 000-default.conf

sudo a2enmod rewrite

sudo apache2ctl configtest

sudo systemctl reload apache2

SSL with Let’s Encrypt

sudo apt install certbot python3-certbot-apache -y

sudo certbot --apache -d example.com -d www.example.com


Quick Reference

| Task | Command |

| Enable site | sudo a2ensite example.com.conf |

| Disable site | sudo a2dissite example.com.conf |

| Test config | sudo apache2ctl configtest |

| Reload Apache | sudo systemctl reload apache2 |

| View error log | sudo tail -f /var/log/apache2/example.com_error.log |

.Groups[1].Value -split ‘\|’

$tds = ($cells | ForEach-Object { “

$(

LAMP Stack Installation & Virtual Host on Ubuntu 24.04

Install LAMP Stack

Update System

sudo apt update && sudo apt upgrade -y

Install Apache

sudo apt install apache2 -y

sudo systemctl enable apache2

sudo systemctl start apache2

sudo ufw allow in "Apache Full"

Install MySQL

sudo apt install mysql-server -y

sudo systemctl enable mysql

sudo mysql_secure_installation

Install PHP 8.1

sudo apt install software-properties-common -y

sudo add-apt-repository ppa:ondrej/php

sudo apt update

sudo apt install php8.1 php8.1-cli php8.1-common php8.1-opcache \

php8.1-gd php8.1-curl php8.1-mysql php8.1-mbstring php8.1-xml \

php8.1-zip php8.1-bcmath libapache2-mod-php8.1 -y

php -v

Set PHP 8.1 as Default for Apache

sudo a2dismod php8.3

sudo a2enmod php8.1

sudo systemctl restart apache2


Create Virtual Host for example.com

Create Document Root

sudo mkdir -p /var/www/example.com/public_html

sudo chown -R $USER:$USER /var/www/example.com/public_html

sudo chmod -R 755 /var/www/example.com

Virtual Host Config

Create /etc/apache2/sites-available/example.com.conf:


ServerName example.com

ServerAlias www.example.com

ServerAdmin webmaster@example.com

DocumentRoot /var/www/example.com/public_html

Options Indexes FollowSymLinks

AllowOverride All

Require all granted

ErrorLog ${APACHE_LOG_DIR}/example.com_error.log

CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined

Enable Site

sudo a2ensite example.com.conf

sudo a2dissite 000-default.conf

sudo a2enmod rewrite

sudo apache2ctl configtest

sudo systemctl reload apache2

SSL with Let’s Encrypt

sudo apt install certbot python3-certbot-apache -y

sudo certbot --apache -d example.com -d www.example.com


Quick Reference

| Task | Command |

| Enable site | sudo a2ensite example.com.conf |

| Disable site | sudo a2dissite example.com.conf |

| Test config | sudo apache2ctl configtest |

| Reload Apache | sudo systemctl reload apache2 |

| View error log | sudo tail -f /var/log/apache2/example.com_error.log |

.Trim())

” }) -join ”

$tds

Write a comment
Verified by MonsterInsights