Welcome Guest, Not a member yet? Register   Sign In
set up multiple applications
#1

Hi,
Here's my context : codeigniter 3 on wamp.
Here's my problem :
  • I have two environments (production and test).
  • I have one source code for each environment.
  • In each environment I can have multiple applications sharing the same source code (one application/environment is associated to a group of databases).
  • Currently the server is located on my machine
I created the following source tree for my files in www/code_igniter directory :
  • applications (directory)
  • assets (directory)
  • system directory (of codeigniter)
  • .htaccess file (for removing index.php from url)
  • index.php
Content of applications directory :
  • application test (directory)
  • application prod
each applications directory contains the files and directories of codeigniter application directory (cache,config, controllers, core,...etc)

I want to run my applications by using the following url : http://localhost/<application_name>_<environment>
I don't succeed in making the access to my application work ("I've got The requested URL was not found on this server").
I'm lost in the configuration of index.php, .htaccess, routes.php, config.php

In index.php, I parse $_SERVER['REQUEST_URI'] to set $application_folder value and database credentials
In .htaccess i set :
Code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

in config.php I set :
Code:
$config['base_url'] = 'http://localhost'; and $config['index_page'] = '';

Did I make the good choices for my source tree ?
How should I configure the files index.php, .htaccess, routes.php, config.php ?

Please help me
Reply
#2

Hi,
I tried that :
In my htaccess located in code_igniter directory :
Code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule application1/test code_igniter/generic_test.php/generic_controller

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule application1/prod code_igniter/generic_prod.php/generic_controller [L]
</IfModule>
 
In route.php in /code_igniter/applications/generic_test/config :
Code:
$route['default_controller'] = 'generic_controller';


In config.php in /code_igniter/applications/generic_test/config :
Code:
$config['base_url'] = 'http://localhost/code_igniter';


In index.php in code_igniter directory : 
Code:
$application_folder = 'applications/generic_test';


When I run http://localhost/application1/test I've got "The requested URL /application1/test was not found on this server".

I checked my rewrite rule on a the site https://htaccess.madewithlove.be/ and "http://localhost/application1/test" should produce "http://localhost/code_igniter/generic_test.php/generic_controller"

So I don't understand what's wrong.

Thanks for your help
Reply
#3

(This post was last modified: 01-16-2020, 11:43 AM by php_rocs.)

@fredg,

Why didn't you just use the built in CI environment feature: https://codeigniter.com/user_guide/gener...ments.html

This way, by simply changing the value of a variable your code will work in multiple environments.
Reply
#4

Are there any reason you need to do it like that? Because that just look like you are going to dig a big hole in the ground and never get out of it.

I would recommend setting up virtual hosts (multiple domains) and send environment variables from apache into CI. And change your application directory path. So you can access it normally.
Reply
#5

(01-16-2020, 11:43 AM)php_rocs Wrote: @fredg,

Why didn't you just use the built in CI environment feature: https://codeigniter.com/user_guide/gener...ments.html

This way, by simply changing the value of a variable your code will work in multiple environments.
Hi,
Thanks for your reply.
Here is a part of the document https://codeigniter.com/user_guide/gener...ments.html
"Developers often desire different system behavior depending on whether an application is running in a development or production environment. For example, verbose error output is something that would be useful while developing an application, but it may also pose a security issue when “live”."

That doesn't meet my need because my code is different following I'm on test or production. I want to switch for code test or code prod following my url
Reply
#6

(01-16-2020, 11:49 AM)jreklund Wrote: Are there any reason you need to do it like that? Because that just look like you are going to dig a big hole in the ground and never get out of it.

I would recommend setting up virtual hosts (multiple domains) and send environment variables from apache into CI. And change your application directory path. So you can access it normally.
Hi,
Thanks for your reply.
Here's my need :
I need to run my test code if my url contains "test"
I need to run my prod code if my url contains "prod"
I need to run my code with database application1 id my url contains "application1"
I need to run my code with database application2 id my url contains "application2"

I don't know If I followed the good way, that's why I asked if someone could help me.

I would recommend setting up virtual hosts (multiple domains) and send environment variables from apache into CI.
=> Thanks I'm going to investigate further on that point

And change your application directory path. So you can access it normally.
=> Done by using two index files
Reply
#7

(01-16-2020, 11:49 AM)jreklund Wrote: Are there any reason you need to do it like that? Because that just look like you are going to dig a big hole in the ground and never get out of it.

I would recommend setting up virtual hosts (multiple domains) and send environment variables from apache into CI. And change your application directory path. So you can access it normally.

The document https://codeigniter.com/user_guide/gener..._apps.html describes the configuration I set, but things are missing about htaccess, routes.php, config.php,
Reply
#8

(01-16-2020, 11:49 AM)jreklund Wrote: Are there any reason you need to do it like that? Because that just look like you are going to dig a big hole in the ground and never get out of it.

I would recommend setting up virtual hosts (multiple domains) and send environment variables from apache into CI. And change your application directory path. So you can access it normally.

Hi,
I found the solution to my problem.
The main problem was that I had two index.php (one in code_igniter directory and one in each application directory) and I modified the bad one (the one in code_igniter directory).
I used virtuel hosts, as you adviced to me to do, to shorten my urls

Thank you for your help.

Frederic
Reply




Theme © iAndrew 2016 - Forum software by © MyBB