$_Server Variable Failed (Requirements)

I’m trying to install Yii on a windows plesk server running PHP 5.2.13 and I ran into this when I check requirments

I checked around I found this issue


Apparently I am supposed yo use that code, but where do I place it doesn’t mention.

Anyway know how to fix this?


Well, qiang suggests to put that code into your entry script, so I’d think you should do just that :)

Out of interest: What kind of webserver are you using? Plesk implies it’s most likely Apache, but it would still be interesting to know.

I’m using Parallels Plesk, it supports ASP and PHP.

Sorry where is the entry script exactly, and how do I locate it?

That’s a hosting management solution, not a webserver. The underlying webserver were of interest. It is my understanding that this is most likely Apache httpd followed by nginx.

Your entry script is the index.php handling and routing all incoming requests. It should be in the docroot of your project.

My bad Microsoft-IIS/7.0

So I copied and pasted the code inside index.php, where it calls the framework like so, but it’s still showing failed


function api_request_uri() 


   if (!empty($_SERVER['REQUEST_URI'])) 


      return $_SERVER['REQUEST_URI']; 




      $uri = $_SERVER['SCRIPT_NAME']; 

      if (!empty($_SERVER['QUERY_STRING'])) 


         $uri .= '?'.$_SERVER['QUERY_STRING']; 


      $_SERVER['REQUEST_URI'] = $uri; 

      return $uri; 



// change the following paths if necessary



// remove the following lines when in production mode

defined('YII_DEBUG') or define('YII_DEBUG',true);

// specify how many levels of call stack should be shown in each log message

defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);



If it try to run the web app I get 500 - Internal server error.

Also I tried placing the code after the include calls


Well, you weren’t supposed to copy that code in as-is. Anyway, can you try to follow the instructions on this wiki page and see if your situation improves? I think your greatest problem is IIS not passing the query string to PHP correctly.

Oh, and I’m afraid my support has got to end here as I’m not proficient with IIS :)

I checked out that Wiki and it didn’t help anything.

Would you be able to tell me how? I really think this will solve my problem.

Thanks for all the help, much appreciated.

It’s not clear to me what you are trying to do.

If you want to check requirements, run the requirements script, otherwise: explain what it is you need to do.

Im installing Yii on a server- IIS/7, one of the requirements failed ($_SERVER variable).

I’m trying to find out how to fix/pass that requirement

The CHttpRequest component takes care of the differences between server software.

Are you telling me that the requirements script failed?

Can you run a regular php script on your server?


If it is, you’re running IIS.

No the requirements script runs fine, one of the requirements failed from the list. I can run regurlar PHP scripts fine. This is the one that failed $_SERVER variable

Look at the output of phpinfo.

You also didn’t answer all my questions. :)

What am I supposed to look for on phpinfo?

Not sure what you mean by the above

I am running IIS7, I can confirm.


I used http://www.yiiframework.com/forum/index.php/topic/31145-errors-and-iis-7/page__p__149995__hl__IIS#entry149995 fr0d0z has a solution.

$_SERVER variable still failed but when I run index.php yii takes over instead of 500 server error.

I’m still getting Yii erros as I need to configure my Web App, (DB connection etc).

I will see what problems I get next.

Thanks everyone.

From what I remember, to get this type of thing running onIIS, I had to tweak a web.config file in the web data folder. Don’t remember much more right now, but I can look it up for you if you don’t have this solved.

If it’s not too much trouble, please: do :)

Besides bringing closure, it’s also going to be useful for others stumbling upon this topic in the future.

Hmm, my issues with IIS were actually different (trying to remove index.php from the URL and having permissions issues when changing the file).

But I just found this fix:

@jacmoe, think we should add a github issue about this? Wouldn’t be too hard to add that line to CHttpRequest and it could really help IIS folks with their problems …

It is already in there - CHttpRequest:

	public function getRequestUri()




			if(isset($_SERVER['HTTP_X_REWRITE_URL'])) // IIS


			else if(isset($_SERVER['REQUEST_URI']))











			else if(isset($_SERVER['ORIG_PATH_INFO']))  // IIS 5.0 CGI







				throw new CException(Yii::t('yii','CHttpRequest is unable to determine the request URI.'));


		return $this->_requestUri;


Or, perhaps I’m wrong?

It doesn’t look like Yii handles the specific fix that shows up on that blog. Here’s what he has:

if (!isset($_SERVER['REQUEST_URI']))


       $_SERVER['REQUEST_URI'] = substr($_SERVER['PHP_SELF'],1 );

       if (isset($_SERVER['QUERY_STRING'])) { $_SERVER['REQUEST_URI'].='?'.$_SERVER['QUERY_STRING']; }


He’s handling the case when REQUEST_URI doesn’t exist, which Yii only does if HTTP_X_REWRITE_URL is set in IIS.

@ItsYii: can you do a:


On your server and post the results (with any info snipped to protect you that you need to)?