Lighttpd server configuration to run cgi binaries using fast cgi - fastcgi

I have a lighttpd webserver runnning in a linux embedded box. Lighttpd have got Fastcgi enabled for php. How to edit my lighttpd.conf such that to run cgi binaries using fastcgi? Also my linux box doesn't have cgi-bin folder in it's document root.
I am quoting the excerpt from lighttpd.conf which enables fastcgi and php configuration. Also, it can be seen that cgi.assign is commented.
server.modules = (
# "mod_rewrite",
"mod_redirect",
# "mod_alias",
"mod_access",
# "mod_trigger_b4_dl",
# "mod_auth",
# "mod_status",
# "mod_setenv",
"mod_fastcgi",
# "mod_proxy",
#
and
## read fastcgi.txt for more info
## for PHP don't forget to set cgi.fix_pathinfo = 1 in the php.ini
fastcgi.server = ( ".php" =>
( "localhost" =>
(
"socket" => "/tmp/php-fastcgi.socket",
"bin-path" => "/bin/php-cgi -c /etc/php.ini"
)
)
)
#### CGI module
#cgi.assign = ( ".pl" => "/usr/bin/perl",
# ".cgi" => "/usr/bin/perl" )
#

You need to compile php with cgi option. Basically its a standalone php.

Related

Cannot start ruby on rails application on server but works locally, wrong environment path

I've encountered an issue that is preventing me from starting my Ruby on Rails application on our Production server despite it running correctly on both Development and Staging environments. The error message is as follows:
[ E 2021-04-26 14:53:39.4216 14896/T11 age/Cor/App/Implementation.cpp:221 ]: Could not spawn process for application /path/to/application: The application encountered the following error: No such file to load -- /path/to/application/app/config/environment.rb (LoadError)
For some reason Passenger is attempting to find the config/environment.rb inside of an app folder when instead it should just be looking for:
/path/to/application/config/environment.rb
Passenger is being configured using Apache and the site config can be seen below:
<VirtualHost *:80>
# PassengerFriendlyErrorPages on
# PassengerStartTimeout 90
ServerAdmin email#example.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
DocumentRoot /path/to/application/public
<Directory /path/to/application/public>
AllowOverride None
Options -Multiviews
Require all granted
</Directory>
</VirtualHost>
PassengerPreStart http://localhost
PassengerAppEnv production
PassengerLogFile ${APACHE_LOG_DIR}/passenger.log
The server is running Ubuntu 18.04. I've included what I think are the relevant versions below:
Ruby - 2.5.1
Ruby on Rails - 5.2.5
Passenger - 6.0.7
Does anyone know what config I may be missing that is causing Passenger to be looking in the wrong place?
look .. i read about passenger , i am beginner to ruby ;"beginner"= when i remember about ruby,python i download them and i try to compile them to exe to find out if they changed things = .exe smaller or for the another alternative of compilers i usually use ..
today's test was in ruby + apache + php 8.1 as testing a output from a http://localhost/test/ and without any compilation (this isn't the answer to your question but if anyone needs this new point of view and you use php and ruby always ..)
in windows with apache ,php ,.. and ruby installed , in your htdocs create test folder and put these into it:
index.php
<?php
// Highest priority
proc_nice(-20);
echo shell_exec('index.rb');
//system('index.rb');
?>
index.rb
#puts "Content-type: text/html\r\n"
puts "Hello World" + "<br>"
time1 = Time.new
puts "Current Time : " + time1.inspect + "<br>"
# Time.now is a synonym:
time2 = Time.now
puts "Current Time : " + time2.inspect + "<br>"
now open the browser and go to http://localhost/test/
then if you click refresh or you hit f5 key(refresh) in your bowser after the first results then the time shoul display the refresh values

Upgrade redis from v2 to v4 on Windows causes Rails connection error

Background
My dev environment is Windows, Rails cache_store worked fine for redis V2.
I am implementing ActiveJob with sidekiq, which required redis >= v3
I installed Redis for Windows from GitHub, I tried both V4 and V5.
Windows setup
Ran the installation .msi file
After install and re-boot, checked the redis-cli and connected and tested fine.
Rail setup
from config/environments/development.rb
config.cache_store = :redis_cache_store, { url: 'redis://localhost:6379/0' }
Rails console
>> Rails.cache
=> #<ActiveSupport::Cache::RedisCacheStore options={:namespace=>nil, :compress=>true, :compress_threshold=>1024, :expires_in=>nil, :race_condition_ttl=>nil} redis=#<Redis client v4.2.5 for redis://localhost:6379/0>>
>> Rails.cache.redis.connected?
=> false
>> t = Rails.cache.fetch('test') { 'T' }
=> "T"
>> r = Redis.new
=> #<Redis client v4.2.5 for redis://127.0.0.1:6379/0>
>> r.get 'test'
=> "123"
>> r.connected?
=> true
Question
What am I doing wrong in my config?
Solved!
Changed development.rb to:
config.cache_store = :redis_cache_store, { url: 'redis://127.0.0.1:6379/0' }

