Step by Step - Creating Web Server - Digital Ocean Ubuntu - LAMP

Installing web server with apache, php and mysql step by step in Digital Ocean Environment.

Jan 2, 2023 - 16:12
Jan 2, 2023 - 16:27
Step by Step - Creating Web Server - Digital Ocean Ubuntu - LAMP
LAMP

CREATING WEBSERVER IN DIGITAL OCEAN

(APACHE - PHP - MYSQL - phpmyadmin)

*** Log in to your digital ocean account and select "+New Project" from left panel.

https://cloud.digitalocean.com/projects/new

Step 1 - Enter project details and click "Create Project".

Step 2 - Select "Get Started with a Droplet" from project screen.

Step 3 - It is really easy to try one click deployments from Digital Ocean. Go to "Marketplace" and Select "LAMP on Ubuntu 20.04"

Step 4 - Choose the plan for the project. Regular and cheapest options were selected for the project.

Step - 5 Select "Add block storage" if needed and chose datacenter region. Datacenter region selection is important for the target audience of the website.

Step 6 - Create a root password for the server and select additional options such as backups, IPv6 etc.

Step 7 - Last step. Choose a hostname and select the project for the droplet. Then click "Create Droplet"

Step 8 - The droplet will be ready in less than a minute. You may now see the IP address of the droplet and select options from right site.

Software included with the LAMP:

Package
Version License
Apache
2.4.41 Apache 2
MySQL server
8.0.30 GPL 2 with modifications
PHP
8.1.8 PHP v3.01
Fail2ban
0.11.1 GPL 2 with modifications
Postfix
3.4.10 IBM Public
Certbot
0.39.0 Apache 2

In addition to the package installation, the 1-Click also:

  • Enables the UFW firewall to allow only SSH (port 22, rate limited), HTTP (port 80), and HTTPS (port 443) access.
  • Sets the MySQL root password and runs mysql_secure_installation.
  • Sets up the debian-sys-maint user in MySQL so the system’s init scripts for MySQL will work without requiring the MySQL root user password.

After you create a LAMP One-Click Droplet:

  • You can view the LAMP instance immediately by visiting the Droplet’s IP address in your browser.
  • You can log into the Droplet as root using either the password you set when you created the Droplet or with an SSH key, if you added one during creation.
  • The MySQL root password is in /root/.digitalocean_password.
  • The web root is /var/www/html.
  • You can get information about the PHP installation by logging into the Droplet and running php -i.

Step 9 - After all access and launch the console. Welcome page provides some information about the droplet created.

Step 10 - Write "sudo apt update" and hit enter to console. Wait till installation.

Step 11 - Write "sudo apt install apache2" and hit enter to console. Wait till installation.

Step 12 - After completed. You may enter your droplet IP address to a browser and the default welcome page will appear. It means Apache 2 is ready.

Step 13 - To install mysql write "sudo apt install mysql-server" and hit enter. Wait for the installation.

Step 14 - When the installation is complete, run a simple security script that comes pre-installed with MySQL which will remove some dangerous defaults and lock down access to your database system. Start the interactive script by running: "sudo mysql_secure_installation".

After validating the password you may now write "sudo mysql" to use mysql commands. You may exit from mysql command lline by writing "exit" command.

Step 15 - Run the "sudo apt install php libapache2-mod-php php-mysql" command to install php and packacges.

PHP is the component of your setup that will process code to display dynamic content. It can run scripts, connect to your MySQL databases to get information, and hand the processed content over to your web server so that it can display the results to your visitors.

Step 16 - To change the directory index of the apache write "sudo nano /etc/apache2/mods-enabled/dir.conf" and hit enter. From the index move "index.php" to first order in order to use php as the first option.

When you are finished, save and close the file by pressing CTRL+X. Confirm the save by typing Y and then hit ENTER to verify the file save location.

After this, restart the Apache web server in order for your changes to be recognized. You can do that by using "sudo systemctl restart apache2" command.

Step 17 - Apache on Ubuntu has one server block enabled by default that is configured to serve documents from the /var/www/html directory. While this works well for a single site, it can become unwieldy if you are hosting multiple sites. Instead of modifying /var/www/html, let’s create a directory structure within /var/www for your_domain site, leaving /var/www/html in place as the default directory to be served if a client request doesn’t match any other sites. After that you may enter following commands:

**** sudo chown -R $USER:$USER /var/www/your_domain

**** sudo chmod -R 755 /var/www/your_domain

**** nano /var/www/your_domain/index.html

Step 18 - After running last command. You will be able to edit you "index.html". When you are finished, save and close the file by pressing CTRL+X. Confirm the save by typing Y and then hit ENTER to verify the file save location.

Step 19 - Enter and hit "sudo nano /etc/apache2/sites-available/your_domain.conf" command to edit the conf file for the virtual directory. When you are finished, save and close the file by pressing CTRL+X. Confirm the save by typing Y and then hit ENTER to verify the file save location.