User Tools

Site Tools


setuplampubuntu22

This is an old revision of the document!


Commands to Setup a LAMP server in Ubuntu 22.

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

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

MySQL: Creating Users and Databases

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




Credit to: https://www.digitalocean.com/community/tutorials/how-to-install-lamp-stack-on-ubuntu

setuplampubuntu22.1745881517.txt.gz · Last modified: 2025/04/28 23:05 by tektinkers