Lamp: Difference between revisions

From cumulotechnic
No edit summary
No edit summary
Line 43: Line 43:
<li>Now we will create our index.html file.</li>
<li>Now we will create our index.html file.</li>
<p><strong>sudo vim /var/www/"my_domain_name.com"/index.html</strong></p>
<p><strong>sudo vim /var/www/"my_domain_name.com"/index.html</strong></p>
<xmp>
<div>
<div>
         <pre style="font-size: 150%">
         <pre style="font-size: 150%">
Line 58: Line 58:
</html>
</html>
         </pre>
         </pre>
</div></xmp>
</div>

Revision as of 12:02, 14 August 2023

LAMP stack

LAMP is an acronym for Linux, Apache, MySQL, and PHP stack, it is a popular software stack for serving websites.

It is comprised of 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.
  • ssh root@127.0.0.1 use the ip-address provided by your vps provider.

    passwd set strong password.

  • Set up a non-root user account
  • adduser "new_user"

  • Now give the new user sudo privileges.
  • usermod -aG sudo "new_user"

  • Lets transfer our ssh-keys to our new user.
  • rsync --archive --chown="new-user":"new-user" ~/.ssh /home/"new_user"

  • Set up the firewall
  • sudo ufw allow OpenSSH

    sudo ufw enable

  • Lets go ahead and update the server now.
  • apt update; apt dist-upgrade -y; apt autoremove -y

  • 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.
  • 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.

  • We need to reload sshd.
  • systemctl 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.
  • 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.

  • Now we are going to install our webserver and database server we are using apache2 for our webserver and mariadb for our database.
  • sudo apt install apache2 mariadb-server -y

  • We need to let apache2 through our firewall for now on port 80
  • 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.

  • After installing apache2 and mariadb we need to enable and strart them.
  • sudo systemctl enable apache2

    sudo systemctl start apache2

    sudo systemctl enable mysql

    sudo systemctl start mysql

  • Run the mysql_secure_installation script and follow the instructions
  • sudo mysql_secure_installation

  • Now we will install php.
  • sudo apt install php libapache2-mod-php php-mysql -y

  • Now that PHP is installed lets create the document root of our web server, and give the directory the right permissions.
  • sudo mkdir /var/www/"my_domain_name.com"

    sudo chmod -R 755 /var/www/"my_domain_name.com"

  • Now we will create our index.html file.
  • 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>