Shell script – install LAMP with dependencies for PHP/mod_fcgi

This script is intended for fresh Linux installs to provide support for the LAMP stack running with mod_fcgid instead of the default mod_php Apache module.


Version 1.1 – August 18 2011

  • Added apt-get update to refresh package list
  • Added MySQL server
  • Added php5-gd library (to comply with Drupal 7 requirements)
  • Added PDO MySQL driver (to comply with Drupal 7 requirements)
  • Moved specific php.ini extensions and fixes to separate custom.ini file
  • Added restart of proftpd

To run the script, begin with pasting it into a new file:


Make it executable:

chmod 755

Run it:


To easily set up sites and users, read Shell script: create virtual hosts with PHP/fastCGI (mod_fcgi)

# Shell script to install LAMP with dependencies for running PHP applications
# with mod_fcgi
# -------------------------------------------------------------------------
# Version 1.1 (August 18 2011)
# -------------------------------------------------------------------------
# Copyright (c) 2011 Finn Hensner <>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
apt-get update
aptitude install apache2 apache2-suexec libapache2-mod-fcgid php5-cgi
a2dismod php5
a2enmod rewrite
a2enmod suexec
a2enmod include
a2enmod fcgid

apt-get install mysql-server
apt-get install php5-gd
apt-get install php5-common php5-mysql

sleep 1
echo "Adding extensions and fixes to custom ini"
cat > /etc/php5/conf.d/custom.ini << EOF
cgi.fix_pathinfo = 1

sleep 1
echo "Add server name to Apache config"
echo "ServerName" >> /etc/apache2/apache2.conf

sleep 1
echo "Installing ProFTPd server"
apt-get purge proftpd
apt-get install proftpd
#jail users in their home directory
echo -e "<Global>\nDefaultRoot ~\n</Global>" >> /etc/proftpd/proftpd.conf

sleep 1
echo "Removing default virtual host."
rm /etc/apache2/sites-available/default
rm /etc/apache2/sites-enabled/default-000

sleep 1
echo "Restarting apache2 and proftpd"
service apache2 restart
service proftpd restart

Post a comment

You may use the following HTML:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>