Do CGI and mod_perl play nicely together? - apache2

I've got an apache web server (without mod_perl) that's been running just fine for a long time.
It has been suggested that we use mod_perl to improve the performance of some scripts.
I want to go ahead and install mod_perl on the server, which seems to be a relatively straightforward process, but I'm confused by some of the stuff coming up on Google searches.
If I install mod_perl (through the debian repositories), will all of my existing CGIs suddenly start "using mod_perl" and exhibiting potentially wonky behavior?
Or is there some configuration in apache that needs to be done for an old CGI to "start using mod_perl"?
Apologies if this is a straightforward answer but I am confused by the terminology being used in multiple ways in the documentation.

mod_perl has to be configured in your httpd.conf to be enabled. So not every script on your server will start to use mod_perl automatically.
Usually, you enable mod_perl per VHost. A usual configuration of mod_perl for a vhost looks like this:
<VirtualHost some.funny-domain.com>
ServerName some.funny-domain.com
ServerAdmin admin#funny-domain.com
DocumentRoot /data/path/to/root/
Perlrequire /data/path/to/startup.pl
PerlModule Apache2::Reload
PerlInitHandler Apache2::Reload
PerlModule Apache2::RequestRec
ScriptAlias /cgi-bin/ "/data/path/to/root/cgi-bin/"
<Location /cgi-bin/>
SetHandler perl-script
PerlResponseHandler ModPerl::Registry
PerlOptions +ParseHeaders
PerlOptions +SetupEnv
Options +ExecCGI
</Location>
CustomLog logs/access.log combined
ErrorLog logs/error.log
</VirtualHost>
Be carefull with the automated install-process! It may enable mod_perl on the wrong host for some reason! BackUp your config and apache-installation first to be able to "roll back" easily.
Comment: The line "Perlrequire /data/path/to/startup.pl" is not required. It is optional and sets some environment variables for the running scripts under the mod_perl env.

Related

Enable server-side includes in Apache2 for selected domains

I'm running Apache2 (2.4.29-lubuntu4.11) on Ubuntu Server 18.04.
I see documentation for enabling server-side includes (SSI) when I google, but it's always done in httpd.conf (modern apache2.conf), etc. I suspect these are older posts. I manage my domains out of /etc/apache2/sites-available/some-domain.conf (individual vhost configuration) files and I don't wish to enable server-side includes except for a couple of domains.
Can the effect of enabling SSI be limited to only selected domains?
How is this done specifically? I've tried, for example,
<VirtualHost *:80>
...
AddType text/html .shtml
AddHandler server-parsed .shtml
AddOutputFilter INCLUDES .shtml
Options Includes
</VirtualHost>
How do Options, AddType, AddHandler, AddOutputFilter, etc., done in some-domain.conf, interact with what's in /etc/apache2/apache2.conf?
You can do it in your . htaccess as well as just enabling it in a container.
For more information please take a look at this documentation: https://httpd.apache.org/docs/current/howto/ssi.html
To permit SSI on your server, you must have the following directive
either in your httpd.conf file, or in a .htaccess file:
Options +Includes
This tells Apache that you want to permit files to
be parsed for SSI directives.
To enable SSI for a specific domain or directory you can also put it in a container inside a virtualhost configuration:
<Directory /example/dir>
...
Options ...someOtherOptions... +Includes
...
</Directory>
I think your last question (site conf or Apache conf) was already answered here.

Apache localhost authentication

I am trying to setup up basic authentication to a folder on my localhost running apache. Currently the app runs fine without authentication. I have setup a virtual host so I can access my application through dev.myapp.com
The code I add to my .htaccess file to force authentication is:
<Directory "/Users/myusername/Sites/dev.myapp.com">
AuthType Basic
AuthName Test
AuthBasicProvider file
AuthUserFile /etc/apache_users
Require valid-user
</Directory>
I have created a user.
When I type dev.myapp.com into the browser I get an internal server error. I am fairly new to apache. A point in the right direction would be appreciated.
Thanks.
First off, using .htaccess is a bit slower and requires that you have set the AllowOverride directive accordingly. It is recommended that you instead use httpd.conf to establish basic authentication. The Apache documentation explains all of this so check out this link http://httpd.apache.org/docs/2.2/howto/auth.html.
Regardless, I think I see the error. Your <Directory> tag looks a little odd. I understand the name of your site is dev.my.app.com but is that the actual name of the folder where the site dev.myapp.com points to on your server? Your httpd.conf file should have an entry like this:
<VirtualHost *>
DocumentRoot "document/root/path"
Other directives here
</VirtualHost>
The DocumentRoot is where Apache directs all incoming web traffic. If you are trying to establish authentication for your entire site, the value of DocumentRoot is most likely what you would want in your Directory tag ... making it <Directory /document/root/path>.
To locate httpd.conf look in in /etc/apache2/. Make sure to restart your server after you change the file (sudo /etc/init.d/apache2 restart). Hope that helps, please update if you haven't already resolved the problem.

Vagrant 403 Forbidden

