Getting Started in Digital Ocean is a great way to launch a new web server quickly and easily. In this blog post, we will walk through the process of creating a new droplet and setting up Nginx on it.
To create a droplet on DigitalOcean, you will need to sign up for an account if you don't already have one.
If you don't already have a DigitalOcean account, you can sign up for one at https://www.digitalocean.com. Once you have signed up and logged in, you will be taken to the DigitalOcean dashboard.
From the dashboard, click on the "Create" button, and then select "Droplets" from the menu. You will then be prompted to select a droplet configuration. For this tutorial, we will be using Ubuntu as the operating system. You can also select the size of your droplet based on your needs.
Next, you will need to select a datacenter region for your droplet. This is the location where your droplet will be physically located. Choose the region that is closest to your target audience for best performance.
Before you can create your droplet, you will need to add an SSH key. This will allow you to securely connect to your droplet once it's created. If you don't already have an SSH key, you can create a new one by clicking on the "New SSH Key" button.
Once you have completed all of the previous steps, you can click on the "Create" button to launch your droplet. It will take a few minutes for the droplet to be created and set up.
Make sure that your system is up-to-date by running the following commands:
sudo apt update sudo apt upgrade
Next, we'll install Nginx using the apt package manager:
sudo apt install nginx
Now insert nginx into firewall
sudo ufw allow 'Nginx HTTP'
By default, Nginx listens on port 80, and now put port 80 for http and port 443 for https into firewall
sudo ufw allow 443/tcp sudo ufw allow 80/tcp
(optional) And if you want control your server with ssh, don't forget put 'OpenSSH' to firewall to
sudo ufw allow 'OpenSSH'
Verified the changes by:
sudo ufw status
The output:
Output Status: active To Action From -- ------ ---- OpenSSH ALLOW Anywhere Nginx HTTP ALLOW Anywhere OpenSSH (v6) ALLOW Anywhere (v6) Nginx HTTP (v6) ALLOW Anywhere (v6)
Enable the firewall to complete the process (if the firewall have enabled it won't be affect anything)
sudo ufw enable
(optional) Install the curl if need it
sudo apt-get install curl
After the installation is complete, you can check the status of the Nginx service by running:
systemctl status nginx
The output should indicate that the service is running:
nginx.service - A high performance web server and a reverse proxy server Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset:> Active: active (running) since Sun 2023-01-08 02:51:48 UTC; 3 days ago Docs: man:nginx(8) Main PID: 2504 (nginx) Tasks: 2 (limit: 1131) Memory: 5.5M CGroup: /system.slice/nginx.service ├─2504 nginx: master process /usr/sbin/nginx -g daemon on; master_> └─2507 nginx: worker process
To test that Nginx is working properly, open a web browser and navigate to http://localhost or your server ip address. You should see the Nginx default welcome page, which confirms that the web server is up and running.
If you want to change the default page just go to this directory:
/var/www/html
You can remove the default file inside html folder and create a new file or put your website file to this directory and navigate to it in your web browser to see it displayed.
Nginx is now installed and running on your Ubuntu system. You can now proceed to configure and customize it to suit your needs.
1.Install MySQL
To install MySQL, run the following command:
sudo apt-get install mysql-server
During the installation process, you will be prompted to set a root password for the MySQL server. Make sure to choose a strong and secure password.
2.Verify the installation
To verify that the installation was successful, check the MySQL service status by running the following command:
sudo systemctl status mysql
You should see an output indicating that the service is active and running.
3.Secure the Installation
MySQL provides a script called mysql_secure_installation that can be used to improve the security of your MySQL installation. To run the script, enter the following command:
sudo mysql_secure_installation
You will be prompted to answer several questions about how to secure your MySQL installation. It is recommended to answer yes to all questions.
OUTPUT: Securing the MySQL server deployment. Connecting to MySQL using a blank password. VALIDATE PASSWORD COMPONENT can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD component? Press y|Y for Yes, any other key for No: Y There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG:
After choosing validation policy, the next prompt will be to set for mysql password, and retype the password for confirmation
OUTPUT: Please set the password for root here. New password: Re-enter new password:
4.Log in to MySQL
Once the installation is complete, you can log in to the MySQL server by running the following command:
sudo mysql -u root -p
Enter the root password that you set during the installation process when prompted.
Congratulations, you have successfully installed MySQL on your Ubuntu system! You can now use MySQL to create and manage databases.
And that's it! Your droplet is now up and running with Nginx installed and configured. You can now upload your website files to the droplet and start serving them to your users.
In conclusion, creating a droplet on DigitalOcean is a simple process that only takes a few minutes. With this tutorial, you now know how to launch a new web server on DigitalOcean and configure Nginx to serve your website. This is a great way to quickly launch a new website or web application.