Django 1.6 not loading css files

Im using Django 1.6 version over apache webserver on windows.
Im not able to load the css file when accesisng the
DJango admin panel ,once i login also im not able to load the css file
href="/static/admin/css/base.css"
PROJECT_ROOT = 'D:/DjangoProjects/firstproject/firstproject'
STATIC_ROOT = os.path.join(PROJECT_ROOT,'static')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
# empty
)
Am i missing anything?
Run
python manage.py collectstatic
to add the admin files to static.
You should set a static url different than the static folder name - not required, but recommended
STATIC_URL = '/public/'
STATIC_ROOT = os.path.join(PROJECT_ROOT,'static')
Create an alias on the virtualhost (/etc/apache2/sites-avaliable/you_site.conf) for the STATIC_ROOT
Alias /public /var/www/public_html/your_project/static
<Directory /var/www/public_html/your_project/static>
Order allow,deny
Allow from all
</Directory>
Restart apache

Different php ini files by directory or alias in lighttpd

Take 2 domains: www.domain.com and sub.domain.com. Each hosted on the same server at /home/www and /home/sub respectively and using a different php.ini file through vhost configuration within lighttpd.
fastcgi.server = ( ".php" =>
((
"bin-path" => "/usr/bin/php5-cgi -c /home/www/php.ini"
))
)
$HTTP["host"]=="sub.domain.com" {
fastcgi.server = ( ".php" =>
((
"bin-path" => "/usr/bin/php5-cgi -c /home/sub/php.ini"
))
)
}
Is it possible to enable www.domain.com/sub to serve the content of sub.domain.com while still using the appropriate php.ini?
The major difference in the php.ini files we are using is the include_path. Is there an alternative way to alter this through the server config by directory or alias? Or within a single php.ini?
The motivation for this is that we only have an SSL certificate for the main www domain, but wish to serve sub content via SSL on the primary domain path.
Using lighttpd on debian.
Don't know if it's still valid, but I followed this a few years ago... sadly I don't use lighttp where I work right now so can't verify it will still work.
http://www.cyberciti.biz/tips/custom-phpini-file-for-each-domain-user.html

My Rails 3 site won't start on Ubuntu/Apache2/Passenger

