How to run Multiple codeigniter application in single shared hosting server? - codeigniter

I am using shared hosing for Codeigniter application for deployment.
How can i run staging url on live server?
1) domain.com (Working)
2) domain.com/staging/ (Not working, showing 404 error)
I created staging folder under public_html directory, now put All CI code in staging folder, and tried to run the application with URL domain.com/staging/ but it redirect on domain.com/404
I expect to run domain.com for users and domain.com/staging for development. (Staging URL i will use for development and after that i will place the same code for live URL.)

This is most easily done by using a subdomain for the staging version, i.e. staging.doman.com. The folder where you put the CI files isn't super important as the subdomain will be set to use the directory you choose.
You will either need to have complete control over the server or have a service provider that allows you to set up subdomains.
- Expanded Answer -
If you cannot set up a subdomain then your next best option is to use the advice in the documentation on Managing you Applications. It isn't required to use the file structure shown there. In your case try the following.
Create a folder on the same level as application named staging.
Into that folder copy all the folders and files normally found in /application.
Add all application folders and files required by your site. The files in these folders are those that make up the application you are staging.
Make a copy of index.php (the file at the root of the public folder, i.e. domain.com/index.php) and name it staging.php. Both index.php and staging.php will be in the same folder.
Edit staging.php and change the value of $application_folder to be the absolute path to the staging folder. For example:
$application_folder = '/path/to/domain.com/public_folder/staging';
The path above is an example. You must replace it with the actual path in your server. If you have no idea what the full and absolute path is you can use
$application_folder = dirname(__FILE__).'/staging';
Browse to the URL domain.com/staging.php and you should get your default controller's output. To test that you are actually seeing the staging version of the page temporarily change something in the view file so there can be no doubt.
You will go to other controllers by using the URL domain.com/staging.php/other_controller.
Change the value of $config['index_page'] in /staging/config/config.php to staging.php, e.g.
$config['index_page'] = 'staging.php';
Without the above change redirect() and many other "helper" functions will not work correctly.
(Optional?) You can probably edit the main .htaccess and add rewrite rules for staging.php the same way it is done for index.php. But I will leave that as an exercise for you. (Or for another SO question.)
A final word. It might be necessary to make other configuration changes to accommodate the revised file structure. I tested the answer here but did not go beyond the most basic task of browsing to controllers. Most likely config values for sessions, cookies, and many others will need to be adjusted for the staged version to work correctly. Check out the documentation on Handling Multiple Environments for guidance on making this less painful.

Related

Move magento from one url to another on the same server

