Hi, So I’ve had a webserver with Ubuntu and Apache on the LAMP stack for about a year. It’s mainly just a portfolio website.
I’ve just made an API using Ruby on Rails that is on my local machine and I’ve read up that you can host multiple different applications on the same droplet.
The idea is to make a subdomain such as www.api.Example.com My existing website I have is www.Example.com With this subdomain I wish to host my Ruby on Rails API, it uses PHP myadmin which I think I’ll have to install on the LAMP stack? And it also has gems to install such as mysql2.
My question is how do I do this?
I’ve looked at so many tutorials but they’re all saying a different thing and mentioning Nginx and I don’t know how to get a subdomain. I bought my domain from Google so do I do it on Google Domains or do I do it on Digital Ocean?
So altogether I’m asking how to… Make a subdomain such as www.api.Example.com? Do I install PHPmyadmin on the main Apache bit and will it be on both my subdomain and main domain? Is it possible to have a Ruby On Rails app and an existing Apache web server working concurrently? How do I move my API from my PC over? Is it simply a case of copying over files? (To the Sites folder I’m guessing?) How would I start it? (The usual rails s? or is it slightly different cause of the sub domain? MySQL is already installed through the LAMP stack so I can just forget about it right?
Is that everything? It’s been a good 7 months since I actually went on my server terminal so I’m probs a bit rusty with the commands.
Thanks in advance, I know I’m pretty bad at explaining myself but I think I did an alright job
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!
Hello,
Yes, all the above is possible, you can run Ruby on Rails onto an existing Apache server and you don’t need Nginx server. Here’s a guide on how to set that all up:
Before you start with the guide you can point your subdomain name to your Droplet’s IP address. If you are using Google’s namesevers you need to do that via your Google account, if you are using DigitalOcean’s nameservers you need to make this DNS change via your Digital Ocean domain control panel.
Also before you proceed with the rails setup make sure to backup your droplet, in case that anything goes wrong, you can simply revert to that backup.
Regarding the PHPmyAdmin installation you can follow the steps here on how to install PHPmyAdmin manually with an existing Apache server, start from step Step 3:
Hope that this helps! Let me know if you need any help!
Hosting multiple applications on a single DigitalOcean droplet, including setting up a Ruby on Rails API alongside an existing Apache web server, involves several steps. You’ve outlined a good series of questions, so let’s tackle them one by one.
The subdomain www.api.example.com should be set up through your DNS provider, which in your case is Google Domains since that’s where you bought your domain.
www.api if you want it to be www.api.example.com.Since you already have Apache installed, you can continue to use it, or you can opt to install Nginx, which is often favored for Ruby on Rails applications due to its capability to handle concurrent connections more efficiently. However, for simplicity, you can stick with Apache.
Edit Apache configuration files typically located in /etc/apache2/sites-available/.
You can copy the existing site configuration file and modify it for your API.
Example snippet for your virtual host:
<VirtualHost *:80>
ServerName www.api.example.com
DocumentRoot /var/www/api/public
<Directory /var/www/api/public>
Allow from all
Options -MultiViews
Require all granted
</Directory>
</VirtualHost>
a2ensite www.api.example.com.conf and reload Apache service apache2 reload.database.yml is configured to use it. Since MySQL is part of your LAMP stack, you can use the same MySQL server, but you might consider creating a separate database for your API./var/www/api.rails assets:precompilerails db:migrate RAILS_ENV=productionInstead of using rails s, which is typically for development, you should set up a proper application server such as Puma or Passenger which can be integrated into Apache.
sudo apt-get install libapache2-mod-passengersudo a2enmod passengerYou can install PHPMyAdmin on the Apache server, and it will be accessible from any domain hosted on that server, provided you configure it securely. It can be accessed via a URL like example.com/phpmyadmin or api.example.com/phpmyadmin.
By following these steps, you should be able to successfully deploy your Ruby on Rails API on your existing server without affecting your current Apache setup for your portfolio website.
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.