Can not run app using fcgi of perl Dancer - perl

I am testing to deploy the tester example of Dancer using fcgi. But it just didn't work.
I keep getting the error message:
File does not exist: /home/tester/MyApp/public/dispatch.fcgi/
However, this app can run successfully with cgi. And I have made the changes to http.conf according to dancer's deployment manual.
Can someone pointing me to some solutions or possible reasons for this error?
below is the http.conf:
<VirtualHost *:80>
ServerName localhost
# /srv/www.example.com is the root of your
# dancer application
DocumentRoot /home/tester/MyApp/public
ServerAdmin you#example.com
<Directory "/home/tester/MyApp/public">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
AddHandler fastcgi-script .fcgi
</Directory>
ScriptAlias / /home/tester/MyApp/public/dispatch.fcgi/
ErrorLog /var/log/apache2/MyApp-error.log
CustomLog /var/log/apache2/MyApp-access_log common
</VirtualHost>
Thank you

I don't think that ScriptAlias is what you want to be using. From the documentation...
The ScriptAlias directive has the same behavior as the Alias
directive, except that in addition it marks the target directory as
containing CGI scripts that will be processed by mod_cgi's cgi-script
handler.
Basically Apache looks for a directory called '/home/tester/MyApp/public/dispatch.fcgi/' and every file in this dir is processed through mod_cgi. In this case it can't be found since it's a regular file.
Have you tried using mod_rewrite? My httpd config for Dancer is pretty much the same as yours except I'm using mod_rewrite
DocumentRoot /home/user/src/MyApp/public
<Directory "/home/user/src/MyApp/public">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
AddHandler fcgid-script .fcgi #using fcgid instead of fastcgi
</Directory>
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /dispatch.fcgi$1 [QSA,L]

Related

Apache2 config - sites-enabled, problem with RewriteRule

I have upgraded my cloud service (owncloud -> nexcloud) and now need to get rid of the string "/apps/gallery" from any link that uses it.
What I currently have in /etc/apache2/sites-enabled/000-default.conf:
Listen 80
Listen 443
<VirtualHost *:80>
ServerName ***
DocumentRoot ***
RewriteEngine on
RewriteRule ^/apps/gallery/s/.*$ /s/ [L]
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:443>
ServerName ***
DocumentRoot ***
RewriteEngine on
RewriteRule ^/apps/gallery/s.*$ /s [L]
SSLEngine on
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/***/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/***/privkey.pem
</VirtualHost>
Rewrite rule does not work and I can't get anything from logs (error and access log)...
I'm restarting apache with sudo service apache2 restart - is it enough to load new config?
Any help would be much appreciated!
------ EDIT
Following mode_rewrite manual, I have changed rewrite part to this, but still the problem exist
RewriteEngine on
RewriteRule ^/apps/gallery(.*)$ $1 [NC,R=301]

Perl files in Virtualhosts cgi-bin are always downloaded (Debian 6 and Apache2)

I have been tearing my hair out trying to get this working but no matter what I do I can't get .pl files to execute in the cgi-bin of my virtual directory. I have been searching for solutions for the past 4 hours and have tried everything I have come across, and nothing works for me. Perl files are executing perfectly for my default site, just not for my virtual host. The only mopdified file in my Apache2 configuration is the /etc/apache2/sites-available/default file, and currently it is as follows (except for the sitename):
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
<Directory /var/www/cgi-bin>
Options +ExecCGI
AllowOverride All
AddHandler cgi-script cgi pl
Order allow,deny
allow from all
</Directory>
# ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
# <Directory "/usr/lib/cgi-bin">
# AllowOverride All
# Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
# Order allow,deny
# Allow from all
# </Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAlias subdom.mysite.com
DocumentRoot /var/www/subdom
<Directory /var/www/subdom/cgi-bin>
Options +ExecCGI
AllowOverride All
AddHandler cgi-script cgi pl
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Any and all help is very much appreciated.
I think it is a typo: You need a period before pl.
AddHandler cgi-script .cgi .pl
Also check this: How do I configure Apache 2 to run Perl CGI scripts?
This sounds and looks familiar:
In my case, I made a mistake with my ScriptAlias directive. I uncommented the original one, but forgot to configure a new one.
As soon as I correctly changed and saved my sites-available/default config file from this:
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
.. to this:
ScriptAlias /cgi-bin/ /var/www/cgi-bin/
<Directory "/var/www/cgi-bin">
.. and reloaded apache2, it just worked: it stopped displaying my scripts as text, and started running them as a script. Also, it no longer displayed /var/www/cgi-bin as a directory in the browser, but now correctly displays the error:
Forbidden
You don't have permission to access /cgi-bin/ on this server.

