KNOWNHOST WIKI

User Tools

Site Tools


developmental:ruby-rails-apps-cpanel

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
developmental:ruby-rails-apps-cpanel [2019/10/11 08:08]
Karson N.
developmental:ruby-rails-apps-cpanel [2020/06/16 16:10] (current)
Karson N.
Line 1: Line 1:
 ====== Installing Ruby/Rails Apps on a cPanel/CentOS 7 Server with EasyApache 4 ====== ====== Installing Ruby/Rails Apps on a cPanel/CentOS 7 Server with EasyApache 4 ======
 +----
  
-<WRAP center round info 60%>+<WRAP center round info 80%>
 This is an informational guide in which its intended use is for experienced systems administrators. This is an informational guide in which its intended use is for experienced systems administrators.
  
Line 11: Line 12:
 Let's install Rails.  Let's install Rails. 
  
 +\\
 ===== Quick Start Rails Installation Guide ===== ===== Quick Start Rails Installation Guide =====
  
Line 16: Line 18:
  
 As the user //root// via SSH (remember that KnownHost uses port 2200 by default for SSH), run the following: As the user //root// via SSH (remember that KnownHost uses port 2200 by default for SSH), run the following:
 +<code>
   yum -y install ea-ruby24-mod_passenger ea-ruby24-ruby-devel ImageMagick-devel sqlite-devel ea-apache24-mod_env ea-ruby24-rubygem-passenger ea-ruby24-rubygem-rack ea-ruby24-rubygem-rake ea-ruby24-rubygem-sqlite3   yum -y install ea-ruby24-mod_passenger ea-ruby24-ruby-devel ImageMagick-devel sqlite-devel ea-apache24-mod_env ea-ruby24-rubygem-passenger ea-ruby24-rubygem-rack ea-ruby24-rubygem-rake ea-ruby24-rubygem-sqlite3
   curl --silent --location https://rpm.nodesource.com/setup_8.x | bash -   curl --silent --location https://rpm.nodesource.com/setup_8.x | bash -
   yum -y install nodejs   yum -y install nodejs
   scl enable ea-ruby24 'gem install bundler bundle spring uglifier turbolinks rails'   scl enable ea-ruby24 'gem install bundler bundle spring uglifier turbolinks rails'
-  +</code>
  
 //**Note**:// We must install NodeJS separately above because it isn't available by default in the CentOS/cPanel yum repos.  //**Note**:// We must install NodeJS separately above because it isn't available by default in the CentOS/cPanel yum repos. 
Line 31: Line 33:
  
 Next, you will need a cPanel user to own the Rails application. If you have yet to create a cPanel account for this, you can use the following commands as the //root// user to create a new user, replacing the appropriate fields as desired (domain, user, password, etc). Then, modify the user to be permitted to have Passenger Apps. The last command creates the Passenger App via cPanel's Application Manager (be sure to edit appropriately for the app you want to create): Next, you will need a cPanel user to own the Rails application. If you have yet to create a cPanel account for this, you can use the following commands as the //root// user to create a new user, replacing the appropriate fields as desired (domain, user, password, etc). Then, modify the user to be permitted to have Passenger Apps. The last command creates the Passenger App via cPanel's Application Manager (be sure to edit appropriately for the app you want to create):
 +<code>
   whmapi1 createacct username=mycpuser domain=mycpdomain.tld hasshell=1   whmapi1 createacct username=mycpuser domain=mycpdomain.tld hasshell=1
   whmapi1 modifyacct user=mycpuser MAXPASSENGERAPPS=5   whmapi1 modifyacct user=mycpuser MAXPASSENGERAPPS=5
   uapi --user=mycpuser PassengerApps register_application name="test_blog" path="/ruby_apps/test_blog" domain="mycpdomain.tld" deployment_mode="development" enabled="1"   uapi --user=mycpuser PassengerApps register_application name="test_blog" path="/ruby_apps/test_blog" domain="mycpdomain.tld" deployment_mode="development" enabled="1"
 +</code>
  
 //**Note**//: I am using //mode="development"// because I will be creating my Rails App from scratch. You would use //mode="production"// if you were migrating an existing production Rails application.  //**Note**//: I am using //mode="development"// because I will be creating my Rails App from scratch. You would use //mode="production"// if you were migrating an existing production Rails application. 
  
 You will also need to enable compilers for the user.  You will also need to enable compilers for the user. 
 +<code>
   usermod -a -G compiler mycpuser        # replace mycpuser with your cPanel username   usermod -a -G compiler mycpuser        # replace mycpuser with your cPanel username
 +</code>
  
 The first command below is the command that you will use to change to the cPanel user, but make sure to replace //mycpuser// with your actual cPanel user that will own the Ruby Application. Run the following commands in order to create a new test application called "test_blog" in the directory ~/ruby_apps/test_blog/ (feel free to change these directories as desired, but make sure to use consistent data for the commands you issue). The first command below is the command that you will use to change to the cPanel user, but make sure to replace //mycpuser// with your actual cPanel user that will own the Ruby Application. Run the following commands in order to create a new test application called "test_blog" in the directory ~/ruby_apps/test_blog/ (feel free to change these directories as desired, but make sure to use consistent data for the commands you issue).
 +<code>
   su mycpuser   su mycpuser
   cd ~   cd ~
