Apache Server installation and deployment of rails applications using the passenger plugin

Source: Internet
Author: User
Tags wrappers ruby on rails

A small example can be deployed on rails ' webrick, and it will take Apache to move backwards.

Installing the Apache server

command is sudo apt-get install apache2

Installing the Passenger plugin

The installation is not ready for immediate use, because you want to run the Rails app and install the plugin passenger for the Apache server.

Passenger is a gem package and the installation command is gem install passenger

Passenger integrated into Apache

Execute the command passenger-install-apache2-module and enter the installer.

12345678910111213141516 [email protected]:~$ passenger-install-apache2-moduleWelcome to the Phusion Passenger Apache 2 module installer, v3.0.18.This installer will guide you through the entire installation process. Itshouldn‘t take more than 3 minutes in total. Here‘s what you can expect from the installation process: 1. The Apache 2 module will be installed for you. 2. You‘ll learn how to configure Apache. 3. You‘ll learn how to deploy a Ruby on Rails application.Don‘t worry if anything goes wrong. This installer will advise you on how tosolve any problems.Press Enter to continue, or Ctrl-C to abort.

After the carriage return is determined, the dependency checks are made, some content does not pass, and the carriage return will prompt how to resolve.

1234567891011121314151617181920 Checking for required software... * GNU C++ compiler... found at /usr/bin/g++ * Curl development headers with SSL support... found * OpenSSL development headers... found * Zlib development headers... found * Ruby development headers... found * OpenSSL support for Ruby... found * RubyGems... found * Rake... found at /home/abbuggy/.rvm/wrappers/ruby-1.9.2-p320/rake * rack... found * Apache 2... found at /usr/sbin/apache2 * Apache 2 development headers... not found * Apache Portable Runtime (APR) development headers... not found * Apache Portable Runtime Utility (APU) development headers... not foundSome required software is not installed.But don‘t worry, this installer will tell you how to install them.Press Enter to continue, or Ctrl-C to abort.

Follow the prompts for the missing dependency packages, such as I am missing apache2-perfork-dev,libapr1-dev,libaprutil1-dev three packages.

123456789101112 --------------------------------------------Installation instructions for required software * To install Apache 2 development headers:   Please run apt-get install apache2-prefork-dev as root. * To install Apache Portable Runtime (APR) development headers:   Please run apt-get install libapr1-dev as root. * To install Apache Portable Runtime Utility (APU) development headers:   Please run apt-get install libaprutil1-dev as root.

The procedure also gives a solution. Although they are given separately, we can do it together. Your environment may not be the same as mine, follow the above tips to 90%.

1234567891011121314151617181920 [email protected]:~$ sudo apt-get install apache2-prefork-dev libapr1-dev libaprutil1-dev正在读取软件包列表... 完成正在分析软件包的依赖关系树       正在读取状态信息... 完成       下列【新】软件包将被安装:  apache2-prefork-dev libapr1-dev libaprutil1-dev升级了 0 个软件包,新安装了 3 个软件包,要卸载 0 个软件包,有 0 个软件包未被升级。需要下载 0 B/1,718 kB 的软件包。解压缩后会消耗掉 11.3 MB 的额外空间。Selecting previously unselected package libapr1-dev.(正在读取数据库 ... 系统当前共安装有 230693 个文件和目录。)正在解压缩 libapr1-dev (从 .../libapr1-dev_1.4.6-1_i386.deb) ...Selecting previously unselected package libaprutil1-dev.正在解压缩 libaprutil1-dev (从 .../libaprutil1-dev_1.3.12+dfsg-3_i386.deb) ...Selecting previously unselected package apache2-prefork-dev.正在解压缩 apache2-prefork-dev (从 .../apache2-prefork-dev_2.2.22-1ubuntu1.2_i386.deb) ...正在处理用于 man-db 的触发器...正在设置 libapr1-dev (1.4.6-1) ...正在设置 libaprutil1-dev (1.3.12+dfsg-3) ...正在设置 apache2-prefork-dev (2.2.22-1ubuntu1.2) ...

Perform the Passenger-install-apache2-module installation again, and after the compilation is complete, a successful prompt is given. It is also required to place the following in the Apache configuration file.

12345678910111213 The Apache 2 module was successfully installed.Please edit your Apache configuration file, and add these lines:   LoadModule passenger_module /home/abbuggy/.rvm/gems/ruby-1.9.2-p320/gems/passenger-3.0.18/ext/apache2/mod_passenger.so   PassengerRoot /home/abbuggy/.rvm/gems/ruby-1.9.2-p320/gems/passenger-3.0.18   PassengerRuby /home/abbuggy/.rvm/wrappers/ruby-1.9.2-p320/ruby After you restart Apache, you are ready to deploy any number of Ruby on Railsapplications on Apache, without any further Ruby on Rails-specificconfiguration!Press ENTER to continue.

Apache configuration files are located in/etc/apache2/httpd.conf, edited and added. So far, httpd.conf has been like this.

123 LoadModule passenger_module /home/abbuggy/.rvm/gems/ruby-1.9.2-p320/gems/passenger-3.0.18/ext/apache2/mod_passenger.soPassengerRoot /home/abbuggy/.rvm/gems/ruby-1.9.2-p320/gems/passenger-3.0.18PassengerRuby /home/abbuggy/.rvm/wrappers/ruby-1.9.2-p320/ruby
Deploy Rails Apps

I want to visit my example site through an address similar to "localhost/simple-cms", and more sites can follow the form

Localhost/site1

Localhost/site2

The format.

First you have to configure a base directory, which is the root directory of Apache.

Add the following configuration to httpd.conf, set/var/www as the root of the web and go back to the directory where you want to place each site.

1234567 <VirtualHost*:80>      ServerName localhost      DocumentRoot /var/www      <Directory/var/www>         Allow from all      </Directory></VirtualHost>

Next, hang a specific site under the Web root directory, such as this simple-cms. or configure it to/etc/apache2/httpd.conf, the next four lines are added. /simple-cms is the access address relative to the above localhost

123456789101112 <VirtualHost *:80>   ServerName localhost   DocumentRoot /var/www   <Directory/var/www>      Allow from all   </Directory>       RailsBaseURI /simple-cms   <Directory/var/www/simple_cms>      Options -MultiViews   </Directory></VirtualHost>

/var/www/test_site is a soft connection that points to the public directory in the development environment.

1 sudo ln -s /home/abbuggy/workspace/simple_cms/public  /var/www/simple-cms

However, when I configure myself, I am wrong, always prompt "We ' re sorry,but something went wrong!" The solution was finally found near the edge of the crash. "The DEFAULTRAILS_ENV environment in which deployed Rails Applicationsare run, is" production ". You can change this by changing therailsenv configuration option. "-From phusion passenger users Guide

That is, the default is the production environment, if you use the development environment when debugging, you need to add a line railsenv development in the Apache configuration file, so the correct configuration is.

12345678910111213 <VirtualHost*:80>   ServerName localhost   DocumentRoot /var/www   <Directory/var/www>      Allow from all   </Directory>      RailsBaseURI /simple-cms   RailsEnv development   <Directory/var/www/simple_cms>      Options -MultiViews   </Directory></VirtualHost>

Restart the Apache,sudo service apache2 restart to access Localhost/simple-cms successfully.

Apache Server installation and deployment of rails applications using the passenger plugin

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.