This server runs on Ubuntu 10.04, particularly on Linode VPS.
Passenger Error:
A source file that the application requires, is missing.
It is possible that you didn't upload your application files correctly. Please check whether all your application files are uploaded.
A required library may not installed. Please install all libraries that this application requires.
Further information about the error may have been written to the application's log file. Please check it in order to analyse the problem.
Error message:
no such file to load -- bundler
Exception class:
LoadError
Application root:
/srv/rails_app/current
I do have bundler installed, I know this because I did "bundle".
Here is my apache configs:
/etc/apache2/sites-enabled/000-default.conf:
<VirtualHost *:80>
PassengerRoot /usr/local/rvm/gems/ruby-1.9.2-p0/gems/passenger-2.2.15
PassengerRuby /usr/local/rvm/rubies/ruby-1.9.2-p0/bin/ruby
ServerName 173.230.152.41
DocumentRoot /srv/rails_app/current/public
<Directory "/srv/rails_app/current/public">
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
/etc/apache2/apache2.conf:
#
# Based upon the NCSA server configuration files originally by Rob McCool.
#
# This is the main Apache server configuration file. It contains the
# configuration directives that give the server its instructions.
# See http://httpd.apache.org/docs/2.2/ for detailed information about
# the directives.
#
# Do NOT simply read the instructions in here without understanding
# what they do. They're here only as hints or reminders. If you are unsure
# consult the online docs. You have been warned.
#
# The configuration directives are grouped into three basic sections:
# 1. Directives that control the operation of the Apache server process as a
# whole (the 'global environment').
# 2. Directives that define the parameters of the 'main' or 'default' server,
# which responds to requests that aren't handled by a virtual host.
# These directives also provide default values for the settings
# of all virtual hosts.
# 3. Settings for virtual hosts, which allow Web requests to be sent to
# different IP addresses or hostnames and have them handled by the
# same Apache server process.
#
# Configuration and logfile names: If the filenames you specify for many
# of the server's control files begin with "/" (or "drive:/" for Win32), the
# server will use that explicit path. If the filenames do *not* begin
# with "/", the value of ServerRoot is prepended -- so "/var/log/apache2/foo.log"
# with ServerRoot set to "" will be interpreted by the
# server as "//var/log/apache2/foo.log".
#
### Section 1: Global Environment
#
# The directives in this section affect the overall operation of Apache,
# such as the number of concurrent requests it can handle or where it
# can find its configuration files.
#
#
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# NOTE! If you intend to place this on an NFS (or otherwise network)
# mounted filesystem then please read the LockFile documentation (available
# at <URL:http://httpd.apache.org/docs-2.1/mod/mpm_common.html#lockfile>);
# you will save yourself a lot of trouble.
#
# Do NOT add a slash at the end of the directory path.
#
ServerRoot "/etc/apache2"
#
# The accept serialization lock file MUST BE STORED ON A LOCAL DISK.
#
#<IfModule !mpm_winnt.c>
#<IfModule !mpm_netware.c>
LockFile /var/lock/apache2/accept.lock
#</IfModule>
#</IfModule>
#
# PidFile: The file in which the server should record its process
# identification number when it starts.
# This needs to be set in /etc/apache2/envvars
#
PidFile ${APACHE_PID_FILE}
#
# Timeout: The number of seconds before receives and sends time out.
#
Timeout 300
#
# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.
#
KeepAlive On
#
# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.
#
MaxKeepAliveRequests 100
#
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
#
KeepAliveTimeout 15
##
## Server-Pool Size Regulation (MPM specific)
##
# prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 150
MaxRequestsPerChild 0
</IfModule>
# worker MPM
# StartServers: initial number of server processes to start
# MaxClients: maximum number of simultaneous client connections
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadsPerChild: constant number of worker threads in each server process
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_worker_module>
StartServers 2
MinSpareThreads 25
MaxSpareThreads 75
ThreadLimit 64
ThreadsPerChild 25
MaxClients 150
MaxRequestsPerChild 0
</IfModule>
# event MPM
# StartServers: initial number of server processes to start
# MaxClients: maximum number of simultaneous client connections
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadsPerChild: constant number of worker threads in each server process
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_event_module>
StartServers 2
MaxClients 150
MinSpareThreads 25
MaxSpareThreads 75
ThreadLimit 64
ThreadsPerChild 25
MaxRequestsPerChild 0
</IfModule>
# These need to be set in /etc/apache2/envvars
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
#
# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives. See also the AllowOverride
# directive.
#
AccessFileName .htaccess
#
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<Files ~ "^\.ht">
Order allow,deny
Deny from all
Satisfy all
</Files>
#
# DefaultType is the default MIME type the server will use for a document
# if it cannot otherwise determine one, such as from filename extensions.
# If your server contains mostly text or HTML documents, "text/plain" is
# a good value. If most of your content is binary, such as applications
# or images, you may want to use "application/octet-stream" instead to
# keep browsers from trying to display binary files as though they are
# text.
#
DefaultType text/plain
#
# HostnameLookups: Log the names of clients or just their IP addresses
# e.g., www.apache.org (on) or 204.62.129.132 (off).
# The default is off because it'd be overall better for the net if people
# had to knowingly turn this feature on, since enabling it means that
# each client request will result in AT LEAST one lookup request to the
# nameserver.
#
HostnameLookups Off
# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
# container, error messages relating to that virtual host will be
# logged here. If you *do* define an error logfile for a <VirtualHost>
# container, that host's errors will be logged there and not here.
#
ErrorLog /var/log/apache2/error.log
#
# LogLevel: Control the number of messages logged to the error_log.
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
#
LogLevel warn
# Include module configuration:
Include /etc/apache2/mods-enabled/*.load
Include /etc/apache2/mods-enabled/*.conf
# Include all the user configurations:
Include /etc/apache2/httpd.conf
# Include ports listing
Include /etc/apache2/ports.conf
#
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
# If you are behind a reverse proxy, you might want to change %h into %{X-Forwarded-For}i
#
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
#
# Define an access log for VirtualHosts that don't define their own logfile
CustomLog /var/log/apache2/other_vhosts_access.log vhost_combined
# Include of directories ignores editors' and dpkg's backup files,
# see README.Debian for details.
# Include generic snippets of statements
Include /etc/apache2/conf.d/
# Include the virtual host configurations:
Include /etc/apache2/sites-enabled/
LoadModule passenger_module /usr/local/rvm/gems/ruby-1.9.2-p0/gems/passenger-2.2.15/ext/apache2/mod_passenger.so
So how do I go about getting this working?
You need to follow RVM's instructions for generating a passenger wrapper script to use on your PassengerRuby line. Without it, you won't have the proper environment variables set, and Apache won't be able to find the gems installed in that RVM install.
A follow up to #Chris's answer. If your on Ubuntu and using Apache do the following:
rvm install 1.9.2
rvm 1.9.2 --passenger
gem install passenger
rvmsudo passenger-install-apache2-module
Then in your apache.conf add/modify the following lines:
LoadModule passenger_module /usr/local/rvm/gems/ruby-1.9.2-p0/gems/passenger-2.2.15/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/rvm/gems/ruby-1.9.2-p0/gems/passenger-2.2.15
PassengerRuby /usr/local/bin/passenger_ruby
This worked for me, after hours of trawling SO and the rest of the internet.
James
It should be noted that Passenger 3 supports RVM natively without special instructions. The Passenger instructions on the RVM website will become obsolete.

Resources