Hello,
I am very new to deployment. I have been a learning developer for the last 3 months and I am ready to deploy my first project.
It is a simple web app which uses node.js and php. However I am not sure how I should set it app up. I have a few concerns:
Which Linux distro should I use - for now I am going for Ubuntu since it seems the most popular ?
When I get a droplet in Digital Ocean should it be partitioned somehow or should I install node.js with pm2 and apache all on the same machine ?
When sending the files to the served should the PHP part be kept separate from the JS part of the application ? Or should I deploy the whole project in one directory ?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hi @kkrumov
I prefer to use Ubuntu server for my projects so you can use it too, it is popular and has enough documentation and guides to work with it.
You can install pm2 and apache on the same droplets, that is okay.
NodeJS and PHP are both for backend you are using them both? How is your project structed in Development if they are together then you can keep them together on the server.
Hope this helps
Ubuntu is a great choice, especially for beginners. It’s widely used, has excellent documentation, and most cloud providers (like DigitalOcean) have plenty of tutorials and support for Ubuntu. I recommend Ubuntu 22.04 LTS, as it’s stable and has long-term support.
For a simple web app, partitioning isn’t necessary, especially when you’re starting out. You can install both Node.js (with PM2) and Apache on the same machine. This setup will work fine for smaller projects.
However, if your project grows in complexity later, you might consider separating different services (Node.js, PHP, databases) across multiple droplets or using containers like Docker. For now, keeping everything on one server is perfectly fine.
There are two ways you can organize the PHP and Node.js parts of your application:
You can structure your project so that PHP and Node.js live in separate directories:
/var/www/html/php-app)./var/www/node-app).You would then configure Apache as a reverse proxy to serve both PHP and Node.js. Requests to /php would be handled by Apache, and requests to /node or the API would be forwarded to the Node.js server.
Alternatively, you could deploy both parts of the project in the same directory if they’re tightly integrated. For example, you might have the following structure:
/var/www/my-project
├── public/ # Public files (JS, CSS, HTML)
├── php/ # PHP scripts
└── node/ # Node.js app
In this setup, you would still use Apache to serve the PHP files, and Node.js would handle its own routes. Apache could also act as a reverse proxy to forward requests to the Node.js part if needed.
Here’s a simplified deployment approach for your use case:
Create a DigitalOcean Droplet with Ubuntu 24.04 LTS.
Update your droplet, install Apache, Nodejs and PM2:
sudo apt update && sudo apt upgrade -y
sudo apt install apache2 -y
sudo apt install php libapache2-mod-php -y
sudo apt install php libapache2-mod-php -y
curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt install -y nodejs
sudo npm install pm2@latest -g
/etc/apache2/sites-available/000-default.conf), add the following lines to proxy requests to Node.js:<VirtualHost *:80>
ServerName yourdomain.com
# Proxy requests to Node.js
ProxyPass /node http://127.0.0.1:3000/
ProxyPassReverse /node http://127.0.0.1:3000/
# PHP settings
DocumentRoot /var/www/html/php-app
<Directory /var/www/html/php-app>
AllowOverride All
</Directory>
</VirtualHost>
Enable the necessary modules:
sudo a2enmod proxy proxy_http
sudo systemctl restart apache2
/var/www/html/php-app/.pm2 start /var/www/node-app/app.js
sudo apt install certbot python3-certbot-apache -y
sudo certbot --apache
Once done, you’ll have a setup where PHP and Node.js run together on the same server and domain. Requests can be routed appropriately between Apache and Node.js.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.