Here's a concise blog post based on the provided code for setting up a Digital Ocean droplet:
Setting up a Digital Ocean droplet can be a great way to host your web applications. Here's a quick guide to get you started:
First, create a sudo user:
adduser username
usermod -aG sudo username
Generate an SSH key pair for secure access:
ssh-keygen -t ecdsa -b 521
Install PHP 8.3 and necessary extensions:
sudo apt update
sudo add-apt-repository ppa:ondrej/php
sudo apt install php8.3-cli php8.3-common php8.3-bcmath php8.3-mbstring php8.3-xml php8.3-curl php8.3-gd php8.3-zip php8.3-mysql
Verify installation:
php8.3 -m
sudo apt install composer
Install and secure MySQL:
sudo apt install mysql-server
sudo mysql_secure_installation
Create a database and user:
CREATE DATABASE yourdatabase;
CREATE USER 'your-username'@'localhost' IDENTIFIED BY 'your-password';
GRANT ALL PRIVILEGES ON yourdatabase.* TO 'your-username'@'localhost';
FLUSH PRIVILEGES;
Install NVM and Node.js:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
nvm install --lts
Set proper ownership and permissions:
sudo chown -R $USER:www-data .
sudo find . -type f -exec chmod 664 {} \;
sudo find . -type d -exec chmod 775 {} \;
sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache
Install Certbot and obtain an SSL certificate:
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d yourdomain.com
Add this to your SSH config file to keep the ssh-agent active:
User git
Hostname github.com
IdentityFile ~/.ssh/id_github
TCPKeepAlive yes
IdentitiesOnly yes
ServerAliveInterval 60
By following these steps, you'll have a well-configured Digital Ocean droplet ready for your web applications. Remember to adjust usernames, passwords, and domain names as needed.