We are moving our website from our current web host to AWS. The website was outsourced to a third party developer and was turned over to me. On checking the codes, I saw that it was done in Code Igniter.
I've uploaded the website to an instance in AWS for parallel running with the current web host:
I've made sure that the AWS database connection is working. In one config files, I've adjusted the base URL:
function baseUrl(){
//$base ='http://www.oursite.com/';
$base = 'http://ec2-our-instance.compute.amazonaws.com/';
return $base;
}
Calling the baseURL() returns our AWS instance URL.
My problem now is that the website calls functions in a file, site_info.php via routing the filename, function and parameters in the URL.
The directory of the function file is listed below:
\site\application\controllers\site_info.php
One function in site_info.php is:
function showWorld(){
echo 'Hello World';
}
The cURL call to showWorld() has the URL set to the route of the function, i.e. baseURL().'/site/site_info/showWorld'. The code is listed below:
function showSomething(){
$url = baseURL().'/site/site_info/showWorld';
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,120);
curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 200);
curl_setopt($ch, CURLOPT_USERAGENT ,
curl_setopt($ch, CURLOPT_URL, $url );
}
showSomething();
The call to function showSomething() echos the content on the currently hosted website, i.e. www.oursite.com. I can even run on the browser the URL, www.oursite.com/site/site_info/showWorld and get the echo content.
The AWS hosted site returns the error 'The requested URL /site/site_info/showWorld was not found on this server.'
How do I correct this?
Just Define in your root/application/config/config.php
$config['base_url'] = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['SERVER_NAME']."/";
call like this
function showSomething(){
$url = base_url(true).'site/site_info/showWorld';
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,120);
curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 200);
curl_setopt($ch, CURLOPT_USERAGENT ,
curl_setopt($ch, CURLOPT_URL, $url );
}
showSomething();