Ruby doesn't execute and show source

Discussion in 'Installation/Configuration' started by minttux, Mar 14, 2016.

  1. minttux

    minttux Member

    i enable ruby and i have this in my virtualhost:
    Code:
            <IfModule mod_ruby.c>
                <Directory /var/www/iliketech.ir/web>
                    Options +ExecCGI
                </Directory>
                RubyRequire apache/ruby-run
                #RubySafeLevel 0
                AddType text/html .rb
                AddType text/html .rbx
                <Files *.rb>
                    SetHandler ruby-object
                    RubyHandler Apache::RubyRun.instance
                </Files>
                <Files *.rbx>
                    SetHandler ruby-object
                    RubyHandler Apache::RubyRun.instance
                </Files>
            </IfModule>
    
    and i put this source:
    Code:
    #!/usr/bin/ruby
    
    puts <<EOS
    Content-type: text/html
    
    <html><body>hi</body></html>
    EOS
    class HelloWorld
       def initialize(name)
          @name = name.capitalize
       end
       def sayHi
          puts "Hello #{@name}!"
       end
    end
    
    hello = HelloWorld.new("World")
    hello.sayHi
    but it doesn't run and show source when i open the url:
    [​IMG]
    Also is my apache mod enabled:
    Code:
    # ls  /etc/apache2/mods-enabled/
    access_compat.load  auth_digest.load  autoindex.conf  deflate.conf  fastcgi.load  mime.load         php5.load           ssl.conf     suphp.load
    actions.conf        authn_core.load   autoindex.load  deflate.load  fcgid.conf    mpm_prefork.conf  python.load         ssl.load
    actions.load        authn_file.load   cgi.load        dir.conf      fcgid.load    mpm_prefork.load  rewrite.load        status.conf
    alias.conf          authz_core.load   dav_fs.conf     dir.load      filter.load   negotiation.conf  setenvif.conf       status.load
    alias.load          authz_host.load   dav_fs.load     env.load      include.load  negotiation.load  setenvif.load       suexec.load
    auth_basic.load     authz_user.load   dav.load        fastcgi.conf  mime.conf     php5.conf         socache_shmcb.load  suphp.conf
    
    also:
    Code:
    # apachectl -M
    AH00548: NameVirtualHost has no effect and will be removed in the next release /etc/apache2/sites-enabled/000-ispconfig.conf:61
    Loaded Modules:
    core_module (static)
    so_module (static)
    watchdog_module (static)
    http_module (static)
    log_config_module (static)
    logio_module (static)
    version_module (static)
    unixd_module (static)
    access_compat_module (shared)
    actions_module (shared)
    alias_module (shared)
    auth_basic_module (shared)
    auth_digest_module (shared)
    authn_core_module (shared)
    authn_file_module (shared)
    authz_core_module (shared)
    authz_host_module (shared)
    authz_user_module (shared)
    autoindex_module (shared)
    cgi_module (shared)
    dav_module (shared)
    dav_fs_module (shared)
    deflate_module (shared)
    dir_module (shared)
    env_module (shared)
    fastcgi_module (shared)
    fcgid_module (shared)
    filter_module (shared)
    include_module (shared)
    mime_module (shared)
    mpm_prefork_module (shared)
    negotiation_module (shared)
    php5_module (shared)
    python_module (shared)
    rewrite_module (shared)
    setenvif_module (shared)
    socache_shmcb_module (shared)
    ssl_module (shared)
    status_module (shared)
    suexec_module (shared)
    suphp_module (shared)
    
     
    Last edited: Mar 14, 2016
  2. ztk.me

    ztk.me Well-Known Member HowtoForge Supporter

    What if you make the .rb file executeable => chmod +x 1.rb
     
  3. minttux

    minttux Member

    Yes of course i know when a file wants to be execute it should have enough permission but it seems apache handler doesn't work and open ruby file just like a normal text
     
  4. ztk.me

    ztk.me Well-Known Member HowtoForge Supporter

    So you did make the .rb file executeable?

    Edit: whopsy the following will not work unless you install/enable eRuby - my fault.

    Well yeah, your use of ruby is CGI like behaviour. Did you try to test ruby using this kind of code already?
    Code:
        <%
          1.upto(99) do |x|
            puts "counting #{x} red balloons"
          end
        %>
    
    Edit2: Another thing I remember to is disable the rb extension in /etc/mime.types like described on
    this howto.
     
    Last edited: Mar 14, 2016
  5. minttux

    minttux Member

    Sure

    but it's not inside tutorial and then how to? is it need to change something in ispconfig like template or whatever?

    No same result . it shows it as a text file

    YEs i did
     
  6. ztk.me

    ztk.me Well-Known Member HowtoForge Supporter

    for eruby you would need to modify the template, yes
    Code:
    RubyRequire apache/eruby-run
    ...
        <Files *.rhtml>
            SetHandler ruby-object
            RubyHandler Apache::ERubyRun.instance
        </Files>
    
    
    But this is out of scope and not solving your issue here, also requires liberubis-ruby to be installed.


    To be honest, I really don't know why - config looks great and appearently your mod_ruby is beeing loaded.
    Any errors / warnings / hints in your error.log while restarting apache? Or in the vhost error log when trying to execute the file?

    I guess you did but... is the file owned by the client/webgroup belonging to that domain?


    What if you use
    Code:
    #!/usr/bin/env ruby
    or just a very basic example.rb ( without #! stuff )
    Code:
    puts "Hello World!"
     
  7. minttux

    minttux Member

    How can you say it's loaded? its not in:
    Code:
    # ls  /etc/apache2/mods-enabled/
    access_compat.load  auth_digest.load  autoindex.conf  deflate.conf  fastcgi.load  mime.load         php5.load           ssl.conf     suphp.load
    actions.conf        authn_core.load   autoindex.load  deflate.load  fcgid.conf    mpm_prefork.conf  python.load         ssl.load
    actions.load        authn_file.load   cgi.load        dir.conf      fcgid.load    mpm_prefork.load  rewrite.load        status.conf
    alias.conf          authz_core.load   dav_fs.conf     dir.load      filter.load   negotiation.conf  setenvif.conf       status.load
    alias.load          authz_host.load   dav_fs.load     env.load      include.load  negotiation.load  setenvif.load       suexec.load
    auth_basic.load     authz_user.load   dav.load        fastcgi.conf  mime.conf     php5.conf         socache_shmcb.load  suphp.conf
    and in:
    Code:
    # apachectl -M
    AH00548: NameVirtualHost has no effect and will be removed in the next release /etc/apache2/sites-enabled/000-ispconfig.conf:61
    Loaded Modules:
    core_module (static)
    so_module (static)
    watchdog_module (static)
    http_module (static)
    log_config_module (static)
    logio_module (static)
    version_module (static)
    unixd_module (static)
    access_compat_module (shared)
    actions_module (shared)
    alias_module (shared)
    auth_basic_module (shared)
    auth_digest_module (shared)
    authn_core_module (shared)
    authn_file_module (shared)
    authz_core_module (shared)
    authz_host_module (shared)
    authz_user_module (shared)
    autoindex_module (shared)
    cgi_module (shared)
    dav_module (shared)
    dav_fs_module (shared)
    deflate_module (shared)
    dir_module (shared)
    env_module (shared)
    fastcgi_module (shared)
    fcgid_module (shared)
    filter_module (shared)
    include_module (shared)
    mime_module (shared)
    mpm_prefork_module (shared)
    negotiation_module (shared)
    php5_module (shared)
    python_module (shared)
    rewrite_module (shared)
    setenvif_module (shared)
    socache_shmcb_module (shared)
    ssl_module (shared)
    status_module (shared)
    suexec_module (shared)
    suphp_module (shared)
    and mod-ruby it's not longer support on ubuntu 14.04 server

    No i think it because if ifmodule so when mod-ruby doesn't installed then nothing run and nothing made error
    Yes i put it by ftp
    No you can see it:
    http://iliketech.ir/1.rb
     
  8. ztk.me

    ztk.me Well-Known Member HowtoForge Supporter

    Hmm my eyes must have tricked me - omg
    Ok, well then - you'd probably need to move your ruby to cgi-bin directory and run it as CGI :/

    Another possible solution would be to setup passenger ... would need some modification of the templates...
    @till maybe it's time to write some howtos for mpm worker/event using non mod_ modules to do things and updates to the template files =) What about ISPC 3.1?

    I'm back in 10 minutes, getting some coffee :)
     
  9. minttux

    minttux Member

    Thanks i'm happy to find something to change on next version of ISPconfig and help to improve it.

    Now i would like to install passenger and help me to change template for ruby can enabled and disabled as a feature. do you have any doc to install and config ruby module on apache ?
     
  10. ztk.me

    ztk.me Well-Known Member HowtoForge Supporter

    I'm going to do a test setup including needed changes to the template files, currently I'm drinking my coffee and preparing a test VM to work on.
    I'll post an update after I confirmed it's working. I assume you're using apache mpm prefork as it's still in the howtos?
     
  11. minttux

    minttux Member

  12. ztk.me

    ztk.me Well-Known Member HowtoForge Supporter

    Quick update, actually you either need to run your ruby files as CGI or need to build the new mod_ruby ( the old one is dead ).
    Nay other method would require to make a few changes and let the ruby app run / listen on an interface/port which is assumingly not what you want.

    My issue right now is, I'm currently not able to run ubuntu 14.x since I lack of 64bit VM right now and there's no 32bit edition available it seems.
    Anyway, the main difference should be the installation process, which seems to be easy in ubuntu since it's already described on the projects page https://github.com/mikeowens/mod_ruby
     
  13. ztk.me

    ztk.me Well-Known Member HowtoForge Supporter

    Update2: Ok, I did make it work - however I can't see how it supports custom headers, so probably these won't work. So I assume running ruby files as CGI might be the only option to use custom headers. I'll give an update after doing some experiments with the template files. But if you want to try this module, I did it so I share it.

    This is going to install the new mod_ruby package from https://github.com/mikeowens/mod_ruby

    This is for Debian 8

    We need a few build tools and dev packages

    Code:
    apt-get install cmake libaprutil1-dev libapr1-dev ruby ruby-dev apache2-dev pbuilder debootstrap devscripts
    



    Prepare folders and build dir.
    Code:
    mkdir /usr/local/src/mod_ruby
    cd /usr/local/src/mod_ruby
    wget https://github.com/mikeowens/mod_ruby/archive/master.zip
    unzip master.zip
    cd mod_ruby-master
    /usr/lib/pbuilder/pbuilder-satisfydepends
    fakeroot debian/rules clean
    


    If you're on debian or dpkg-buildpackage step fails: modify debian/changelog
    Code:
    mod-ruby (3.0.0-3~jessie) jessie; urgency=low
    
      * Release of 3.0.0-3
    
    -- Michael Owens <[email protected]>  Mon, 14 Mar 2016 18:27:47 +0100
    


    If you're on debian or dpkg-buildpackage step fails: modify debian/changelog.in
    Code:
    mod-ruby (${MODRUBY_RELEASE_VERSION}~jessie) jessie; urgency=low
    
      * Release of ${MODRUBY_RELEASE_VERSION}
    
    -- Michael Owens <[email protected]>  ${MODRUBY_RELEASE_DATE}
    



    Building and installing .deb, please not that your .deb could have a different name - we also don't need the -git- deb file.
    Code:
    dpkg-buildpackage
    dpkg -i ../mod-ruby_3.0.0-3~jessie_i386.deb
    


    Enable our new mod_ruby
    Also remove the ruby.conf - no need to enable it global.

    Code:
    a2enmod ruby
    rm /etc/apache2/mods-enabled/ruby.conf
    



    Edit your /usr/local/ispconfig/server/conf/vhost.conf.master

    Code:
    # Replace
    
    <tmpl_if name='ruby' op='==' value='y'>
                    <IfModule mod_ruby.c>
                            <Directory {tmpl_var name='web_document_root_www'}>
                                    Options +ExecCGI
                            </Directory>
                            RubyRequire apache/ruby-run
                            #RubySafeLevel 0
                            AddType text/html .rb
                            AddType text/html .rbx
                            <Files *.rb>
                                    SetHandler ruby-object
                                    RubyHandler Apache::RubyRun.instance
                            </Files>
                            <Files *.rbx>
                                    SetHandler ruby-object
                                    RubyHandler Apache::RubyRun.instance
                            </Files>
                    </IfModule>
    </tmpl_if>
    
    # with
    
    <tmpl_if name='ruby' op='==' value='y'>
        <IfModule mod_ruby.c>
            AddHandler ruby-handler .rsp
            AddHandler ruby-handler .rhtml
            AddHandler ruby-script-handler .rb
    
            # Set MIME types for RUBY/RHTML/Ruby files
            AddType text/html .rhtml .rsp .rb
    
        </IfModule>
    </tmpl_if>
    



    Sidenotes
    Code:
    The author of this module mentioning a quirk for ubuntu users to be placed between <IFModule ...></IFModule> :
    # Hack for Ubuntu.
    RubyConfig GEM_PATH /usr/lib/ruby/gems/2.0.0/gems/
    This wasn't needed for me to run some simple ruby scripts.
    Also This compiles on 64bit, it will segfault, no issue on 32bit.
    If you need 64bit see page 2 of this thread.
    
    Also this code:
    
    #!/usr/bin/ruby
    
    puts <<EOS
    Content-type: text/html
    
    <html><body>hi</body></html>
    
    Will actually print out Content-type: aswell, so it might not be a real drop-in-replacement
    
     
    Last edited: Mar 16, 2016
  14. ztk.me

    ztk.me Well-Known Member HowtoForge Supporter

    Ruby without mod_ruby Apache
    Use Ruby with ISPConfig 3.0.x using CGI

    Edit your /usr/local/ispconfig/server/conf/vhost.conf.master

    Code:
    # Replace
    
    <tmpl_if name='ruby' op='==' value='y'>
                    <IfModule mod_ruby.c>
                            <Directory {tmpl_var name='web_document_root_www'}>
                                    Options +ExecCGI
                            </Directory>
                            RubyRequire apache/ruby-run
                            #RubySafeLevel 0
                            AddType text/html .rb
                            AddType text/html .rbx
                            <Files *.rb>
                                    SetHandler ruby-object
                                    RubyHandler Apache::RubyRun.instance
                            </Files>
                            <Files *.rbx>
                                    SetHandler ruby-object
                                    RubyHandler Apache::RubyRun.instance
                            </Files>
                    </IfModule>
    </tmpl_if>
    
    # with
    
    <tmpl_if name='ruby' op='==' value='y'>
            <Directory {tmpl_var name='web_document_root_www'}>
                Options +ExecCGI
            </Directory>
            AddHandler cgi-script .rb
    </tmpl_if>
    



    Sidenotes
    Code:
    Don't forget to make your .rb executeable.
    Also note, this basically allows any CGI in .rb files :/
    
     
    Last edited: Mar 14, 2016
    till likes this.
  15. ztk.me

    ztk.me Well-Known Member HowtoForge Supporter

    I tried to make the old mod_ruby work with 2.4 but besides I already probably broke http authentification data, error logging it segfaults
    ruby_call_interpreter() failed
    and I'm not into it too much so as many others already said: wont fix :(
     
  16. minttux

    minttux Member

    Wow thanks man i tried all and put feedback
     
  17. minttux

    minttux Member

    i've got error when compile:
    Code:
    # fakeroot debian/rules clean
    dh_testdir
    dh_testroot
    cmake .
    -- The C compiler identification is GNU 4.8.4
    -- The CXX compiler identification is GNU 4.8.4
    -- Check for working C compiler: /usr/bin/cc
    -- Check for working C compiler: /usr/bin/cc -- works
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    -- Check for working CXX compiler: /usr/bin/c++
    -- Check for working CXX compiler: /usr/bin/c++ -- works
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- PLATFORM: linux
    -- SYSTEM: Linux-3.13.0-79-generic
    -- VERSION: 3.13.0-79-generic
    -- ARCH: x86_64
    -- SYSTEM: 3.13.0-79-generic (linux/debian/settings.cmake)
    -- LINUX_DISTRO: trusty
    -- RELEASE_DATE: Tue, 15 Mar 2016 16:17:50 +0330
    -- VERSION:      3.0.0
    -- SOVERSION:    3.0.0
    -- RUBY_INCLUDE_ARCH_PATH:
    -- RUBY_INCLUDE_PATH: RUBY_INCLUDE_PATH-NOTFOUND
    -- RUBY_ARCH_DIR: /usr/lib/ruby/1.9.1/x86_64-linux
    -- RUBY_LIBRARY: /usr/lib/libruby-1.9.1.so.1.9.1
    -- RUBY_ARCH_LIB_DIR :
    --
    -- -------------------------------------------------------------------------------
    --  BUILD_SHARED_LIBS = OFF
    --  CMAKE_INSTALL_PREFIX = /usr/local/src/mod_ruby/mod_ruby-master
    --  CMAKE_BUILD_TYPE = RelWithDebInfo
    --  CMAKE_MODULE_PATH =
    --  Project_DEPENDS = ""
    --  BUILD_WITH = ""
    --  INSTALL_DOC = ON
    --  Change a value with: cmake -D<Variable>=<Value>
    -- -------------------------------------------------------------------------------
    --
    CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
    Please set them or make sure they are set and tested correctly in the CMake files:
    RUBY_INCLUDE_PATH (ADVANCED)
       used as include directory in directory /usr/local/src/mod_ruby/mod_ruby-master/src
       used as include directory in directory /usr/local/src/mod_ruby/mod_ruby-master/src
       used as include directory in directory /usr/local/src/mod_ruby/mod_ruby-master/src
    
    -- Configuring incomplete, errors occurred!
    See also "/usr/local/src/mod_ruby/mod_ruby-master/CMakeFiles/CMakeOutput.log".
    make: *** [clean] Error 1
    
    Also log file: http://codepad.org/BbkIg9rR
    my os is:
    Code:
    # lsb_release -a
    No LSB modules are available.
    Distributor ID:    Ubuntu
    Description:    Ubuntu 14.04.4 LTS
    Release:    14.04
    Codename:    trusty
    
     
  18. ztk.me

    ztk.me Well-Known Member HowtoForge Supporter

    Were you been able to install all dependencies including all *-dev packages listed above? Or did APT say something could not be found so it'll continue without a specific package?
    I'm not sure wether all the packages are called exactly the same on Ubuntu.

    Another thing you could try is just setting
    Code:
    bash$ RUBY_INCLUDE_PATH=/usr/include/ruby-2.1.0
    
    Be sure it's the correct folder - and I currently can just assume it shall work :/
     
  19. minttux

    minttux Member

    YEs absolutely it installed everything otherwise i said it as an error.

    I have this version:
    Code:
    # ls /usr/include/ruby-1.9.1/
    ruby  ruby.h  x86_64-linux
    
    and strange thing is define that path as variable:
    Code:
    # RUBY_INCLUDE_PATH=/usr/include/ruby-1.9.1
    root@server:/usr/local/src/mod_ruby/mod_ruby-master# export RUBY_INCLUDE_PATH=/usr/include/ruby-1.9.1
    root@server:/usr/local/src/mod_ruby/mod_ruby-master# echo $RUBY_INCLUDE_PATH
    /usr/include/ruby-1.9.1
    
    but i get same error when i run: # fakeroot debian/rules clean
    Code:
    # fakeroot debian/rules clean
    dh_testdir
    dh_testroot
    cmake .
    -- PLATFORM: linux
    -- SYSTEM: Linux-3.13.0-79-generic
    -- VERSION: 3.13.0-79-generic
    -- ARCH: x86_64
    -- SYSTEM: 3.13.0-79-generic (linux/debian/settings.cmake)
    -- LINUX_DISTRO: trusty
    -- RELEASE_DATE: Tue, 15 Mar 2016 18:11:59 +0330
    -- VERSION:      3.0.0
    -- SOVERSION:    3.0.0
    -- RUBY_INCLUDE_ARCH_PATH:
    -- RUBY_INCLUDE_PATH: RUBY_INCLUDE_PATH-NOTFOUND
    -- RUBY_ARCH_DIR: /usr/lib/ruby/1.9.1/x86_64-linux
    -- RUBY_LIBRARY: /usr/lib/libruby-1.9.1.so.1.9.1
    -- RUBY_ARCH_LIB_DIR :
    --
    -- -------------------------------------------------------------------------------
    --  BUILD_SHARED_LIBS = OFF
    --  CMAKE_INSTALL_PREFIX = /usr/local/src/mod_ruby/mod_ruby-master
    --  CMAKE_BUILD_TYPE = RelWithDebInfo
    --  CMAKE_MODULE_PATH =
    --  Project_DEPENDS = ""
    --  BUILD_WITH = ""
    --  INSTALL_DOC = ON
    --  Change a value with: cmake -D<Variable>=<Value>
    -- -------------------------------------------------------------------------------
    --
    CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
    Please set them or make sure they are set and tested correctly in the CMake files:
    RUBY_INCLUDE_PATH (ADVANCED)
       used as include directory in directory /usr/local/src/mod_ruby/mod_ruby-master/src
       used as include directory in directory /usr/local/src/mod_ruby/mod_ruby-master/src
       used as include directory in directory /usr/local/src/mod_ruby/mod_ruby-master/src
    
    -- Configuring incomplete, errors occurred!
    See also "/usr/local/src/mod_ruby/mod_ruby-master/CMakeFiles/CMakeOutput.log".
    make: *** [clean] Error 1
    
     
  20. ztk.me

    ztk.me Well-Known Member HowtoForge Supporter

    A somewhat hacky way to do it, but who cares now ... it works =)

    edit your config/ruby.cmake
    Code:
    # After this line
    SET(RUBY_ARCH_LIB_DIR       ${RUBY_ARCH_LIB_DIR}       CACHE PATH "The Ruby arch lib dir")
    # add
    SET(RUBY_POSSIBLE_INCLUDE_PATHS "/usr/include/ruby-1.9.1")
    

    Oh and you can run the old mod_ruby on ubuntu 14.04, doesn't work as expected probably but it does the same, it will output Content-Type as text on the site the same way the new mod does.
     
    Last edited: Mar 16, 2016

Share This Page