📜 ⬆️ ⬇️

Rails 2.3.5 + mod_rails + MAMP on OSX Tiger

Strange, but I have not found in the network any intelligible manual for installing OS X rails with mod_rails - a new (relatively) module for Apache, which is eliminated from a headache with a delay. All manuals are outdated, then Mongrel, then FastCGI. Oddly enough, this was nothing difficult - it turned out a kind of zombie from old tutorials and a couple of new actions.

You will need Xcode for the work (last 2.5 for the tiger) - it is not installed by default, but can be found on the Mac OS X installation disc or downloaded from Apple's Developer Connection developer.apple.com . All commands need to be typed in the terminal - it can be found in / Programs / Utilities (/ Applications / Utilities). I also use Textmate to edit files (the mate command in the console), it also does not need to be defaulted, so you can use vi or pico.

I will note two points:
')
1) I put everything on OSX 10.4, I think there shouldn't be any special differences from Leopards, but I note that REE 1.8.7.xxx refused to work with me (because of a bug in MRI: redmine.ruby-lang.org/issues/show / 405 )

2) I specifically put mod_rails in parallel with php to make sure that they can live quietly next to each other




Part I. Preparation of the usual MAMP Environment



1) We put macports.
www.macports.org/install.php
Download and install via gui via the link, then in the console:

sudo port selfupdate


2) We put the Apache

sudo port install apache2
sudo ln -s /opt/local/apache2/bin/apachectl /opt/local/bin/apache2ctl



3) Change DocumentRoot in httpd.conf so that it points to the folder we need.
I created the Rails folder in my home directory, with public_html as the document root.
All the applications I create in ~ / Rails and link to public_html.

sudo mate /opt/local/apache2/conf/httpd.conf

# --- httpd.conf --- #

DocumentRoot "/Users/ikido/Rails/public_html"
<Directory "/Users/ikido/Rails/public_html">

# --- httpd.conf --- #



4) Step mysql

sudo port install mysql5-server
sudo -u mysql mysql_install_db5
sudo ln -s /opt/local/bin/mysql5 /opt/local/bin/mysql

# Mysql
/opt/local/lib/mysql5/bin/mysqld_safe &

# ,
/opt/local/lib/mysql5/bin/mysql_secure_installation



5) We put php5

sudo port install php5 +apache2 +mysql5

cd /opt/local/apache2/modules
sudo /opt/local/apache2/bin/apxs -a -e -n "php5" libphp5.so # php5



6) rule httpd.conf:

sudo mate /opt/local/apache2/conf/httpd.conf

# --- httpd.conf --- #

<IfModule mime_module>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

<IfModule dir_module>
DirectoryIndex index.html index.php

# --- httpd.conf --- #


7) We check that everything works:

echo "<? phpinfo(); ?>" > /Users/ikido/Rails/public_html/index.php
sudo apache2ctl start


We check the browser localhost , there must be a phpinfo page





Part II. Now we put Ruby Environment



1) Set ruby

sudo port install ruby


2) Set rubygems
in macports the old version, so we install from the source
docs.rubygems.org/read/chapter/3

mkdir -p /opt/src/
cd /opt/src/
curl -O files.rubyforge.vm.bytemark.co.uk/rubygems/rubygems-1.3.5.tgz
tar zxf rubygems-1.3.5.tgz
cd rubygems-1.3.5
sudo ruby setup.rb



4) Set rails

sudo gem install rails --include-dependencies


5) We put a bunch of mysql

sudo gem install mysql -- --with-mysql-dir=/opt/local/lib/mysql5/


6) Install mod_rails
www.modrails.com/install.html

sudo gem install passenger
sudo passenger-install-apache2-module --apxs2-path /opt/local/apache2/bin/apxs



7) Edit httpd.conf , insert what the installer gave us:
www.modrails.com/documentation/Users%20guide%20Apache.html

sudo mate /opt/local/apache2/conf/httpd.conf

# --- httpd.conf --- #

LoadModule passenger_module /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.9/ext/apache2/mod_passenger.so
PassengerRoot /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.9
PassengerRuby /opt/ruby-enterprise/bin/ruby

# --- httpd.conf --- #



8) The rule is httpd.conf , for each application we register RailsBaseUri after specifying the DocumentRoot (Accordingly, the directive works for vhosts), and as far as I understand the rails can be in any subfolder. Railsenv - optional, here we specify which environment to use by default.

# --- httpd.conf --- #

DocumentRoot "/Users/ikido/Rails/public_html"
RailsBaseURI /testapp
RailsBaseURI /someotherapp
RailsEnv development

# --- httpd.conf --- #



8) Check that we are on the rails - create a test application

cd ~/Rails
rails -d mysql testapp
ln -s /Users/ikido/Rails/testapp/public/ public_html/testapp
cd testapp
mate config/database.yml # mysql
rake db:create
script/generate scaffold test
rake db:migrate
sudo apache2ctl restart


Now you can go to localhost / testapp / tests browser, enjoy (hopefully) and make sure everything works fine

Source: https://habr.com/ru/post/80885/


All Articles