I have developed a site in the url www.example.com/demo on now i want to move the site to www.example.com on the same server what are the steps that are to be taken to move the site on the same server with the same database.
Just copy all the files from demo folder to root folder. Since Database configuration in file will be same, so you don't need to change those.
In database Run this query
SELECT * FROM core_config_data WHERE path = 'web/unsecure/base_url' OR path = 'web/secure/base_url';
change base secure and unsecure url to www.example.com.
Clear the cache and your are ready with www.example.com
I do a similar thing to you. I have a subsite set up for testing before I push to production. I simply copy the files (using git) and the database whenever I want to update production. However, these are two distinct sites with their own directory structure and database.
So, in order to keep things "simple" (ie I don't need to redo things every time), I have untracked versions of app/etc/local.xml so each site connects to the right database and on the production system I have a module to set my secure and unsecure urls (see here for more detail than you probably want: Unable to set base url from config file).
Good luck

multiple environments with codeigniter

I'm trying to understand the best course of action with using multiple environments, such as development, testing, production for my application with codeigniter.
As of right now I have one folder for my application. I'm seen places that talk about in the config file doing a folder for each of the environments and placing for example a copy of the database file in each of the environment folders.
Is this the best method of handling multiple environments? The reason I'm asking is because if I work on my dev subdomain I'd still have to reupload to the main root folder all the same files. Is this the best workflow?
So basically I have two sites.
dev.siteurl.com
siteurl.com
I'm trying to figure out the best option of handling this. Because I'm wondering if I'm going to just have to reupload all the files again to the main level so that it can handle the production server or is there an easier way.
Yes the way it works is under your /application/config folder you create an extra nested folder called development so that you have
/application/config/development/
Inside development you will place a copy of your database.php file and change your development database settings
/application/config/development/database.php
THEN you have to tell codeigniter which version you are on, so in your base root folder edit index.php:
/index.php
define('ENVIRONMENT', 'development');
When you want to use the /config/development/database.php you will change your environment to development, and when you want to use the production database you will change the environment to production
edit: also the CI TOC has a brief section explaining this: https://www.codeigniter.com/user_guide/general/environments.html
I'm defining envirement in index.php
do something like
if ($_SERVER['SERVER_NAME']=='siteurl.com')
define('ENVIRONMENT', 'production');
else if ($_SERVER['SERVER_NAME']=='test.siteurl.com')
define('ENVIRONMENT', 'testing');
else
define('ENVIRONMENT', 'development');
and use config sections according to ENVIRONMENT variable
I know this is an old thread, but I am working on a Codeigniter project now and was looking for a good way to maintain two environments without having to maintain two codebases at two different urls. In case anyone else is looking for a similar answer, here's a possible solution that allows you to maintain one codebase.
For my current project, I have siteurl.com and siteurl.com/sandbox.
siteurl.com/index.php
define('ENVIRONMENT', 'production');
$system_path = '../system';
$application_folder = '../application';
siteurl.com/sandbox/index.php
define('ENVIRONMENT', 'development');
$system_path = '../../system';
$application_folder = '../../application';

How to use symlinks in magento?

How to use symlinks in magento?
This is the scenario:
I have a subdomain store.example.com (say), it has 4 websites (de,fr,au,af).
I want each of these websites to link to store.de.example.com , store.fr.example.com, store.au.example.com and store.af.example.com respectively.
So that I can run each of these magento websites individually.
My usual approach for setting up Magento multisite environment.
Here are few additional goals that I’d like to achieve when doing this: core code out of the way , clean public folders, packed for easier deployment and testing.
magento_base/
htdocs/
htdocs/website_01/
htdocs/website_01/index.php
htdocs/website_01/.htaccess <-- symlink
htdocs/website_01/js/ <--symlink
htdocs/website_01/skin/ <--symlink
htdocs/website_01/media/ <--symlink
htdocs/website_01/errors/ <--symlink
htdocs/website_01/downloader/ <--symlink
htdocs/website_02/
Set up your magento isntallation to magento_base folder and right next to it (or any place you need or your virtual-host makes them) you’d make a folder for each of your subdomain, website (dependent of your multisite goals). Next we symlink public parts of magento to this folder and make a copy of index.php and change path for including Mage.php and set your website or store code at the end of it.
*note that if you have few sites then you can make htdocs folder inside your magento_base for easier deployment and map your domains inside that folder*
Next step is to point your domain, subdomain and map it to right website folder and you are good to go:
You get your codebase out of the public folder by pointing domains to public folder and symlinking Magento’s few public needs
Upgrades won’t mess with your symlinked files and you don’t have to change server configuration files
If you use git then you can have those symlinks pointed to stage, live branch checkouts and just push your changes to production or stage env’s
You can test inside magento base folder on your test-server without conflicting your production settings and setup different sites (sites can be accessed by site or store code)
client is pointed to public folder to upload his other stuff , campaigns, blogs whatever and that won’t be mixing with magento_base folder and you can make rules to include/exclude from your deployment procedure. No more crap inside.

Creating an admin section controllers and views in Code Igniter 2.0

I have created my site with controllers such as about, products etc... which gives me example.com/about/ etc..
How would I create a admin section with the same controller name, like example.com/admin/about or example.com/admin/products ?
How do I organize my controllers?
2 more options to compliment WebweaverD answer.
Use Modular Separation
Create a second application folder and index file, that will be responsible for admin, connect them to the same system folder.
The second option is really easy to manage once you have set it up. There are variations but I find the structure below to be the most convenient.
mykewlwebsite.com
apps/
frontend/
app/ frontend codeigniter application folder
public/
index.php
assets/ frontend js, css, images
backend
app/ backend codeigniter application folder
public/
index.php
assets/ backend js, css, images
config/
database.php
constants.php
system/ codeigniter system folder
The database.php file contains the code from CodeIgniter's config/database.php and is shared for all applications of your project - simply remove all code and add require_once('../../../../config/database.php'); to the config/database.php
index.php files inside public folders have two important variables $system_path and $application_folder, change them to
$system_path = '../../../system/codeigniter';
$application_folder = '../app';
constants.php file can have some constants like the ENVIRONMENT constant from the index.php files and some other. Just require_once() it from the index.php files.
Though there are pros and cons.
PROS
For those of you, who are developing on localhost and deploying to servers via FTP or other systems can simply upload one folder - apps and overwrite the target folder without fear of overwriting database.php settings (I'm sure most of you have them different from the local ones).
Adding one more application is easy - just duplicate one of existing. You can add as many applications as you want - api, ajax, user cabinet, etc.
CONS
This structure is meant to be used if you have a domain as mykewlwebsite.com and have the ability to add sub-domains to it, so you just configure the home folders for each of them:
mykewlwebsite.com: path/to/mykewlwebsite.com/apps/frontend/public/
admin.mykewlwebsite.com: path/to/mykewlwebsite.com/apps/backend/public/
api.mykewlwebsite.com: path/to/mykewlwebsite.com/apps/api/public/
You have a few options here:
1) CREATE A SUBFOLDER - Put them in a folder called admin within the controllers directory (in application/contollers/admin/products.php)
A word of warning here is that you can only go one folder deep or codeigniter gets upset. Also, it will use first level controller/methods first so be careful of naming conflicts - e.g if you have an admin controller with a products method in it, that will get called before it looks in the admin directory for a products controller. (when going to example.com/admin/products)
2) USE THE ROUTES FILE - If it is just the urls you are worried about you could just call the controllers whatever you want and use the application/config/routes to redirect those paths to the controllers you want like this:
controller name: admin_products.php
routes file:
$route['admin/products'] = "admin_products";
3) USE A MASTER CONTROLLER FOR ALL - Final option would be to have a single admin controller and use named methods inside it, so for example you have admin.php controller with a products method within it this would then be called by admin/products uri (this will probably get messy though in a big application/site - not recommended)
Hope I have explained this OK for you, if you need any clarification please ask and I will try to elaborate.

