Skip to main content


 Quickly set up Apache, MySQL and PHP on Ubuntu optionally using FastCGI with PHP5-FPM - ideal for your busy site.



PHP5-FPM with Apache with mpm-event reduces the number of processes which can increase performance by requiring less forks and less memory overall. In case you want to switch back to the standard mode, the commands are also listed.


Install all dependencies - without actually installing the typo3 packages themselves

export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get install exim4 dbconfig-common debconf graphicsmagick lsb-base mysql-client php5 php5-cli php5-gd php5-mysql debconf

Enable multiverse and install php5-fpm

apt-get install software-properties-common -y
apt-add-repository multiverse
apt-get update
apt-get install apache2-mpm-event # might already be installed
apt-get install libapache2-mod-fastcgi php5-fpm

Create the php5-fpm configuration for apache2

cat > /etc/apache2/conf-available/php5-fpm.conf << EOF
<IfModule mod_fastcgi.c>
AddHandler php5-fcgi .php
Action php5-fcgi /php5-fcgi
Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -socket /var/run/php5-fpm.sock -pass-header Authorization
<Directory /usr/lib/cgi-bin>
    Require all granted

Tune php5 for Typo3
cat > /etc/php5/mods-available/typo3_tune.ini << EOF
; configuration for php tuning 
; priority=20
max_execution_time = 240
memory_limit = 80M
upload_max_filesize = 1G
post_max_size = 1G
max_input_vars = 1500

php5enmod gd
php5enmod mysql
php5enmod typo3_tune


Change DocumentRoot to /var/www (instead of /var/www/html )

# vi /etc/apache2/sites-enabled/000-default.conf

sed -ie 's/DocumentRoot .*/DocumentRoot \/var\/www/' /etc/apache2/sites-enabled/000-default.conf

service apache2 restart
service php5-fpm restart

Optional: Check if php5-fpm is working

cat > /var/www/info.php << EOF
<?php phpinfo(); ?>


Open http:// <yoursite> /info.php  and check for Server API = FPM/FastCGI

You should delete /var/www/info.php when done.

Enable UTF8 for mysql

Configure mysql for UTF8

cat > /etc/mysql/conf.d/utf8_charset.cnf << EOF

Create the Typo3 Database

mysqladmin create TYPO3

Allow the mysql user typo3 with password typo3 to use the above database. (use a different password !) 

echo "grant all privileges on TYPO3.* to typo3@localhost identified by 'typo3'; flush privileges;" | mysql -u root 


If you used a root password for mysql, use -p<password> here.

Set mysql root password (optional)

View current users

mysql -e "SELECT User, Host, Password FROM mysql.user;"

Set all root passwords to 'newpwd'

mysql -u root -e "UPDATE mysql.user SET Password = PASSWORD('newpwd') WHERE User = 'root'; FLUSH PRIVILEGES;"

Typo3 Installation

Get and unpack the latest Typo3 Release

cd /var/www
curl -L | tar zxpvf -
# You can also use the following to get the latest release
# wget
# wget --content-disposition
# curl -L -o typo3_src.tgz
# tar xpvf typo3_src-*.tar.gz

Create the necessary links and directories

ln -s typo3_src-* typo3_src
ln -s typo3_src/typo3
ln -s typo3_src/index.php
mkdir typo3temp
mkdir typo3conf
mkdir uploads
chown www-data.www-data typo3* uploads /var/www
chmod 2775 /var/www
chmod -R 2775 typo3* uploads
chown root:www-data -R typo3_src-*
chmod -R 775 typo3_src-*

Enable the Install Tool

touch typo3conf/ENABLE_INSTALL_TOOL

and go to the Install Tool to set up Typo3 !

http:// <yoursite> /typo3/install

Enable php5-fpm, mpm_event for apache

a2dismod mpm_prefork php5
a2enmod actions fastcgi alias mpm_event
a2enconf php5-fpm
service apache2 restart

Return to default

If you prefer to run apache with mod-php5, you can easily switch back to mod-php/mpm_prefork for apache

a2dismod mpm_event fastcgi
a2enmod actions alias mpm_prefork php5
a2disconf php5-fpm
service apache2 restart


service php5-fpm stop
service php5-fpm disable

Google Pagespeed

Enable Optimization Module

Beta Version:

curl -O
dpkg -i mod-pagespeed-beta_current_amd64.deb
service apache2 restart

Stable Version:

curl -O
dpkg -i mod-pagespeed-stable_current_amd64.deb
service apache2 restart

The bleeding edge development versions are on github :

For Typo3 you can safely enable these additional options - use ModPagespeedDisallow to disable pagespeed for certain paths.

/etc/apache2/mods-available/pagespeed.conf has the original configuration, we will add our own file with the local changes now:

cat > /etc/apache2/conf-available/local_pagespeed.conf << EOF
<IfModule pagespeed_module>
    <Location /pagespeed_admin>
        Order allow,deny
        Allow from localhost
        Allow from
        SetHandler pagespeed_admin
    <Location /pagespeed_global_admin>
        Order allow,deny
        Allow from localhost
        Allow from
        SetHandler pagespeed_global_admin
ModPagespeedFetchHttps enable
ModPagespeedEnableFilters defer_javascript
ModPagespeedEnableFilters move_css_to_head
# ModPagespeedEnableFilters prioritize_critical_css
ModPagespeedEnableFilters local_storage_cache
ModPagespeedEnableFilters sprite_images
# ModPagespeedEnableFilters insert_ga
ModPagespeedEnableCachePurge on
ModPagespeedDisallow "*/path/*"

a2enconf local_pagespeed.conf

Optimize your Webserver further

Convert .htaccess to apache config files

cat > << XEOF
for i in \$( find /var/www -name .htaccess )
ht_path=\$( dirname \$i )
# echo \${ht_conf} \${i}
cat > /etc/apache2/conf-available/\${ht_conf}.conf <<EOF
<Directory \$ht_path>
\$( cat \$i )
(cd /etc/apache2/conf-available/; a2enconf _var*)
echo "Check the configuration for AllowOverride All in these files (if any)"
find /etc/apache2/ -type f | xargs grep -li "AllowOverride.*All"
chmod 755