Welcome Guest, Not a member yet? Register   Sign In
Simple tips to making your CI application more portable
#1

[eluser]Jonathon Hill[/eluser]
Hello CodeIgniters,

I've been using CI for about 4-5 months. I'm not very experienced with web development, but here are some ideas that I just implemented on one of my CI apps to make it more "server-agnostic" configuration-wise. This is a timesaver when you're deploying to several different servers (development servers, production server).

Use URLs based off the document root

In other words, use URLs like '/controller/view' instead of 'http://mysite/controller/view'. Here's how:

In your application/config/config.php file:

Code:
$config['base_url'] = '/';

That way you won't have to edit config.php every time you deploy to a different server.

Use identical MySQL server credentials

Most of us probably use localhost for the MySQL server. If you do, set a MySQL username/password specifically for your CI application. That way you won't have to edit application/config/database.php each time.

Don't hack, extend

Don't touch core CodeIgniter files! If you need to make a modification to a core library, extend it. This will make things much easier when switching or upgrading to a later version of CodeIgniter.

Separate your application folder from your system folder

There are plenty of threads on this forum on how to do this, but if you put your application directory somewhere besides inside the system folder you'll make things easier to manage. Here's how I'm doing it:

Code:
/var/www/vhosts

                /codeigniter-1.6.3   (contains the contents of the system folder)

                /[host name]
                             /.htaccess
                             /index.php
                             /application     (your application folder)
                             /...             (other site files)

With this configuration, whenever I want to upgrade CI I just create a new codeigniter-xxx folder in /var/www/vhosts and edit [host name]/index.php to pint to it. I can also share it with multiple applications.

Your thoughts

Anyone else have ideas of their own, or thoughts about my methods here?
#2

[eluser]Tom Glover[/eluser]
With the Config File it is best not to use relative url's in any form of web development as it can cause some issues with SEO and SEF url's.
#3

[eluser]Jonathon Hill[/eluser]
Really? How?
#4

[eluser]Tom Glover[/eluser]
Have a look here:

Quote:What is the difference between an absolute URL and a relative URL? For newbies out there, a relative URL points to links on a server in a local manner like this - a href="contact.html" - where you just point to the page link like you are right there working on the server.
http://www.webpronews.com/blogtalk/2008/...ative-urls
#5

[eluser]Mirage[/eluser]
Agreed.

To ease development, I use this:

Code:
$config['base_url'] = "http://{$_SERVER['HTTP_HOST']}/";

Cheerio -
m
#6

[eluser]Jonathon Hill[/eluser]
@Mirage: OK, I started to do that, but my development box is http:// and the production server is https://

@TJ-Glover: Thanks for that info, and you're right. Except, as in my case, it's all on ONE protocol. If I were developing a shopping cart or the like where parts of the site were one and parts were the other I'd have to set the protocol like Mirage. But, still, you're only going to have one protocol in your links, aren't you? (Assuming you're using CI functions for your links, which I do)
#7

[eluser]internut[/eluser]
good post, helps me out a bit. I wish there was an easy way to over-ride certain config settings from an admin area of the program you build so it could be from an admin interface and not /config/config.php
#8

[eluser]Colin Williams[/eluser]
Really nice little suggestions, Mr. Hill. I too do the base_url = / approach. The notion that relative URLs can be a detriment to SEO is baloney!

Quote:So, what's the problem? The problem is that Google and the other search engines can see that single page as two identical pages - one https: and the other http: - and consider them duplicate content. Worse, if the spiders have access to that https: page through even a single misplaced link, they can follow those relative links, potentially indexing a duplicate https: version of your entire web site.

Sorry, Richard Burckhardt, but a site should not even allow different areas to be accessed by both HTTP and HTTPS protocols (it should be forced into one or the other via 301 redirects). This has to do with poor server architecture, not the fact that one uses relative URLs.
#9

[eluser]Colin Williams[/eluser]
Quote:I wish there was an easy way to over-ride certain config settings from an admin area of the program you build so it could be from an admin interface and not /config/config.php

There is (or will be). PM me.
#10

[eluser]xwero[/eluser]
I want to contribute a tip to make parts of your CI application usable in other frameworks or legacy websites:

When you create a library make it as less depending on CI functionally as possible, or better make it not CI dependent. The latter option will result in more code most of the time.

When you create views echo variables and functions instead of CI related variables and methods.




Theme © iAndrew 2016 - Forum software by © MyBB