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 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: DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
To: DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
sudo systemctl restart apache2 sudo systemctl status apache2
Installing other PHP Packages: sudo apt install php-cli
Creating a Virtual Host for Apache
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
CREATE DATABASE example_database; CREATE USER 'example_user'@'%' IDENTIFIED BY 'password';
Change password of users: ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
GRANT ALL ON example_database.* TO 'example_user'@'%'; exit