Apache 2.2¶
The Apache HTTP Server is the world’s most used web server (according to Wikipedia). It is open source, mature and reliable.
To serve a Sulu website with Apache, you need to adapt your hosts file, create a virtual host configuration file and restart your server.
Host Name Configuration¶
Add the domain of your site to the hosts file. Depending on your operating system, this file can be found in different places:
- Unix:
/etc/hosts
- Windows:
%SystemRoot%\System32\drivers\etc\hosts
On a development machine, we could use the domain sulu.lo (“lo” stands for “local”). Add that domain to the end of the hosts file:
# ...
127.0.0.1 sulu.lo
When you type the URL http://sulu.lo in your browser, the browser will now load the page from your computer.
Note
You may need to restart your browser after changing the hosts file.
But before it works, we need to tell Apache what to do when that URL is loaded.
Virtual Host Configuration¶
Let’s add the Apache configuration file for the sulu.lo domain.
<VirtualHost *:80>
DocumentRoot "/var/www/sulu.lo/web"
ServerName sulu.lo
<Directory "/var/www/sulu.lo/web">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
SetEnv SYMFONY_ENV dev
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/svg+xml "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType text/css "access plus 1 month"
ExpiresByType font/woff2 "access plus 1 month"
ExpiresByType font/woff "access plus 1 month"
ExpiresByType font/eot "access plus 1 month"
ExpiresByType font/ttf "access plus 1 month"
</IfModule>
<IfModule mod_deflate.c>
SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
</Directory>
</VirtualHost>
Note
It is a good practice to create a virtual host for each of your Sulu projects. They are separated by domain and you’ll got full control on what you expose.
MAMP Pro¶
In general you should configure your vHost like the Apache 2.2 paragraph above describes it.
If you want to enable the dev-environment (including the debug toolbar) you have to be sure that the
vHost environment variable (SetEnv SYMFONY_ENV dev
) is set properly
and you configured a DEV-domain within your webspace.xml.

File Permissions¶
Finally, we need to fix the permissions of our project so that the web server is able to read and write them.
This command is different for sulu-standard and sulu-minimal.
sulu-standard¶
Run the following commands on Linux:
HTTPDUSER=`ps axo user,comm | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1`
sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX app/cache app/logs uploads uploads/* web/uploads web/uploads/* app/data
sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX app/cache app/logs uploads uploads/* web/uploads web/uploads/* app/data
Or these commands for Mac OSX:
HTTPDUSER=`ps axo user,comm | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1`
sudo chmod +a "$HTTPDUSER allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs uploads uploads/* web/uploads web/uploads/* app/data
sudo chmod +a "`whoami` allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs uploads uploads/* web/uploads web/uploads/* app/data
Or these commands for Windows (with IIS web server):
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule -ArgumentList @("IUSR","FullControl","ObjectInherit, ContainerInherit","None","Allow")
$folders = "app\cache", "app\logs", "app\data", "uploads", "uploads\*", "web\uploads", "web\uploads\*"
foreach ($f in $folders) { $acl = Get-Acl $f; $acl.SetAccessRule($rule); Set-Acl $f $acl; }
sulu-minimal¶
Run the following commands on Linux:
HTTPDUSER=`ps axo user,comm | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1`
sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX var/cache var/logs var/uploads var/uploads/* web/uploads web/uploads/* var/indexes var/sessions
sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX var/cache var/logs var/uploads var/uploads/* web/uploads web/uploads/* var/indexes var/sessions
Or these commands for Mac OSX:
HTTPDUSER=`ps axo user,comm | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1`
sudo chmod +a "$HTTPDUSER allow delete,write,append,file_inherit,directory_inherit" var/cache var/logs var/uploads var/uploads/* web/uploads web/uploads/* var/indexes var/sessions
sudo chmod +a "`whoami` allow delete,write,append,file_inherit,directory_inherit" var/cache var/logs var/uploads var/uploads/* web/uploads web/uploads/* var/indexes var/sessions
Or these commands for Windows (with IIS web server):
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule -ArgumentList @("IUSR","FullControl","ObjectInherit, ContainerInherit","None","Allow")
$folders = "var\cache", "var\logs", "var\indexes", "var\sessions", "var\uploads", "var\uploads\*", "web\uploads", "web\uploads\*"
foreach ($f in $folders) { $acl = Get-Acl $f; $acl.SetAccessRule($rule); Set-Acl $f $acl; }