1

I am downloading my site online to my local machine. The database is done set up.

My question is how can change all the navigation in the application within local?

this is my config file

$config['base_url'] = 'https://www.yiyalo.com/';

this is an example of sign up

<a href='<?php echo base_url();  ?>signup/' target="_self" >

so that it will go to https://www.yiyalo.com/signup when the link is press.

Now, how can I perform that in localhost so that I can modify the code in the localhost?

My file is stored in a folder called 'yiyalo'.

Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85
Qi Yang
  • 69
  • 1
  • 12
  • change your base_url to localhost – madalinivascu Nov 29 '17 at 08:01
  • 2
    `$config['base_url'] = 'https://localhost/';` HTTPS might be an issue though, you can also use `127.0.0.1` but the name is preferred. If you use a port other then `80` you can put that in too `$config['base_url'] = 'https://localhost:8080/'`; – ArtisticPhoenix Nov 29 '17 at 08:01
  • At the risk of being "surprised" at something not working, It's probably a good idea to perform a file wide search for any hardcoded url's. And if you find any, it might be a good idea to alter those to use base_url() so everything is consistent and will work as expected. – TimBrownlaw Nov 29 '17 at 08:08
  • @ArtisticPhoenix The requested URL was not found on this server. – Qi Yang Nov 29 '17 at 08:11
  • can you go to `http://localhost/` in the browser? is there an `index.php` in the webroot of your local server? A lot of this depends how you structured your site. I put my sites in folders, so I have to include that ( because I'm to lazy to do virtual hosts ) – ArtisticPhoenix Nov 29 '17 at 08:38
  • when I type http://localhost in browser, it direct to http://localhost/dashboard/ – Qi Yang Nov 29 '17 at 08:51

4 Answers4

2

If you want a version that will work on both your local machine and your server, I'd recommend populating $config['base_url'] depending on your $_SERVER['HTTP_HOST'] value, as such :

if ($_SERVER['HTTP_HOST'] == 'localhost') {
    $config['base_url'] = 'http://localhost/';
} else {
    $config['base_url'] = 'https://www.yiyalo.com/';
}
roberto06
  • 3,844
  • 1
  • 18
  • 29
  • OK then it might be `$config['base_url'] = 'http://localhost/yiyalo/';` – roberto06 Nov 29 '17 at 08:17
  • Can I add a folder after my domain so that I can change everything online? – Qi Yang Nov 29 '17 at 08:22
  • Not that it's a big deal, here. Just wanted to point out this dosn't work on the `CLI` found that out the hard way when I was putting links to my site in emails generated by a background process.. – ArtisticPhoenix Nov 29 '17 at 08:37
1

A nicer approach is to set it up via enviromental variable:

$config['base_url']=getenv('BASE_URL');

So in you run via Apache you can put:

SetEnv BASE_URL "https://www.yiyalo.com/"

In case of cgi with nginx you can pass it as fastcgi_param eg:

location ~ \.php$ {
    include /etc/nginx/fastcgi_params;
    #extra fastcgi params there
    fastcgi_param BASE_URL "https://www.yiyalo.com/"
}

Alternatively in case of a docker use ENV directive into your Dockerfile.

The sole reassonn I am saying to use enviromental variable is that in case of a local php webserver that php provides you can just export them (assuming that you develop over GNU/Linux or similar):

export BASE_URL=http://localhost

So each developer just needs to export its own environment in order to run the app.

Dimitrios Desyllas
  • 9,082
  • 15
  • 74
  • 164
0

try the code below.Go to application/config/config.php and change this

switch ($_SERVER['HTTP_HOST']) {
    case 'yiyalo.com':
      $config['base_url'] = 'https://www.yiyalo.com/';
    break;
    default:
      $config['base_url'] ='http://localhost/yiyalo/';
       break;
      }
0

Change your base_url to:

$config['base_url'] = 'http://localhost/yiyalo/';

Make sure you have a proper .htaccess in the root of the project (localhost/yiyalo in this case).

Remember that you can let $config['base_url'] empty as well.

SomeRSGuy
  • 590
  • 7
  • 19