Mod rewrite virtual host and Zend

My Apache config:
DocumentRoot /var/www
<VirtualHost *:80>
Alias /T "/var/www/Test"
<Directory /var/www/Test>
Options Indexes FollowSymLinks MultiViews
#AllowOverride ALL
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel debug
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
SetEnv APPLICATION_ENV "development"
Alias /N "/var/www/NCAA/public"
<Directory /var/www/NCAA/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride ALL
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel debug
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
My .htacess file in /var/www/NCAA/public:
RewriteEngine On
RewriteBase /N/
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
I can go to files in localhost/T, but I get 404 for /localhost/N I get this in my apache log:
[Sun Nov 20 16:32:37 2011] [error] [client 127.0.0.1] File does not exist: /var/www/N,
so I'm not sure what I am doing wrong. I want 1 domain to be a regular domain with an alias and the other is a Zend app with a mod rewrute for the index.php
Thanks
Do you really need the NCAA app to be accessed under http://localhost/N? Is it acceptable to access it under a different url, like http://local.ncaa/?
If so, then a virtual host entry could look like:
<VirtualHost *:80>
DocumentRoot /var/www/NCAA/public
ServerName local.ncaa
SetEnv APPLICATION_ENV development
<Directory /var/www/NCAA/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride ALL
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel debug
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Then the standard ZF .htaccess can be used (no rewrite base required):
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

apache2: how to find out why I get a 403 error?

That is from the apache error_log:
[Mon Oct 17 17:55:42 2011] [error] [client 127.0.0.1] (13)Permission denied: access to /index.html denied
In /etc/apache2/vhosts.d I've created this file:
<VirtualHost 127.0.0.1:3000>
DocumentRoot "/home/mm/lib/vokabeltrainer"
ServerName localhost:3000
<Directory "/home/mm/lib/vokabeltrainer">
Options FollowSymLinks ExecCGI
AddHandler cgi-script .pl
IndexIgnore *
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}/public/%{REQUEST_URI} -f
RewriteRule ^(.*) public/$1 [L]
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI} !-f
RewriteRule ^(.*) vokabeltrainer.pl [L]
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
The /etc/apache2/listen.conf looks like this:
Listen 127.0.0.1:3000
NameVirtualHost 127.0.0.1:3000
For testing, I've modified the folder like chmod -R 0777 /home/mm/lib/vokabeltrainer
When I run the vokabeltrainer.pl (Mojolicious::Lite script) with morbo development server it works.
Has somebody a clue where I should look?
As Ikegami pointed out, my first problem was that I didn't consider the /home/mm/lib part of the path: the lib-directory didn't have enough rights so I had to ad the needed rights.
Then I changed the path in the shebang form /usr/local/bin/perl to /usr/bin/perl and installed Mojolicious::Lite for the /usr/bin/perl.
The last thing I had to do, was writing the url like this http://localhost:3000/vokabeltrainer.pl/random instead of http://localhost:3000/random.
(In the Pretty "Web 2.0" URLs at mojo/wiki/Apache-deployment is shown a way to keep the short url)

Apache virtual host on a specific directory

I need my site to have a virtual host on a specific directory for my zend application. When user enters www.example.com it should go to normal document root but when user navigates to www.example.com/cms it should go to /var/www/cms/public which its .htaccess file is like this:
SetEnv APPLICATION_ENV development
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
On localhost I added this lines to /etc/apache/httpd-vhosts.conf:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "/var/www/cms/public"
ServerName persian_literature
# This should be omitted in the production environment
SetEnv APPLICATION_ENV development
<Directory "/var/www/cms/public">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Now http://localhost/ goes to /var/www/cms/public and every thing works. My question is how should I change change above code, to force http://localhost/ to be the normal directory root (so I could use other applications) and http://localhost/cms to be the virtual host?
A virtual host is done at the hostname/domainname level, not at a directory level. You can use an alias to point the URI /cms to some other directory on your server by putting
Alias /cms /var/www/cms/public
in a .conf file (this will not work in .htaccess)
Maybe a symlink (symbolic link)? You still should have the entry of course. And you'll have to put in the config (vhost config I think, maybe .htaccess) that apache should follow the symlink.