By UrielJrz1328
Hello, I developed an application with Angular, node and mysql and I would like your support on how to upload it to production on an Apache server.
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!
Heya,
Deploying an Angular, Node.js and MySQL application involves several steps, as these technologies each need specific configurations. Here’s a general guide:
Angular: Build your Angular app for Production
You’ll need to compile your Angular application to static HTML, CSS, and JavaScript files using the Angular CLI’s build command. Navigate to the root of your Angular project and run:
ng build --prod
This will create a dist/ folder in your project which contains the compiled assets of your application.
Node.js: Setting up the server
Apache doesn’t natively support Node.js applications. However, it can be configured as a reverse proxy to forward requests to a Node.js server. Alternatively, you can use a process manager like PM2 to manage your Node.js process. If you don’t already have PM2, you can install it globally using npm:
npm install -g pm2
Once you have PM2, navigate to your Node.js project and start your application:
pm2 start server.js
- Replace `server.js` with the name of your main Node.js file.
Apache: Configuring the Reverse Proxy
You need to enable mod_proxy and mod_proxy_http for the reverse proxy to work. If you haven’t already done this, you can do it using:
sudo a2enmod proxy
sudo a2enmod proxy_http
Then, you will need to edit your Apache configuration file to set up a reverse proxy. Your configuration file will likely be located at /etc/apache2/sites-available/000-default.conf. Open this file in a text editor:
sudo nano /etc/apache2/sites-available/000-default.conf
Then, add the following lines within the <VirtualHost *:80> block, replacing localhost:3000 with your Node.js server’s address and port:
ProxyRequests Off
ProxyPass /api http://localhost:3000
ProxyPassReverse /api http://localhost:3000
This configuration tells Apache to forward all requests at /api to your Node.js server.
Save and close the file, then restart Apache to apply these changes:
sudo systemctl restart apache2
Deploy Angular Application
Now, take the dist/ folder that was generated by Angular CLI and move it to Apache’s web folder, usually at /var/www/html. Make sure to replace your-angular-app with your actual app’s name:
sudo cp -r dist/your-angular-app/* /var/www/html
Now, Apache should serve your Angular app at the root domain and proxy any /api requests to your Node.js server.
Remember, this is a high-level overview and actual steps may vary based on your specific setup and requirements. Always be sure to secure your applications properly when deploying them, which includes using HTTPS, protecting sensitive data, and properly managing your servers.
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.