From: Chad Perrin Date: 2007-02-21T00:30:37+09:00 Subject: Re: Help Me On Tue, Feb 20, 2007 at 11:28:24PM +0900, David Vallner wrote: > On Tue, 20 Feb 2007 15:06:21 +0100, Decky Fiyemonda > wrote: > > >Hi everyone iam new here but iam not in ruby. > > > >How to make Web page with Ruby, and is ruby can run along with PHP? > > > > > A) *twitch* > B) If you're used to PHP, probably the easiest way would be to use > mod_ruby [http://www.modruby.net/en/], or WEBrick > [http://www.webrick.org/]. The latter site has some code in the "HTTP > server" section that should get you started. I think[1] WEBrick by default > will handle files with the extension .rhtml as ERB files, which are the > closest you'll get to the way PHP works - the basic difference is that you > write <% your_code_here %> instead of . If you're using a shared hosting account, you may be able to set up eruby via the cgi-bin directory. The procedure goes something like this: mkdir ~/eruby cd ~/eruby wget http://www.modruby.net/archive/eruby-1.0.5.tar.gz tar -xzf eruby-1.0.5.tar.gz cd eruby-1.0.5 ./configure.rb make make install cp eruby ~/public_html/cgi-bin/eruby cd ~/public_html/cgi-bin chmod 755 eruby Then, you have to edit your ~/.htaccess file to add MIME type association for your files. For instance, add these two lines to be able to create .rhtml files similarly to how you'd use .php files: AddType application/x-httpd-eruby .rhtml Action application/x-httpd-eruby /cgi-bin/eruby Then this code in a hello_world.rhtml file would print out "Hello, world!" in the browser of anyone opening that page: <% puts "Hello, world!" %> Normally, of course, you'd want to actually include normal webpage stuff, like html tags, page title, stylesheets, and so on -- just as you would with PHP. This all assumes you have shell access on the shared hosting account, however -- which you certainly do not have on certain low-quality webhosts such as GoDaddy. Hint about webhosts: Never use one that does not provide SSH, or at least SFTP, access. With standard FTP, you're essentially broadcasting your username and password to anyone with the desire to listen in. > > C) Depends on how you define "run along with". If you use mod_ruby (more > complicated to install), you can run both the languages with one Apache > server, probably depending on the file extension. This is where WEBrick is > more complicated, because it will be a Ruby-specific server independent of > your Apache. But it's possible (and fairly easy once you understand the > principles) to set up Apache so that it asks a running WEBrick to handle > your .rhtml files, using either mod_proxy (if all your .rhtml files are in > a single directory you're serving with WEBrick), or mod_rewrite (this is a > more complicated solution, where you'll have both Apache or WEBrick serve > the same directory, but only tell Apache to turn to WEBrick for the ones > whose filenames end in .rhtml). I have no idea what was meant by "run along with" in this context, either. Both will run on the same server, but mixing both in one file is unlikely to yield positive results. For instance, trying to embed output from the above example hello_world.rhtml in a PHP file with the following code: . . . results in the source code of the .rhtml file being sent to the browser, rather than being executed on the server so that "Hello, world!" would be sent to the browser. -- CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ] Amazon.com interview candidate: "When C++ is your hammer, everything starts to look like your thumb."