DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Spring Boot - How To Use Native SQL Queries | Restful Web Services
  • Develop a Spring Boot REST API in AWS: PART 4 (CodePipeline / CI/CD)
  • RESTful Web Services: How To Create a Context Path for Spring Boot Application or Web Service
  • How To Validate HTTP Post Request Body - Restful Web Services With Spring Framework | Spring Boot

Trending

  • The Role of Retrieval Augmented Generation (RAG) in Development of AI-Infused Enterprise Applications
  • Ensuring Configuration Consistency Across Global Data Centers
  • Grafana Loki Fundamentals and Architecture
  • Java's Quiet Revolution: Thriving in the Serverless Kubernetes Era
  1. DZone
  2. Coding
  3. Frameworks
  4. Hosting Multiple Applications on the Same Server

Hosting Multiple Applications on the Same Server

These days, many developers work on a project on the same server at the same time — but we still need to be able to schedule app updates the server whenever we want to.

By 
Thilina Ranathunga user avatar
Thilina Ranathunga
·
Feb. 21, 17 · Tutorial
Likes (6)
Comment
Save
Tweet
Share
31.8K Views

Join the DZone community and get the full member experience.

Join For Free

In this guide, we will talk about how to host multiple applications built on various backend technologies such as Java, PHP, and nodes on the same Ubuntu server, along with APIs and clients running under multiple domains or sub-domains on the same server.

Most modern developers use collaboration servers like GitHub. With multiple developers working on the same app, what if we could schedule the build and automate updates of the app installed on the server we are configuring whenever we want? With Maven, you build your apps from the updated source cloned from your Git repository. And we can schedule and automate those builds and executions with the support of cron (crontab/cron jobs).

As Apache is running on port 80, we can easily point our domains to apps running on it. If you have some other apps running on different ports, you can use Apache's virtual host configuration to map those apps under different ports to domains or subdomains and omit the ugly port numbers. This means that you can use domains without mentioning port numbers to point several apps installed on same saver computer and running under different application servers such as Apache, Tomcat, node, etc.

When you install the SSH server and enable access, you can control it all from anywhere via the internet — even from your mobile phone or tablet.

It doesn't matter whether you are going to use the same general internet connection that you use for other internet needs. You just have to do some port forwarding configurations to direct all requests on port 80 to the server that we are configuring. If you need the server's SSH to be accessible via the internet, you have to forward port 22, as well — but you should map it to another port number, just to be safe.

There is a risk of going all of it offline if something happens to your internet connection. To prevent that, we can have multiple internet connections from different ISPs (also in different technologies such as fiber optics, WiMAX, and maybe old ADSL) and use a load balance router to mix them up.

We all need backup, mostly in different locations. For that, we can schedule a local backup and upload it via FTP to another server. Also, we can permanently mount a folder shared in a local network on a Windows computer and schedule synchronization of the backup files with that Windows shared folder.

If we use MySQL as our DBMS, we can use phpMyAdmin to manage it via the web. You can configure a subdomain to point to your phpMyAdmin instance.

You can do the same thing and install multiple WordPress sites and configure to work on multiple domains. By that, you can host many websites on your own server.

By installing an FTP server, you can manage files on your server.

Spring Boot apps can be launched by just executing the JAR file as it has an embed server within the jar, but what if you have multiple spring boot app? You may need to set different ports in configurations to run all together on different ports; it looks like a waste of resources. If we use separate Tomcat server, we can deploy them all in that one Tomcat. We can schedule the deployment of apps as we update things via Git.

You may need to see Tomcat logs occasionally. If you create hard links to that log file from within the Tomcat container, you can read them via your browser.

I'd like to share my list of commands and templates with you so that if you are interested, you can give it a try.

You can find many articles about Ubuntu as well as basic installation guides on the internet — so I am not going to explain it all in detail here. 

Look at the BIOS configuration of your computer to confirm if the auto start on power failure feature is turned on.

In the Ubuntu installation wizard, you should have selected LAMP and Open SSH. If you haven't, don't worry; we can install them manually.

Install open SSH server:

sudo apt install openssh-server

See the status of SSH server:

sudo service ssh status

Now you, should be able to connect it via the network.

To install MySQL server:

sudo apt install mysql-server

To install Java:

sudo apt install default-jdk

To install Maven:

sudo apt install maven

To install Git:

sudo apt install git

Clone Git repositories (replace URLs with repos that you need to clone):

mkdir git
cd git
git clone https://github.com/GIT_USER/REPO_ONE.git
git clone https://github.com/GIT_USER/REPO_TWO.git

Install and enable Apache 2:

sudo apt install apache2
enable  apache2

Install phpMyAdmin:

sudo apt install phpmyadmin

Create a folder for hosting the site (replace SITE_NAME with your actual site name).

cd /var/www
sudo mkdir SITE_NAME

Let's assume that you need the site to be a cloned Git repo.

Add a link to the cloned repo folder as your site's public_html folder (replace UBUNTU_USERNAME, CLONED_REPO_FOLDER, and SITE_NAME to match yours).

sudo ln -s /home/UBUNTU_USERNAME/git/CLONED_REPO_FOLDER/var/www/SITE_NAME/public_html

Create and edit virtual host file to manage requests to your site (replace SITE_NAME). 

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/SITE_NAME.conf
sudo nano /etc/apache2/sites-available/SITE_NAME.conf

Enable the site, then disable the default site. Reload Apache 2 to make the change effective.

sudo a2ensite SITE_NAME.conf
sudo a2dissite 000-default.conf
sudo service apache2 reload

At the moment inside one of my servers I have a spring based API app running inside tomcat and an angular based REST client app running inside apache. My virtual host file for this looks like below. (Real domains replaced with "yourdomain.com" evetrything else remains unchanged)

<VirtualHost *:*>
        ProxyPreserveHost On
        ServerAdmin r.thilina@gmail.com
        ServerName yourdomain.com
        ServerAlias app.yourdomain.com
        DocumentRoot /var/www/app.yourdomain.com/public_html
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

<VirtualHost *:*>
    ProxyPreserveHost On
    ServerAdmin r.thilina@gmail.com
    ServerName yourdomain.com
    ServerAlias api.yourdomain.com
    # setup the proxy
    <Proxy *>
        Order allow,deny
        Allow from all
    </Proxy>
    ProxyPass / http://localhost:8080/your-api/
    ProxyPassReverse / http://localhost:8080/your-api /
</VirtualHost>


Now, let's assume that you need to update the site's files from Git. Change the directory to the repository folder then Pull the changes from Git.

cd ~/git/REPO_NAME
git pull


There are more things to come! I will update this continuously and add more as time goes on.

If you feel this helps you in any way, please like and share this article. You can find me on LinkedIn (and I really love it when you upvote my skills there!).

I am happy to help you if you are going to practice these things. Also, please give feedback and suggestions. I will improve this article with your support.

mobile app Spring Framework Host (Unix) Git Internet (web browser) Spring Boot Apache Tomcat Schedule (computer science) Mobile phone Web Protocols

Opinions expressed by DZone contributors are their own.

Related

  • Spring Boot - How To Use Native SQL Queries | Restful Web Services
  • Develop a Spring Boot REST API in AWS: PART 4 (CodePipeline / CI/CD)
  • RESTful Web Services: How To Create a Context Path for Spring Boot Application or Web Service
  • How To Validate HTTP Post Request Body - Restful Web Services With Spring Framework | Spring Boot

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!