Lamp
LAMP stack
LAMP is an acronym for Linux, Apache, MySQL, and PHP, it is a popular software stack for serving websites.
It is comprised of LAMP_(software_bundle)a Linux server operating system running the Apache2 web server, MySQL database, and the PHP scripting language.
This tutorial was made using Ubuntu 22.04, you must provision a vps have a domain name and configure dns settings as per your vps provider and domain registrars instruction.
- SSH into your vps and set a root password.
- Set up a non-root user account
- Now give the new user sudo privileges.
- Lets transfer our ssh-keys to our new user.
- Set up the firewall
- Lets go ahead and update the server now.
- Once the server is updated lets edit the sshd_config file to dissallow remote root access to our server and use our non root user to log in from now on.
- We need to reload sshd.
- Now we should reboot the server, when it comes back up you will need to ssh using the non-root user name that we just created.
- SSH back into your vps using your non-root user account.
- Now we are going to install our webserver and database server we are using apache2 for our webserver and mariadb for our database.
- We need to let apache2 through our firewall for now on port 80
- After installing apache2 and mariadb we need to enable and strart them.
- Run the mysql_secure_installation script and follow the instructions
- Now we will install php.
- Now that PHP is installed lets create the document root of our web server, and give the directory the right permissions.
- Now we will create our index.html file.
- We need to create the virtualhosts file
- We need to tell apache where are document root is, and enable rewrite, and restart apache.
- We are now going to use letsencrypt and certbot to enable ssl on our server.
- Now we will adjust the firewall to allow https traffic.
- Remove the allow 'Apache' rule so that we are only serving https traffic
- Now we are going to run the certbot program.
- Follow the instructions on the screen
- Check the status of the certbot renewal timer
- Do a dry run of the certbot renew script
ssh root@127.0.0.1 use the ip-address provided by your vps provider.
passwd set strong password.
adduser "new_user"
usermod -aG sudo "new_user"
rsync --archive --chown="new-user":"new-user" ~/.ssh /home/"new_user"
sudo ufw allow OpenSSH
sudo ufw enable
apt update; apt dist-upgrade -y; apt autoremove -y
vim /etc/ssh/sshd_config we want to change PermitRootLogin no to yes, make sure PubkeyAuthentication is set to yes, that PasswordAuthentication is set to no, and that KbdInteractiveAuthentication is no.
systemctl reload sshd
ssh "vps_user"@127.0.0.1" Of course replacing "vps_user" with your non-root user account and 127.0.0.1 with the acutual ip-address of your server.
sudo apt install apache2 mariadb-server -y
sudo ufw allow 'Apache' we will remove the allow 'Apache' rule and add the 'Apache Full' rule to enable https traffic later but for now lets just let in http.
sudo systemctl enable apache2
sudo systemctl start apache2
sudo systemctl enable mysql
sudo systemctl start mysql
sudo mysql_secure_installation
sudo apt install php libapache2-mod-php php-mysql -y
sudo mkdir /var/www/"my_domain_name.com"
sudo chmod -R 755 /var/www/"my_domain_name.com"
sudo vim /var/www/"my_domain_name.com"/index.html
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Welcome to my website</title> </head> <body> <h1>Looks like everything works!</h1> </body> </html>
sudo vim /etc/apache2/sites-available/"your_domain_name.com".conf
<VirtualHost *:80> ServerAdmin "email address"@"Your domain name here" ServerName "Your domain name here" ServerAlias www."Your domain name here" DocumentRoot /var/www/"Your domain name here" ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
sudo a2ensite "my_domain_name.com".conf
sudo a2enmod rewrite
sudo systemctl restart apache2
sudo apt update
sudo apt install certbot python3-certbot-apache
sudo systemctl reload apache2
sudo ufw allow 'Apache Full'
sudo ufw delete allow 'Apache'
sudo certbot --apache
sudo systemctl status certbot.timer
sudo certbot renew --dry-run
There we have it a lamp stack running on Ubuntu 22.04 serving our webpage in https.