CodeIgniter How to create Multiple Site with One CMS

I want to create a blog site with only one CMS. This CMS will be in different domain.
For example: mycms.com
Then my blog sites are also in different domains.
For example: website1.com, website2.com, website3.com
They will all use mycms.com as their admin
*Images will be uploaded in mycms.com/images/ so all the 3 websites will get the images from this directory
If images are loaded on website1.com from the main database, they should be displayed as if they're from website1.com. So for example website1.com/images/cat.jpg instead of mycms.com/images/cat.jpg
How will I build this using codeigniter?
You can use the same CodeIgniter /System and /Application folders for all the websites if you like; just make sure all the index.php files are setup to use those same folders for $system_path and $application_folder respectively. Note that these sites also need to reside on the same server.
You can serve up different content by checking $_SERVER['HTTP_HOST'] for the domain the request came from.
As for htaccess you should be able to use %{HTTP_HOST}/$1 or %{HTTP_HOST}$1 (depending on server config) to make the rewrite rule dynamic.
I am actually building a similar project right now using CodeIgniter but there are also several other projects available like halogy, codefight, pyro (with an extension), and many others.
CodeIgniter has a System and an Application folder. You could have one global system folder and then one application folder for each of your subdomains, or you could have one application folder and just make your subdomian folders parallel with your www folder.

Resources