Skip to content
TekTinkers

TekTinkers

Learning and imagination unlock limitless possibilities in technology

  • TinkersLab
    • TinkersDocs
    • Garage LAN
    • HomeLab
  • Resources
    • Events
  • Minecraft
    • Minecraft Technologies
    • Server Tools ‘n Stuff
    • TinkersCraft
  • About
    • Education
    • Experience-Awards
    • Special Thanks
    • Volunteer-Charity
  • Toggle search form

Setup a LAMP server in Ubuntu

Posted on June 17, 2025June 17, 2025 By TekTinkers
Installing Apache
  • sudo apt update
  • sudo apt install apache2
  • sudo ufw app list
  • sudo ufw allow in “Apache”
  • sudo ufw status

Check Website’s URL via IP or DNS

Installing MySQL
  • sudo apt install mysql-server
  • sudo mysql

change “root” and “password” to whatever you want

  • ALTER USER ‘root’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘password’;
  • exit
  • sudo mysql_secure_installation
MySQL: Creating Users and Databases
  • sudo mysql -u root -p

Change “example_database”, “example_user” and “password” to whatever you want

  • CREATE DATABASE example_database;
  • CREATE USER ‘example_user’@’%’ IDENTIFIED BY ‘password’;

OPTIONAL – Change password of users:

  • ALTER USER ‘root’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘password’;
  • GRANT ALL ON example_database.* TO ‘example_user’@’%’;
  • exit
Installing PHP
  • sudo apt install php libapache2-mod-php php-mysql
  • php -v
  • sudo nano /etc/apache2/mods-enabled/dir.conf

change

  • <IfModule mod_dir.c> DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm </IfModule>

to

  • <IfModule mod_dir.c> DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm </IfModule>
  • sudo systemctl restart apache2
  • sudo systemctl status apache2

Installing other PHP Packages

  • sudo apt install php-cli
Creating a Virtual Host for Apache

Change “your_domain” to the name you want

  • sudo mkdir /var/www/your_domain
  • sudo chown -R $USER:$USER /var/www/your_domain
  • sudo nano /etc/apache2/sites-available/your_domain.conf

Copy / Paste into blank file

  • <VirtualHost *:80>
    ServerName your_domain
    ServerAlias www.your_domain
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/your_domain
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>
  • sudo a2ensite your_domain
  • sudo a2dissite 000-default
  • sudo apache2ctl configtest
  • sudo systemctl reload apache2
Linux, TinkersLab Tags:lamp, linux, ubuntu

Post navigation

Previous Post: Setup a Subsonic music server
Next Post: Commands to setup MySQL server and more

Copyright © 2025 TekTinkers - Images by CoPilot, unedited for the lol's