Host your website created with CakePHP 2 at LWS, OVH or 1and1

Page 1 / 1

When you want to host a site created with the CakePHP 2 framework, it is possible that you have an internal server error (code 500).
To address this issue, simply edit 3 ".htaccess" files of CakePHP. But the modification depends on your web hosting.

  1. For LWS
  2. For 1and1
  3. For OVH

1. For LWS

For LWS.FR webhost, there are 2 possibilities :

  • a shared webhosting
  • or a multi-domains web hosting

In the case of the shared webhosting (a web hosting for one site), you will not have problems.

But, if you use the multi-domains option, you will have problems with any additional domains.
Indeed, with this option, you can host a site to the root of your FTP account (no problem for this site), but others will be in subfolders : "my-2nd-domain.net," "my-3rd-domain.net ", ...
For these sites, you will need to edit ".htaccess" files like this :

Plain Text

\.htaccess

Apache

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteBase /
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>

Plain Text

\app\.htaccess

Apache

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /app
    RewriteRule    ^$    webroot/    [L]
    RewriteRule    (.*) webroot/$1    [L]
</IfModule>

Plain Text

\app\webroot\.htaccess

Apache

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /app/webroot
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

2. For 1and1

For 1and1 webhost, you should use PHP 5 and use RewriteBase instructions like this :

Plain Text

\.htaccess

Apache

<IfModule mod_rewrite.c>
    AddType x-mapp-php5 .php
    Options +FollowSymLinks
    RewriteEngine On
    RewriteBase /
    RewriteRule ^$ app/webroot/ [L]
    RewriteRule (.*) app/webroot/$1 [L]
</IfModule>

Plain Text

\app\.htaccess

Apache

<IfModule mod_rewrite.c>
    AddType x-mapp-php5 .php
    Options +FollowSymLinks
    RewriteEngine On
    RewriteBase /
    RewriteRule ^$ webroot/ [L]
    RewriteRule (.*) webroot/$1 [L]
</IfModule>

Plain Text

\app\webroot\.htaccess

Apache

<IfModule mod_rewrite.c>
    AddType x-mapp-php5 .php
    Options +FollowSymLinks
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php/$1 [QSA,L]
</IfModule>

If you get an error about the timezone :

Plain Text

Warning: strtotime() [function.strtotime]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier.

Il suffit de décommenter (enlever le # en début de ligne) et modifier la ligne "date_default_timezone_set" dans le fichier "\app\Config\core.php".
Note : La liste complète des fuseaux horaires se trouve sur le site de PHP.

Just edit the "date_default_timezone_set" line in the "\app\Config\core.php" file.
Note : The full list of time zones is on the PHP site.

PHP

// Time zone of London
date_default_timezone_set('Europe/London');

3. For OVH

Apparently, you only need to use version 5 of PHP.

For this, you have 2 possibilities :

  • use the ".ovhconfig" file
  • activate PHP5 via .htaccess

If you want to use the .ovhconfig file, the file should look like this.
Note : As mentioned in the OVH FAQ, this file is present by default on 2014 web hostings. If this file doesn't exist, just create it.

Plain Text

.ovhconfig

Plain Text

app.engine=php
app.engine.version=5.5
http.firewall=none
environment=production

If you want to use the .htaccess file, simply add this line to the beginning of the ".htaccess" file located in the root of your CakePHP site :

Apache

SetEnv PHP_VER 5