Line 54: Line 58:
   cd test_blog   cd test_blog
   bundle install --path vendor/bundle   bundle install --path vendor/bundle
 +</code>
  
 Note the location that we are installing the gems in the last command (vendor/bundle). We are doing this so that this works with jailed shell.  Note the location that we are installing the gems in the last command (vendor/bundle). We are doing this so that this works with jailed shell. 
Line 65: Line 70:
 </WRAP> </WRAP>
  
 +\\
 ===== A Simple Script ===== ===== A Simple Script =====
 The purpose of this script is to install all necessary software and setup a development Ruby on Rails Application for a cPanel user/account. You have the option to create a new cPanel account within this script or to use an existing cPanel user. If you choose to use an existing cPanel user, the script assumes that the domain you enter also exists already. If the domain you want to use does not yet exist, then you will need to create it in the panel //before// executing this script. If this script completes successfully, you should be able to visit the domain in the browser (provided you've set up your DNS) and load the default "Yay! You’re on Rails!" page. If an error occurs, the script *should* terminate immediately and inform you of the error, at which time, you will need to correct the error and proceed manually where the script left off with the "Quick Start" instructions above. This script has been tested with a default cPanel/CentOS 7 Knownhost server. No guarantee is given that it will continue to work with future versions of CentOS/cPanel. This script is provided only as a courtesy and without support.  The purpose of this script is to install all necessary software and setup a development Ruby on Rails Application for a cPanel user/account. You have the option to create a new cPanel account within this script or to use an existing cPanel user. If you choose to use an existing cPanel user, the script assumes that the domain you enter also exists already. If the domain you want to use does not yet exist, then you will need to create it in the panel //before// executing this script. If this script completes successfully, you should be able to visit the domain in the browser (provided you've set up your DNS) and load the default "Yay! You’re on Rails!" page. If an error occurs, the script *should* terminate immediately and inform you of the error, at which time, you will need to correct the error and proceed manually where the script left off with the "Quick Start" instructions above. This script has been tested with a default cPanel/CentOS 7 Knownhost server. No guarantee is given that it will continue to work with future versions of CentOS/cPanel. This script is provided only as a courtesy and without support. 
Line 149: Line 154:
  
 Save this script is //railsInstaller.sh//. Then, you will be able to run it as follows: Save this script is //railsInstaller.sh//. Then, you will be able to run it as follows:
 +<code>
   sh railsInstaller.sh   sh railsInstaller.sh
 +</code>
  
 If you prefer, you could save it, make it executable, and then run it as shown below: If you prefer, you could save it, make it executable, and then run it as shown below:
 +<code>
   chmod +x railsInstaller.sh   chmod +x railsInstaller.sh
   ./railsInstaller.sh   ./railsInstaller.sh
 +</code>
  
 Feel free to edit the script to suit your needs. If you get any errors with the script claiming that a user does not exist after selecting to use an existing user, though you are certain that the user does exist, you can try running the following command via SSH as root to ensure that /etc/userdomains is updated to include all cPanel users listed in /var/cpanel/users: Feel free to edit the script to suit your needs. If you get any errors with the script claiming that a user does not exist after selecting to use an existing user, though you are certain that the user does exist, you can try running the following command via SSH as root to ensure that /etc/userdomains is updated to include all cPanel users listed in /var/cpanel/users:
 +<code>
   /usr/local/cpanel/scripts/updateuserdomains   /usr/local/cpanel/scripts/updateuserdomains
 +</code>
  
 +\\
 ===== Extended Installation Instructions with Screenshots =====  ===== Extended Installation Instructions with Screenshots ===== 
  
