Installing Mezzanine on Webfaction with Apache and WSGI

Mezzanine Templates and Styling

Although your site is viewable, there is no styling. First we are going to run the collecttemplates command to copy of Mezzanine’s template files to your project’s templates folder.

cd /home/<username>/webapps/mezzanine_cms/mysite
python manage.py collecttemplates

Check your templates folder, to make sure that the files are there. Now we’ll run the collectstatic to copy all static files (css, images, js, etc) to your project’s static folder.

Python manage.py collectstatic --link --noinput

The –link option tells the command to create a symbolic link. The –noinput option is so that you won’t get prompted for any input.
Now view your site. Still no styles. If you view the source the page, you will see:

<link rel="stylesheet" href="/static/css/bootstrap.css">
<link rel="stylesheet" href="/static/css/mezzanine.css">
<link rel="stylesheet" href="/static/css/bootstrap-responsive.css">

The browser is looking for the CSS files under the static folder, but Apache does not know that the folder exists, so it can’t serve to the files. So let’s update Apache config.

vi /home/<username>/webapps/mezzanine_cms/apache2/conf/httpd.conf

The commented portions are the changes.

ServerRoot "/home/<username>/webapps/mezzanine_cms/apache2" 
 
LoadModule dir_module        modules/mod_dir.so 
LoadModule env_module        modules/mod_env.so 
LoadModule log_config_module modules/mod_log_config.so 
LoadModule mime_module       modules/mod_mime.so 
LoadModule rewrite_module    modules/mod_rewrite.so 
LoadModule setenvif_module   modules/mod_setenvif.so 
LoadModule wsgi_module       modules/mod_wsgi.so 
 
#add these modules
LoadModule alias_module      modules/mod_alias.so 
LoadModule authz_host_module modules/mod_authz_host.so 
 
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined 
CustomLog /home/<username>/logs/user/access_mezzanine_cms.log combined 
ErrorLog /home/<username>/logs/user/error_mezzanine_cms.log 
KeepAlive Off 
Listen 26857 
MaxSpareThreads 3 
MinSpareThreads 1 
ServerLimit 1 
SetEnvIf X-Forwarded-SSL on HTTPS=1 
ThreadsPerChild 5 
 
#add the aliases
AliasMatch ^/([^/]*\.css) /home/<username>/webapps/mezzanine_cms/mysite/css/$1 
Alias /robots.txt /home/<username>/webapps/mezzanine_cms/mysite/static/robots.txt 
Alias /favicon.ico /home/<username>/webapps/mezzanine_cms/mysite/static/favicon.ico 
 
Alias /media/ /home/<username>/webapps/mezzanine_cms/mysite/media/ 
Alias /static/ /home/<username>/webapps/mezzanine_cms/mysite/static/ 
 
WSGIDaemonProcess mezzanine_cms processes=5 python-path=/home/<username>/webapps/mezzanine_cms:/home/<username>/webapps/mezzanine_cms/mysite:/home/<username>/webapps/mezzanine_cms/lib/python2.7 threads=1 
WSGIProcessGroup mezzanine_cms 
WSGIRestrictEmbedded On 
WSGILazyInitialization On 
 
WSGIScriptAlias / /home/<username>/webapps/mezzanine_cms/mysite/wsgi.py 
 
#add the directories
<Directory /home/<username>/webapps/mezzanine_cms/mysite/static> 
    Order deny,allow 
    Allow from all 
</Directory> 
 
<Directory /home/<username>/webapps/mezzanine_cms/mysite/media> 
    Order deny,allow 
    Allow from all 
</Directory>

I created an alias for static and media. These files will be served by Apache.

Note: I also created aliases for robots.txt and favicon.ico. For more information, view Django’s documentation.

Now restart Apache.

~/webapps/mezzanine_cms/apache2/bin/restart

Now view your site. That’s it. You should now have Apache, Wsgi, and Mezzanine working on your Webfaction-served website.

Note: You probably don’t want to change Mezzanine’s template and CSS files, so you should create an Django app, copy the template and css files into the app, and update those files only. In my previous post, I discuss how this is done. Enjoy.

Be Sociable, Share!

Checkout My New Site - T-shirts For Geeks