Deploy Rails application with apache2

Total Blog Views: 52

Blog Status: publish

Created By: swaz_ahmed Created at: 01-21-2025

Tags: deployment apache2 apache2 deployement rails app deploy Passenger Virtual Host Server Configuration Production Environment

To Deploy a Rails application on an Apache2 server, follow these essential steps:

1. Move to the directory where your Rails app will be hosted:

cd /var/www/

2. Clone Your Rails Application

 git clone https://github.com/yourusername/yourapp.git
 cd yourapp

3. Install Dependencies

bundle install
bundle install --deployment --without development test
 
4. Precompile Assets
for production
RAILS_ENV=production bundle exec rake assets:precompil

 for developement

bundle exec rake assets:precompil

5. Set Up Database

Run the following commands for production:

RAILS_ENV=production rails db:create
RAILS_ENV=production rails db:migrate

 Run the following commands for developement:

rails db:create rails db:migrate

6. Adjust Permissions If Needed

sudo chown -R www-data:www-data /var/www/yourap

7. Configure Apache Virtual Host

Create a new virtual host file for your app:

sudo nano /etc/apache2/sites-available/yourapp.conf

Add this configuration:

<VirtualHost *:80>
    ServerName yourdomain.com
    DocumentRoot /var/www/yourapp/public 
   <Directory /var/www/yourapp/public>
        Allow from all
        Options -MultiViews
        Require all granted
    </Directory>
     ErrorLog ${APACHE_LOG_DIR}/yourapp-error.log
     CustomLog ${APACHE_LOG_DIR}/yourapp-access.log combined
</VirtualHost>

Enable your site and restart Apache:

sudo a2ensite yourapp.conf 

8. Restart Apache
Finally, restart Apache to apply all changes:

sudo systemctl restart apache2


swaz_ahmed

I am swaz_ahmed blogger on shadbox. I am influencer,content writer,author and publisher. Feel free to ask me any question and suggestions.



Comments



Buy traffic for your website

About Shadbox

we have the “Get things executed” lifestyle at our place of work. There are not any excuses, no if’s or however’s in our dictionary. committed to navigating the ship of creativity to create cell answers, we resolve the real-lifestyles troubles of our clients and their clients. Our passion for work has won us many awards, year after 12 months.

Services

Downloads