简体   繁体   中英

How do you make a Kohana website portable?

I just finished coding an online portal with Kohana PHP .

It works fine on my PC, but when I tried to host it on another server, "BONK!", it shows up without displaying the pictures of the products.

I don't even know what's going on.

What rules I should follow to make my Kohana apps portable?

I'm using Kohana to develop a few websites and here are some tricks that I use to make sure that the websites are portable, as in I can just upload the files from my development environment into the server and have them running without having to modify anything:

  1. Use the same directory structure. For example in my case I put the Kohana core folders into <drive><somepath>/apps/kohana/system/ and <drive><somepath>/apps/kohana/modules/ on my local disk and /apps/kohana/system/ and /apps/kohana/modules/ on the server. Similarly, I set my local XAMPP htdocs to <drive><somepath>/public_html/ to follow the server setting of /public_html . That way I don't have to modify index.php when I upload it to the server. Use relative paths .

  2. Like kfederov suggested, use url::base() in all your src=".." in your templates. The way I do it is by assigning $this->template->baseurl = url::base(); in my Controller_Template (I'm using Kohana 3 but the method is almost the same for Kohana 2.x) and use {$baseurl} in the Smarty templates (I highly recommend using Smarty template system -- you can find the module in the Kohana forum).

  3. Use the same database name, username and password in both development and server environment so that I don't have to modify config/database.php , obviously.

  4. If you are hosting multiple websites with different domains on the same hosting, obviously you cannot use /public_html as the document root for all but one of the websites. You most probably have to configure those non-primary domains to point to different folders, for example in my case I put them in /hosted/*/ folders and configure my server cPanel accordingly. To duplicate this setting in your local environment, you need to use localhost subdomains, which requires you to modify httpd.conf and your HOSTS file accordingly, as below:

    1. Add Virtual Host in httpd.conf . eg:

       <VirtualHost *:80> DocumentRoot /path/to/hosted/coolwebsite ServerName coolwebsite.localhost </VirtualHost> 
    2. Add to your HOSTS file ( C:\\WINDOWS\\system32\\drivers\\etc\\hosts if under Windows):

       127.0.0.1 coolwebsite.localhost 
    3. Now you use http://coolwebsite.localhost/ to access the website on locally running web server for your development environment.

Hope this helps!

  1. Check your .htaccess and bootstrap.php files for the right site path.

  2. Make sure you used URL::base() in src="..." .

确保更新您的.htaccess,index.php中的值,以及也许在配置文件中的值。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM