Apache2 with Perl, PHP, Python and Ruby on Debian 5
- March 14th, 2009
- Posted in Internet . Linux . Server
- By jzerbe
- Write comment
This install assumes a semi-clean Debian 5 install and some access to a root console. The node must have around 220MB ram +/- 20 MB (or a large swap partition and a fast hard drive). The initial installs of some of these services take a heavy toll on ram. Tweaking will be done to speed up the services. This is meant as a multi-user development server, not a production server. I will be working on getting this working on nginx, so the speed and performance will be much better. For ease of installation, apache2 will have to do.
To do this with <400MB of ram we need to keep the applications that apt-get installs from starting.
1) Create a file /usr/sbin/policy-rc.d containing:
#!/bin/sh
exit 1012) chmod +x /usr/sbin/policy-rc.d
After that, packages will install correctly, but not start.
Once you’re done and ready to snapshot your pristine chroot/image, just delete that file. That will let the service start as normal on future boots.
http://ubuntuforums.org/showthread.php?t=856815
install everything we need in one big apt-get install command
apt-get install ssh mysql-server apache2 php5 phpmyadmin openssl vsftpd libapache2-mod-python libapache2-mod-ruby rubygems libapache2-mod-perl2 libapache2-mod-wsgi libapache2-reload-perl libapache2-request-perl libapache2-mod-fcgid libfcgi-ruby1.8 libmysql-ruby libapache2-mod-scgi ruby libzlib-ruby rdoc irb rubygems rails eruby
Once the installation is done, remove “/usr/sbin/policy-rc.d” – rm /usr/sbin/policy-rc.d – so that the various applications will be able to start.
I don’t know a whole lot about exim4, so I just start it without messing with the config files.
/etc/init.d/exim4 start
edit mysql config file – /etc/mysql/my.cnf
I like to comment out the bind-address line so that I can access the mysql database remotely in my other test environments.
start it when done: /etc/init.d/mysql start
edit vsftpd config file to your liking – /etc/vsftpd.conf
and start it: /etc/init.d/vsftpd start
edit apache2 main configuration file so that it takes up less ram
vi /etc/apache2/apache2.conf
—- Start File Excerpt —-
#
# Timeout: The number of seconds before receives and sends time out.
#
Timeout 60
#
# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to “Off” to deactivate.
#
KeepAlive Off
#
# 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 1
MinSpareServers 1
MaxSpareServers 1
MaxClients 3
MaxRequestsPerChild 20
</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 1
MaxClients 20
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 20
</IfModule>
—- End File Excerpt —-
enable various apache2 modules that we need
a2enmod ssl
a2enmod rewrite
a2enmod suexec
a2enmod include
edit apache vhost configuration file [/etc/apache2/sites-available/default] or .htaccess file to enable perl, python, and ruby. php should already be setup and good to go.
—- Start File Excerpt —-
<VirtualHost *:80>
ServerAdmin jzerbe@lizardking.biz
DocumentRoot /home/jason/www/
<Directory /home/jason/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
AddHandler mod_python .py
PythonHandler mod_python.publisher
PythonDebug On
</Directory>
<Directory /home/jason/www/>
Options +ExecCGI
AddHandler cgi-script rb cgi pl
</Directory>
</VirtualHost>
—- End File Excerpt —-
finally start apache2
/etc/init.d/apache2 start
To test that this works, try the following test scripts: test.rb, test.pl, test.py, and test.php.
For more information about the ruby on rails installation see this howtoforge.com article.
On a side note: I was doing this on a vmware node and ran out of space, expanding a vmdisk is pretty easy to do: 1) cd into VMware Workstation/Server directory 2) vmware-vdiskmanager -x [500MB/5GB/etc.] "[path to vmdisk].vmdk" 3) program expands virtual disk.

I followed most of the instructions here and they work fine. I’m running everything out of /var/www at this point and I was wondering if changing it to be in my home directory (/home/ryan/) would fix the permission problem I’m having. PHP files run fine in /var/www but pl, rb and py files throw a 500 error when run unless I change their permissions (I used chmod -R 777 ./ because I have no idea what I’m doing.)
Thanks.
well it’s not like setting them to 777 is all that bad, unless the scripts in question could be used for malicious purposes. you could always try chown(ing) the directories and files in question to the www-data user (the apache daemon).
chown www-data:www-data -R /absolute/path/to/contentSystem users can be set to be chrooted into their home directory at login on vsftpd, which is why I like setting apache to run content from users’ home dirs. Although, you will still have to set your scripts and whatnot to 775 or 777 depending on your system (if not chown’d).
forgot to mention, configuration to use ~60MB RAM for MySQL can be found here: http://wiki.vpslink.com/Low_memory_MySQL_/_Apache_configurations
for more information on the vmware virtual disks manager – http://pubs.vmware.com/server1/vm/wwhelp/wwhimpl/common/html/wwhelp.htm?context=vm&file=disks_server.7.34.html#1088023