Line 166: Line 175:
  
 First, let's log into our server as the root user via SSH (KnownHost uses SSH port 2200 by default) and install a few things via yum: First, let's log into our server as the root user via SSH (KnownHost uses SSH port 2200 by default) and install a few things via yum:
 +<code>
   yum -y install ea-ruby24-mod_passenger ea-ruby24-ruby-devel ImageMagick-devel sqlite-devel ea-apache24-mod_env ea-ruby24-rubygem-passenger ea-ruby24-rubygem-rack ea-ruby24-rubygem-rake ea-ruby24-rubygem-sqlite3   yum -y install ea-ruby24-mod_passenger ea-ruby24-ruby-devel ImageMagick-devel sqlite-devel ea-apache24-mod_env ea-ruby24-rubygem-passenger ea-ruby24-rubygem-rack ea-ruby24-rubygem-rake ea-ruby24-rubygem-sqlite3
   curl --silent --location https://rpm.nodesource.com/setup_8.x | bash -   curl --silent --location https://rpm.nodesource.com/setup_8.x | bash -
   yum install nodejs   yum install nodejs
 +</code>
  
 This will install our Ruby packages, ImageMagick, Sqlite, mod_env, mod_passenger, and  NodeJS. The last command will prompt you to confirm the packages to be installed, and then prompt you to confirm the GPG key before completing the installation (just type //y// and then //Enter// to confirm the dependencies and the GPC Key: This will install our Ruby packages, ImageMagick, Sqlite, mod_env, mod_passenger, and  NodeJS. The last command will prompt you to confirm the packages to be installed, and then prompt you to confirm the GPG key before completing the installation (just type //y// and then //Enter// to confirm the dependencies and the GPC Key:
Line 178: Line 188:
  
 Let's go ahead and install bundler.  Let's go ahead and install bundler. 
 +<code>
   scl enable ea-ruby24 'gem install bundler'   scl enable ea-ruby24 'gem install bundler'
 +</code>
  
 {{:developmental:ror-geminstall-bundler.png?nolink&900|}} {{:developmental:ror-geminstall-bundler.png?nolink&900|}}
  
 Next, let's install a few more gems we will need: Next, let's install a few more gems we will need:
 +<code>
   scl enable ea-ruby24 'gem install bundler bundle spring uglifier turbolinks rails'   scl enable ea-ruby24 'gem install bundler bundle spring uglifier turbolinks rails'
 +</code>
  
 The output is quite long, but you'll want to watch to make sure all gems install. The last of the output should look like this (note that dependencies are also installed and I also chose to install documentation, which can be excluded with --no-rdoc --no-ri  ): The output is quite long, but you'll want to watch to make sure all gems install. The last of the output should look like this (note that dependencies are also installed and I also chose to install documentation, which can be excluded with --no-rdoc --no-ri  ):
Line 192: Line 204:
  
 Create the cPanel account for use with Rails unless you already have an existing cPanel account that you will be using for your Rails application (be sure to replace the username //mycpuser// with a username you'd like to use and then the domain //mycpdomain.tld// with your domain that will run the Rails applicaton). Skip this step if you will be using an existing user, but make sure that your existing user has shell access if you plan to run rails commands via SSH while creating your application. Create the cPanel account for use with Rails unless you already have an existing cPanel account that you will be using for your Rails application (be sure to replace the username //mycpuser// with a username you'd like to use and then the domain //mycpdomain.tld// with your domain that will run the Rails applicaton). Skip this step if you will be using an existing user, but make sure that your existing user has shell access if you plan to run rails commands via SSH while creating your application.
 +<code>
   whmapi1 createacct username=mycpuser domain=mycpdomain.tld hasshell=1   whmapi1 createacct username=mycpuser domain=mycpdomain.tld hasshell=1
 +</code>
  
 //**Note**//: We gave the user shell access via the //hasshell=1// above. We need to make sure the user has shell access enabled, otherwise they will see the following error: //**Note**//: We gave the user shell access via the //hasshell=1// above. We need to make sure the user has shell access enabled, otherwise they will see the following error:
Line 200: Line 213:
  
 //**Note**//: You may want to make sure to set the default shell to jailed shell **if you are using CentOS kernel** first as a jailed shell environment increases security and makes otherwise-unavailable commands (for example, crontab and passwd) available to users. Check the shell setting with this command (jailed shell is not set by default): //**Note**//: You may want to make sure to set the default shell to jailed shell **if you are using CentOS kernel** first as a jailed shell environment increases security and makes otherwise-unavailable commands (for example, crontab and passwd) available to users. Check the shell setting with this command (jailed shell is not set by default):
 +<code>
   whmapi1 get_tweaksetting key=jaildefaultshell   whmapi1 get_tweaksetting key=jaildefaultshell
 +</code>
  
 And set it with this command if not already set: And set it with this command if not already set:
 +<code>
   whmapi1 set_tweaksetting key=jaildefaultshell value=1   whmapi1 set_tweaksetting key=jaildefaultshell value=1
 +</code>
  
 Instead, you could use WHM's Tweak Settings interface to set the default shell (WHM >> Home »Server Configuration »Tweak Settings) Instead, you could use WHM's Tweak Settings interface to set the default shell (WHM >> Home »Server Configuration »Tweak Settings)
Line 214: Line 229:
  
 Allow the account to have Passenger Apps if they are not permitted to already: Allow the account to have Passenger Apps if they are not permitted to already:
 +<code>
   whmapi1 modifyacct user=mycpuser MAXPASSENGERAPPS=5   whmapi1 modifyacct user=mycpuser MAXPASSENGERAPPS=5
 +</code>
  
 You can adjust this via WHM's Modify an Account if you prefer the GUI (Home »Account Functions »Modify an Account).  You can adjust this via WHM's Modify an Account if you prefer the GUI (Home »Account Functions »Modify an Account). 
Line 224: Line 240:
  
 You will also want to check and confirm that, regardless of whether you chose a package or not (in which case the package will be //default//), that the Application Manager is available to your cPanel user's package via WHM's Feature Manager. You can do so via the command line like this: You will also want to check and confirm that, regardless of whether you chose a package or not (in which case the package will be //default//), that the Application Manager is available to your cPanel user's package via WHM's Feature Manager. You can do so via the command line like this:
 +<code>
   grep passengerapps /var/cpanel/features/*   grep passengerapps /var/cpanel/features/*
 +</code>
  
 If you see it listed, and set to '0', then it is disabled for that particular Feature List. If you see no output, or see it listed and set to '1', then it is enabled. You can that it is disabled on for the Mail Only Feature List on this server below: If you see it listed, and set to '0', then it is disabled for that particular Feature List. If you see no output, or see it listed and set to '1', then it is enabled. You can that it is disabled on for the Mail Only Feature List on this server below:
Line 240: Line 257:
  
 Now, create the Ruby App for your user in cPanel's Application Manager: Now, create the Ruby App for your user in cPanel's Application Manager:
 +<code>
   uapi --user=mycpuser PassengerApps register_application name="test_blog" path="/ruby_apps/test_blog" domain="mycpdomain.tld" deployment_mode="development" enabled="1"   uapi --user=mycpuser PassengerApps register_application name="test_blog" path="/ruby_apps/test_blog" domain="mycpdomain.tld" deployment_mode="development" enabled="1"
 +</code>
  
 You will need to replace the values above with the values you'd like to use for the following keys in the command above: You will need to replace the values above with the values you'd like to use for the following keys in the command above:
Line 259: Line 277:
  
 {{:developmental:ror-applicationmanager.png?nolink&1200|}} {{:developmental:ror-applicationmanager.png?nolink&1200|}}
- 
  
 Next, enable compilers. You could choose to do so globally: Next, enable compilers. You could choose to do so globally:
 +<code>
   chmod 755 /usr/bin/gcc   chmod 755 /usr/bin/gcc
 +</code>
  
 Alternatively, you can choose to only enable compilers for certain users (recommended) via WHM >>  Home »Security Center »Compiler Access  Alternatively, you can choose to only enable compilers for certain users (recommended) via WHM >>  Home »Security Center »Compiler Access 
Line 274: Line 292:
  
 You could run the following commands to enable compiler for a single user if you prefer the command line: You could run the following commands to enable compiler for a single user if you prefer the command line:
 +<code>
   usermod -a -G compiler mycpuser        # replace mycpuser with your cPanel username   usermod -a -G compiler mycpuser        # replace mycpuser with your cPanel username
 +</code>
  
 Now, su to the user (SSH only): Now, su to the user (SSH only):
 +<code>
   su mycpuser   su mycpuser
 +</code>
  
 Test //ruby// and //gem// commands: Test //ruby// and //gem// commands:
 +<code>
   scl enable ea-ruby24 'ruby -v'   scl enable ea-ruby24 'ruby -v'
   scl enable ea-ruby24 'gem -v'   scl enable ea-ruby24 'gem -v'
 +</code>
  
 You should see the version output from these commands if the installations were successful: You should see the version output from these commands if the installations were successful:
Line 291: Line 312:
  
 Now, make the installation directory and change into it: Now, make the installation directory and change into it:
 +<code>
   mkdir ruby_apps   mkdir ruby_apps
   cd ruby_apps/   cd ruby_apps/
 +</code>
  
 If you have tried running the commands //ruby//, //gem//, or //rails// up until now without the scl utility, you would get an error "command not found" I personally  prefer to use the command //rails// without using the Software Collections Library utility(//scl//). So, I'm going to add the following to edit my user's .bashrc as follows: If you have tried running the commands //ruby//, //gem//, or //rails// up until now without the scl utility, you would get an error "command not found" I personally  prefer to use the command //rails// without using the Software Collections Library utility(//scl//). So, I'm going to add the following to edit my user's .bashrc as follows:
 +<code>
   echo 'export PATH=$PATH:/opt/cpanel/ea-ruby24/root/usr/bin/' >> ~/.bashrc   echo 'export PATH=$PATH:/opt/cpanel/ea-ruby24/root/usr/bin/' >> ~/.bashrc
   echo 'export PATH=$PATH:/opt/cpanel/ea-ruby24/root/usr/local/bin/' >> ~/.bashrc    echo 'export PATH=$PATH:/opt/cpanel/ea-ruby24/root/usr/local/bin/' >> ~/.bashrc 
   source ~/.bashrc   source ~/.bashrc
 +</code>
  
 Now you can see that these commands can be run without the scl utility. Now you can see that these commands can be run without the scl utility.
Line 307: Line 329:
  
 Now, we should make a test Rails application to confirm this is working. Run the following from within the //ruby_apps// directory:  Now, we should make a test Rails application to confirm this is working. Run the following from within the //ruby_apps// directory: 
 +<code>
   rails new test_blog   rails new test_blog
 +</code>
  
 You should see output like this scrolling down the page: You should see output like this scrolling down the page:
Line 315: Line 338:
  
 Now, change into the newly generated Rails application and run 'bundle install': Now, change into the newly generated Rails application and run 'bundle install':
 +<code>
   cd test_blog   cd test_blog
   bundle install  --path vendor/bundle   bundle install  --path vendor/bundle
 +</code>
  
 Now, you should be able to load the Rails default page via the domain in the browser: Now, you should be able to load the Rails default page via the domain in the browser:
Line 337: Line 361:
 </WRAP> </WRAP>
  
 +\\
 ===== Special Considerations ===== ===== Special Considerations =====
  
developmental/ruby-rails-apps-cpanel.1570799337.txt.gz · Last modified: 2019/10/11 08:08 by Karson N.