Path

7x / documentation / tutorials / building mobile browser and... / configuring ez publish and...


Caution: This documentation is for eZ Publish legacy, from version 3.x to 6.x.
For 5.x documentation covering Platform see eZ Documentation Center, for difference between legacy and Platform see 5.x Architecture overview.

Configuring ez Publish and the server

Creating a sub-domain is probably the most popular option for enabling users to access a mobile version of your site. Using a sub-domain (such as “mobile”, or just “m” to keep it short) keeps your mobile site part of your brand without creating confusion. A sub-domain gives you the flexibility to grow or scale back the mobile site without impacting the traditional website.

Note that this article does not cover mobile browser detection, for example if you want to automatically redirect mobile users to the mobile sub-domain whenever they visit the main domain. There are many different approaches to this, such as using an Apache module.

This section demonstrates how to set up a virtual host on the Apache web server for an eZ Publish installation located in "/var/www/example". Let's say that we want to access the eZ Publish mobile web channel by using the following URL: m.example.com

In order to achieve this, we need to set up both eZ Publish and the web server so that they respond correctly to different URL requests.

Apache configuration: virtual host settings

Assuming that...

  • eZ Publish is located in "/var/www/example"
  • the server's IP address is 128.39.140.28
  • we wish to access the eZ Publish mobile web channel using the sub-domain "m.example.com"

...edit your existing virtual host configuration for your eZ Publish site at the bottom of "httpd.conf" (or in the relevant configuration file depending on your server setup):

NameVirtualHost 128.39.140.28
 
 <VirtualHost 128.39.140.28>
 <Directory /var/www/example>
 Options FollowSymLinks
 AllowOverride None
 </Directory>
 
 <IfModule mod_php5.c>
 php_admin_flag safe_mode Off
 php_admin_value register_globals 0
 php_value magic_quotes_gpc 0
 php_value magic_quotes_runtime 0
 php_value allow_call_time_pass_reference 0
 </IfModule>
 
 DirectoryIndex index.php
 <IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteRule ^api/ index_rest.php [L]
 RewriteRule ^/([^/]+/)?content/treemenu.* /index_treemenu\.php [L]
 RewriteRule ^/var/([^/]+/)?storage/images(-versioned)?/.* - [L]
 RewriteRule ^/var/([^/]+/)?cache/(texttoimage|public)/.* - [L]
 RewriteRule ^/design/[^/]+/(stylesheets|images|javascript)/.* - [L]
 RewriteRule ^/share/icons/.* - [L]
 RewriteRule ^/extension/[^/]+/design/[^/]+/(stylesheets|flash|images|lib|javascripts?)/.* - [L]
 RewriteRule ^/packages/styles/.+/(stylesheets|images|javascript)/[^/]+/.* - [L]
 RewriteRule ^/packages/styles/.+/thumbnail/.* - [L]
 RewriteRule ^/var/storage/packages/.* - [L]
 
# Makes it possible to place your favicon at the root of your
 # eZ Publish instance. It will then be served directly.
 RewriteRule ^/favicon\.ico - [L]
 # Uncomment the line below if you want you favicon be served from the standard design.
 # You can customize the path to favicon.ico by replacing design/standard/images/favicon.ico
 # by the adequate path.
 #RewriteRule ^/favicon\.ico /design/standard/images/favicon\.ico [L]
 RewriteRule ^/design/standard/images/favicon\.ico - [L]
 
 # Give direct access to robots.txt for use by crawlers (Google, Bing, Spammers..)
 RewriteRule ^/robots\.txt - [L]
 # Platform for Privacy Preferences Project ( P3P ) related files for Internet Explorer
 # More info here : http://en.wikipedia.org/wiki/P3p
 RewriteRule ^/w3c/p3p\.xml - [L]
 
 # Uncomment the following lines when using popup style debug.
 # RewriteRule ^/var/cache/debug\.html.* - [L]
 # RewriteRule ^/var/[^/]+/cache/debug\.html.* - [L]
 RewriteRule .* /index\.php
 
</IfModule>
 DocumentRoot /var/www/example
 ServerName www.example.com
 ServerAlias m.example.com
 </VirtualHost>

Note that we have added "m.example.com" using the "ServerAlias" directive for a server name of www.example.com.

eZ Publish configuration: siteaccess settings

A single eZ Publish installation is capable of hosting multiple sites by making use of something called the siteaccess system. This system makes it possible to use different configuration settings based on a set of rules.

The rules control which group of settings should be used in a particular case. Refer to the “Site management” section of the “Concepts and basics” chapter for a detailed description of the siteaccess functionality.

eZ Publish needs to be configured to use the host access method. This can be done by manually editing the global override for the "site.ini" configuration file: /settings/override/site.ini.append.php. A typical configuration would look something like this:

...
 [SiteAccessSettings]
 AvailableSiteAccessList[]
 AvailableSiteAccessList[]=example
 AvailableSiteAccessList[]=mobile
 MatchOrder=host
 HostMatchMapItems[]=www.example.com;example
 HostMatchMapItems[]=m.example.com;mobile
 ...

This configuration tells eZ Publish that it should use the "example" siteaccess if a request starts with "www.example.com" and the "mobile" siteaccess if a request starts with "m.example.com".

In addition, the configuration for the “mobile” siteaccess itself must be created in the following directory "settings/siteaccess/mobile". In this directory, create a file "site.ini.append.php" with contents similar to the following:

<?php /* #?ini charset="utf-8"?
 
 [DatabaseSettings]
 DatabaseImplementation=ezmysqli
 Server=localhost
 Port=
 
 User=root
 Password=
 Database=
 Charset=
 Socket=disabled
 
 [InformationCollectionSettings]
 EmailReceiver=
 
 [Session]
 SessionNamePerSiteAccess=disabled
 
 [SiteSettings]
 SiteName=Mobile Web Example
 SiteURL=m.example.com
 LoginPage=embedded
 AdditionalLoginFormActionURL=http://m.example.com/user/login
 
 [UserSettings]
 RegistrationEmail=
 
 [SiteAccessSettings]
 RequireUserLogin=false
 RelatedSiteAccessList[]
 RelatedSiteAccessList[]=example
 ShowHiddenNodes=false
 
 [DesignSettings]
 SiteDesign=mobile
 AdditionalSiteDesignList[]
 AdditionalSiteDesignList[]=ezwebin
 AdditionalSiteDesignList[]=base
 
 [RegionalSettings]
 Locale=eng-GB
 ContentObjectLocale=eng-GB
 ShowUntranslatedObjects=disabled
 SiteLanguageList[]
 SiteLanguageList[]=eng-GB
 TextTranslation=disabled
 
 [FileSettings]
 VarDir=var/ezwebin_site
 
 [MailSettings]
 AdminEmail=nospam@ez.no
 EmailSender=
 */ ?>

Settings for the [DatabaseSettings] section must be properly configured per your specific setup. Note that the [DesignSettings].SiteDesign setting contains the name of the design (that we will create) that is dedicated to the mobile site.

4.3 eZ Publish configuration: permissions

Once the new siteaccess has been configured, anonymous users will need permission to view it. In order to grant the appropriate permissions, take the following steps:

  1. Log in to the eZ Publish Administration Interface
  2. Click the “User accounts” tab
  3. Click the “Roles and policies” link at the bottom of the left sidebar
  4. Click the “Edit” button for the “Anonymous” role
  5. Click the “Edit” button for the policy for the “user” module and “login” function
  6. Add the “mobile” siteaccess to the existing selection
  7. Click the “OK” button to return to the “Policies” list
  8. Click the “Save” button