Here’s a step-by-step guide to set up your domain with subdomains using GoDaddy and DigitalOcean:
Sign up for DigitalOcean at https://www.digitalocean.com.
Complete the registration process and verify your account using the payment method.
Log in to your DigitalOcean dashboard.
Click on the "Create" button and select "Droplets".
Choose an image for the server:
Select Ubuntu 22.04 (or the latest stable version).
Choose the plan (Basic/Standard is usually sufficient).
Select the data center region closest to your audience.
Add SSH keys (or choose a password-based login if no SSH key is available).
Assign a hostname (e.g., example-droplet
).
Click "Create Droplet".
Go to the "Networking" section in the DigitalOcean dashboard.
Click on "Domains" and add your domain (example.com
).
DigitalOcean will provide nameservers:
Log in to your GoDaddy account.
Navigate to "My Products" and find your domain (example.com
).
Click "DNS" next to the domain.
Under Nameservers, click Change.
Choose Custom Nameservers and add:
Save changes (it may take up to 48 hours for the DNS propagation, though usually faster).
Go to Networking -> Domains in the DigitalOcean dashboard.
Select your domain (example.com
).
Add CNAME records for the subdomains:
Subdomain 1 (e.g., api.example.com
):
Type: CNAME
Name: api
Hostname: example.com
(or the droplet's IP if using A records).
Will be use for host the laravel application which will serve api
Subdomain 2 (e.g., phpmyadmin.example.com
):
Type: CNAME
Name: phpmyadmin
Hostname: example.com
.
Will use for phpmyadmin installations path.
Subdomain 3 (e.g., adminpanel.example.com
):
Type: CNAME
Name: adminpanel
Hostname: example.com
.
Will be use for host the react application which is required for adminpanel frontend
Save each record.
Use a tool like https://dnschecker.org to confirm DNS propagation.
If the subdomains don't resolve, ensure the CNAME records are correct and the nameservers are pointing to DigitalOcean.
Here's a comprehensive guide for setting up your server on DigitalOcean with Nginx for hosting the specified applications and subdomains:
sudo apt update
sudo apt install -y curl wget unzip git build-essential ufw software-properties-common
sudo apt install -y nginx
sudo systemctl enable nginx sudo systemctl start nginx
sudo ufw allow OpenSSH sudo ufw allow 'Nginx Full' sudo ufw enable
Step for running Laravel app which will required for API of this application:
Here's a step-by-step guide to set up and run a Laravel application for the API, assuming it will be hosted on api.example.com
with PHP 8.1:
Update your package list and install required dependencies:
sudo apt update && sudo apt upgrade -y sudo apt install -y nginx php8.1 php8.1-fpm php8.1-mbstring php8.1-xml php8.1-bcmath php8.1-curl php8.1-zip php8.1-mysql unzip curl mysql-client composer
Verify PHP version:
php -v
sudo apt install -y mysql-server
sudo mysql_secure_installation
Here’s how to create a MySQL user named admin
with the password 123456123Password
and grant it full access to all databases:
Log in to MySQL as the root user:
sudo mysql -u root -p
Create the admin
user with the specified password:
CREATE USER 'admin'@'%' IDENTIFIED BY '123456123Password';
Grant full access to all databases:
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' WITH GRANT OPTION;
Apply the changes:
FLUSH PRIVILEGES;
Exit MySQL:
EXIT;
To test the admin
user's access:
Log in as the admin
user:
mysql -u admin -p
Enter the password (123456123Password
) when prompted.
Check access by listing the databases:
SHOW DATABASES;
Ensure the password is stored securely and not shared publicly.
Restrict access to specific IPs if needed by modifying the %
wildcard in the CREATE USER
command:
CREATE USER 'admin'@'localhost' IDENTIFIED BY '123456123Password';
Let me know if you need further assistance!
Navigate to your project directory:
cd /var/www/
Download or clone your Laravel project:
git clone https://github.com/your-repo/laravel-api.git cd laravel-api
Here’s how to set up Composer and use it to install dependencies for a Laravel application:
Step 1: Install Composer
Download the Composer Installer:
curl -sS https://getcomposer.org/installer | php
Move Composer to a Global Location:
sudo mv composer.phar /usr/local/bin/composer
Verify Installation:
composer --version
Step 2: Install Dependencies
Navigate to the Laravel project directory:
cd /path/to/your/laravel-project
Run the composer install
command to install dependencies:
composer update
Ensure permissions are set correctly for the vendor
and storage
directories:
sudo chown -R $USER:$USER /path/to/your/laravel-project sudo chmod -R 775 storage bootstrap/cache
Step 3: Common Composer Commands
Update Dependencies:
composer update
Check Dependencies for Issues:
composer check-platform-reqs
Clear Composer Cache:
composer clear-cache
Set permissions for storage and cache:
sudo chown -R www-data:www-data /var/www/laravel-api sudo chmod -R 775 /var/www/laravel-api/storage /var/www/laravel-api/bootstrap/cache
Set up the .env
file:
Copy the .env
file:
cp .env.example .env E
it .env
with your database credentials:
DB_CONNECTION=mysql DB_ OST=127.0.0.1 DB_PO T=3306 DB_DATA ASE=laravel_api DB_USERNA E=laravel_user DB_PASSWORD secure_password
Step 4: Con
api.example.com
Create a new Nginx configuration file:
sudo nano /etc/nginx/sites-available/api.example.com
Add the following configuration:
server { listen 80; server_name api.example.com; root /var/www/laravel-api/public; index index.php index.html; location / { try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php8.1-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location ~ /\.ht { deny all; } error_log /var/log/nginx/api.example.com-error.log; access_log /var/log/nginx/api.example.com-access.log; }
Enable the site:
sudo ln -s /etc/nginx/sites-available/api.example.com /etc/nginx/sites-enabled/
Test Nginx configuration:
sudo nginx -t
Reload Nginx:
sudo systemctl reload nginx
Install Certbot for Nginx:
sudo apt install -y certbot python3-certbot-nginx
Obtain and apply the SSL certificate:
sudo certbot --nginx -d api.example.com
Test automatic renewal:
sudo certbot renew --dry-run
Ensure the PHP-FPM service is running:
sudo systemctl start php8.1-fpm sudo systemctl enable php8.1-fpm
Open http://api.example.com
or https://api.example.com
in your browser to confirm the API is running.
Check Laravel logs for errors:
tail -f /var/www/laravel-api/storage/logs/laravel.log
Let me know if you need assistance with any of these steps!
Step for running Next.js app which is Frontned of this application:
Here's how to configure Nginx separately for the Next.js application hosted on example.com
and set up the root path /var/www/projectNameFolder
. We'll also configure Node.js with nvm to use the highest Node.js version available.
Install nvm:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash source ~/.bashrc
Verify nvm installation:
command -v nvm
Install the latest Node.js version:
nvm install node
Use the highest version:
nvm use node
Verify the installed version:
node -v npm -v
Create the project directory:
sudo mkdir -p /var/www/projectNameFolder sudo chown -R $USER:$USER /var/www/projectNameFolder
Navigate to the directory and initialize a Next.js application:
cd /var/www/projectNameFolder
example.com
Create a new Nginx configuration file:
sudo nano /etc/nginx/sites-available/example.com
Add the following configuration:
server { listen 80; server_name example.com www.example.com; root /var/www/projectName; index index.html; location / { proxy_pass http://127.0.0.1:3001; # Default Next.js port proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } error_page 404 /404.html; }
Enable the configuration:
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
Test the Nginx configuration:
sudo nginx -t
Reload Nginx:
sudo systemctl reload nginx
(Optional) If you'd like to secure your site with SSL:
Install Certbot:
sudo apt install -y certbot python3-certbot-nginx
Obtain and apply an SSL certificate:
sudo certbot --nginx -d example.com -d www.example.com
Verify automatic renewal:
sudo certbot renew --dry-run
Start the Next.js app with PM2:
Go to project folder and run this command one by one:
npm install -g pm2 pm2 start npm --name "projectNameFolder" -- start pm2 save
Visit http://example.com
to ensure the application is running.
Check https://example.com
if SSL is applied.
Here's a step-by-step guide to set up your React Admin Panel at adminpanel.example.com
.
This setup assumes you're cloning the React app from a GitHub repository, running npm install
, building the project with npm run build
, and serving it with Nginx.
Update your server and install dependencies:
sudo apt update && sudo apt upgrade -y sudo apt install -y nginx git curl build-essential
Install Node.js: Use nvm
(Node Version Manager) to install the latest stable version of Node.js:
curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash - sudo apt install -y nodejs
Check Node.js and npm versions:
node -v npm -v
Navigate to the directory where you want to store the React app:
cd /var/www/
Clone your React admin panel repository:
git clone https://github.com/your-repo/react-admin-panel.git cd react-admin-panel
Install the required npm packages:
npm install
Build the React project for production:
npm run build
Confirm the build
directory is created inside the project:
ls build
Create a new Nginx configuration file for adminpanel.example.com
:
sudo nano /etc/nginx/sites-available/adminpanel.example.com
Add the following configuration:
server { listen 80; server_name adminpanel.example.com; root /var/www/react-admin-panel/build; index index.html index.htm; location / { try_files $uri $uri/ /index.html; } error_log /var/log/nginx/adminpanel.example.com-error.log; access_log /var/log/nginx/adminpanel.example.com-access.log; }
Create a symlink to enable the site:
sudo ln -s /etc/nginx/sites-available/adminpanel.example.com /etc/nginx/sites-enabled/
Test the Nginx configuration for syntax errors:
sudo nginx -t
Reload Nginx to apply the changes:
sudo systemctl reload nginx
Obtain an SSL certificate:
sudo certbot --nginx -d adminpanel.example.com
Test SSL Renewal:
sudo certbot renew --dry-run
Open http://adminpanel.example.com
or https://adminpanel.example.com
in your browser to verify the React admin panel is running correctly.
Check the Nginx error logs if you face issues:
tail -f /var/log/nginx/adminpanel.example.com-error.log
To serve the app using a custom domain with Nginx: Make sure the domain adminpanel.example.com
is correctly configured on your DNS provider (GoDaddy or others) by pointing the A record to your server’s IP address.
To set up Nginx caching (optional): You can enable caching for the static assets in the React app:
location ~* \.(jpg|jpeg|png|gif|ico|css|js|woff|woff2|ttf|eot)$ { expires 30d; access_log off; }
If you face issues, check these:
Nginx logs:
tail -f /var/log/nginx/adminpanel.example.com-error.log
React build output errors: If the React build fails, try running npm run build
again and check for errors in the terminal.
React app not loading correctly: Make sure you have the correct build path and that Nginx is correctly pointing to /build
in the project.