How to Deploy Rails application in ubuntu using Apache & passenger
1. Install the apache type the below command
$ sudo sudo apt-get install apache2
2. Install passenger
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 561F9B9CAC40B2F7
3. Create an APT source file:
$ sudo nano /etc/apt/sources.list.d/passenger.list
insert this line inside passenger.list file
deb https://oss-binaries.phusionpassenger.com/apt/passenger trusty main
save and exit after inserting the above line.
4. Change the owner and permissions for this file to restrict access to root:
$ sudo chown root: /etc/apt/sources.list.d/passenger.list
$ sudo chmod 600 /etc/apt/sources.list.d/passenger.list
5. Update the APT
$ sudo apt-get update
6. While updating if you face any issues. Kindly do the below things
$ sudo rm -r /var/lib/apt/lists/*
$ sudo apt-get clean
$ sudo apt-get update
7. Install the passenger
$ sudo apt-get install libapache2-mod-passenger
8. Enable and restart the server
$ sudo a2enmod passenger
$ sudo service apache2 restart
9. After creating or pulling your application, Now we need to create a virtual host file for our project. We'll do this by copying the default Apache virtual host:
$ sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/serversetup.conf
10. Now open etc/apache2/sites-available/serversetup.conf file change the below things
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
ServerAdmin webmaster@localhost
DocumentRoot /home/rajkumar/Rajkumar/Projects/serversetup/public
RailsEnv production
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "/home/rajkumar/Rajkumar/Projects/serversetup/public">
Options FollowSymLinks
Require all granted
</Directory>
</VirtualHost>
11. Disable the default site and enable new app.
$ sudo a2dissite 000-default
$ sudo service apache2 reload
$ sudo a2ensite serversetup
$ sudo service apache2 restart
12. Now you check your ip address. Your application will work. Dont forget to do clean & precompile the app.