I've been running Vagrant successfully for about a week. Last night I ran vagrant reload and now I can no longer access my sites.
VirtualBox version 4.2.16
Vagrant version 1.2.7
My Vagrantfile and bootstrap.sh: https://github.com/kriskd/vagrant-settings
Running on Mac
My files live at /vagrant/Sites. At first my "welcome page" which lives at /vagrant/Sites rendered at
http://localhost:4567/
All my projects are folders under Sites. For example, /vagrant/Sites/test won't render index.html. I get the following
Forbidden
You don't have permission to access / on this server.
Apache/2.4.6 (Ubuntu) Server at localhost Port 4567
The vhost looks like:
<VirtualHost *:80>
DocumentRoot "/vagrant/Sites/test"
ServerName test
<Directory "/vagrant/Sites/test">
AllowOverride All
</Directory>
</VirtualHost>
The vhosts are owned by root. My project files are owned by vagrant and chmod'ed 0777.
After no success, I did a full vagrant destroy followed by vagrant up and then the localhost host welcome page stopped rendering as well with the forbidden error.
My hunch is that this is not a vagrant issue at all but solely an Apache configuration glitch. There are a few things I can think to check.
First, obviously, is to confirm that the user that apache is running under has read and execute permissions for the DocumentRoot folder.
Since you mentioned Apache 2.4, there have been changes in the configs from 2.2. Make sure your Allow from all statements now read Require all granted. (If you were still on 2.2, you'd want to make sure they said Allow from all instead of Deny from all.) In either case, you can set this in each <VirtualHost> individually, or set a default in your <Directory /> block of the main httpd.conf file.
Getting more obscure, you could check for selinux, although I'm pretty sure this isn't present in Ubuntu by default. (It is in CentOS, for example.)
This is solved and in the end came down to some very simple things.
Use "Require All granted" instead of "Allow from All"
Put each websites' content at the same level namely /vagrant/Sites/default, /vagrant/Sites/test, /vagrant/Sites/real-site
Add .conf extension to vhost names such as test.conf and real-site.conf
Add AllowOverride All to vhosts to respect sites' .htaccess file (I realize that was in my original post, it got lost as I tried to solve this)
All very basic things that eluded me for a better part of a week. I hope this can help someone else.
I had the same problem when changing the DocumentRoot.
Since you've changed your DocumentRoot to "/any/path/foo/bar", make sure you have the permissions set on "apache2.conf" for this path.
Search for:
<Directory /any/path/foo/bar>
in apache2.conf
And add a new block like this:
<Directory /any/path/foo/bar>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
And my guess is that everything is gonna be fine!
cd /etc/apache2/sites-available
for file in `ls *`; do sed 's/\(.*<\/Directory.*>\)/Require\ all\ granted\n\1/' $file > $file.new;mv $file.new $file ; done;
because it worked before, I would not waste time on fix file by file

Apache2 cannot run WSGI script

I'm installing Reviewboard on linux, I have copied the config provided by the install package to httpd.conf
<VirtualHost *:80>
ServerName localhost
DocumentRoot "/usr/www/reviewboard/htdocs"
# Error handlers
ErrorDocument 500 /errordocs/500.html
WSGIPassAuthorization On
WSGIScriptAlias "/reviewboard" "/usr/www/reviewboard/htdocs/reviewboard.wsgi/reviewboard"
<Directory "/usr/www/reviewboard/htdocs">
AllowOverride All
Options -Indexes FollowSymLinks
Allow from all
</Directory>
# Alias static media requests to filesystem
Alias /reviewboard/media "/usr/www/reviewboard/htdocs/media"
Alias /reviewboard/errordocs "/usr/www/reviewboard/htdocs/errordocs"
Alias /reviewboard/favicon.ico "/usr/www/reviewboard/htdocs/media/rbcommons/images/favicon.png"
</VirtualHost>
However, when I access "http://SITE/reviewboard/htdocs/reviewboard.wsgi", it just gives me the file in plain text instead of running the script
I have checked the mod_wsgi is running on apache2 by "apache2ctl -t -D DUMP_MODULES"
Did I miss any other configuration?
You should be using the URL:
http://SITE/reviewboard
and the WSGIScriptAlias directive should be:
WSGIScriptAlias "/reviewboard" "/usr/www/reviewboard/htdocs/reviewboard.wsgi"
Do be aware though that it is bad practice to be putting your whole Django site under DocumentRoot. That you are seeing the source code for the WSGI script file highlights why it is bad. That is, have an issue with your Apache configuration and you could expose all your source code for people to download. Especially bad if settings.py is in there and it contains database passwords.
Now, address those issues and update question with what you then have and what next problem is as I don't expect that to completely solve the problem because with those mistakes you should have got a different problem than what you describe, so suspect that your configuration is not even being used.

Apache addon perl script for obtaining subdomain from a wildcard

I had an issue regarding this which I've manage to fix to this stage, but the only issue is finding out how this could be achieved by perl.
This is a current structure of a link:
http://username.mydomain.com/public/name
And this is the current VirtualHost I've got:
<VirtualHost *:80>
ServerName mydomain.com
ServerAlias *.mydomain.com
<Location /public>
DAV svn
SVNParentPath /home/svn/public/{SubdomainHere}
</Location>
ErrorLog /home/svn/log/error.log
CustomLog /home/svn/log/warning.log combined
</VirtualHost>
The above shows the current VirtualHost structure, and where the subdomain pattern is required. I've looked into the mod_perl and enabled it, and also understand now I can just add the tags. However, my perl skills are limited if not none existant.
I've seen the answer here and I believe it's somewhat similar to mine but requiring more mods: https://serverfault.com/questions/85256/using-url-within-vhost-container-with-mod-perl-dynamically
Could someone show me how this could be achieved and/or point me in the right direction?
Many thanks,
Shaun
I overcame this by creating a C++ init script which auto added the config files then reloaded apache2

Resources