Installing apache 2.2, proftpd, fcgi and mysql on Ubuntu
February 16th, 2009
No comments
This how to shows you a way to install a LAMP system on a fresh Ubuntu server installation.
First we bring our package management into a current state:
sudo su apt-get update apt-get upgrade
Then we can install mysql, php, proftpd and apache:
apt-get install mysql-server mysql-client apt-get install apache2.2-common apache2-mpm-worker apache2-threaded-dev apt-get install php5-cgi libapache2-mod-fcgid apache2-suexec php-apc php5-gd php5-imagick apt-get install proftpd -> select "Servermode"
Now we create the users and group basic configuration:
addgroup ftpuser cp /bin/false /bin/ftp echo "/bin/ftp" >> /etc/shells
We create a user default, that receives all remaining requests:
useradd -g ftpuser -d /var/www/default -s /bin/ftp -m default
chown default.www-data /var/www/default
chmod 750 /var/www/default
mkdir /var/www/default/conf
mkdir -p /var/www/default/domain/{cgi-bin,exec,html,log,session,temp}
chmod 770 /var/www/default/domain/temp
chmod 777 /var/www/default/domain/session
chmod 700 /var/www/default/domain/exec
chown -R default.ftpuser /var/www/default/*
rm -rf /var/www/default/.b*
rm -rf /var/www/default/.p*
We can create now an Apache vHost for the default user:
cd /etc/apache2/sites-available/ a2dissite default rm def* -> remove the old default configuration vim default
You can insert this configuration for default:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
SuexecUserGroup default ftpuser
ServerName www.domain.tld
ServerAlias more.domains.tld
DocumentRoot /var/www/default/domain/html
DirectoryIndex index.php index.html index.htm
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory />
Order Deny,Allow
Deny from All
</Directory>
<Directory /var/www/default/domain/html>
FCGIWrapper /var/www/php-fcgid-scripts/default/php-fcgid-starter .php
Options +ExecCGI
order allow,deny
allow from all
</Directory>
ErrorLog /var/www/default/domain/log/apache_error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/www/default/domain/log/apache_access.log combined
ServerSignature On
</VirtualHost>
First we make the general fcgi configuration:
cd /etc/apache2/mods-available vim fcgid.conf
We can use the following configuration:
<IfModule mod_fcgid.c> AddHandler fcgid-script .php SocketPath /var/lib/apache2/fcgid/sock IPCConnectTimeout 20 </IfModule>
Then we can configure fcgi for the user:
a2enmod suexec cd /var/www mkdir php-fcgid-scripts chown root:root /var/www/php-fcgid-scripts cd php-fcgid-scripts mkdir default cd default touch php-fcgid-starter chmod +x php-fcgid-starter vim php-fcgid-starter
We can use the following configuration:
#!/bin/sh PHPRC="/var/www/default/conf" export PHPRC PHP_FCGI_CHILDREN=15 export PHP_FCGI_CHILDREN exec /usr/bin/php5-cgi
Now you should assign the proper rights to it:
chown -R default.ftpuser /var/www/php-fcgid-scripts/default chmod 755 /var/www/php-fcgid-scripts/default/php-fcgid-starter chattr -V +i /var/www/php-fcgid-scripts/default/php-fcgid-starter
We create a php.ini file for this vHost:
cd /var/www/default/conf wget http://www.naumann.cc/wp-content/uploads/2009/02/php.ini chown root.root php.ini
Now we can test it:
cd /var/www/default/domain/html touch index.php echo "<? phpinfo(); ?>" >> /var/www/default/domain/html/index.php chown default.ftpuser /var/www/default/domain/html/index.php a2ensite default /etc/init.d/apache2 restart
Now you can call www.domain.tld with your favorite browser.