Strange Asset Behaviour

Hi!

I run into an issue with the asset manager.

After copying a working site to a remote server, the asset manager throws the invalid directory error,

even though i set the directory rights.

The strange thing is that when i removed the if statement from the CAssetManager.setPath it could publish the assets to the webroot (obiously they were in the wrong place there) and it could write the application log as well

to the protected/runtime directory, meaning that this is not a problem with directory rights nor something concerning realpath.

I’m out of ideas on this, so please help.

BTW. The copied site is in production mode, if this matters.

What is the error exactly?

Never met it?

CException

CAssetManager.basePath "/hosting/atw.hu-users/c/s/csepelszigeti/uj/assets" is invalid. Please make sure the directory exists and is writable by the Web server process.

directory structure:

+root /the framework can publish the assets under here

|-some

|-old

|-site

|+uj

-|-assets /but not under here

-|+protected

-||-runtime /the application log is created as well

-||-ect.

-|-ect.

Maybe open_basedir restriction in effect (that’s a php configuration setting)? You can check its value with phpinfo() in your index.php.

EDIT: Sorry, didn’t look carefully at your tree. So probably it’s something else.

Still think it’s permissions problem. What are permissions for uj, assets and runtime? Who is the owner of these?

777

first I tried messing with different settings and the got upset and give 777 recursive, but still nothing.

EDIT: runtime works perfectly fine with 775.

UPDATE: I moved everything to webroot, and the oldsite into an other directory, but still the same error. There is only two things left to try: separating yii from the site folder and try if switch to debug mode(i don’t think either will work though). So i think the server owner must have some elaborate security rules in effect that keeps the site from working(which is gonna be a hard fight getting them to lift it).

Thanks anyway

It looks like it can’t find the directory even though, the directory is there, that only happened to me when I built sites on Linux, you have to be very careful to write the names exactly as they are. Working with Yii, the best is work always in lower case for directories (and Controller Names capitalized only on the first Letter).

It is also strange that your sharing host would allow you to set the permissions on the folder and not allow to write on that folder. Have you sent him an email to find out if that is correct?

You also said: The strange thing is that when i removed the if statement from the CAssetManager.setPath it could publish the assets to the webroot (obiously they were in the wrong place there)

So it actually publishes the assets to a writable folder. Where do you configure the basePath of AssetManager?

I didn’t configured it, the variables were on default.

This is exacly the strange thing. If the server’s config forbids filesystem operations, then this could not happen. But if the problem was with actually finding directories, then the protected directory (or that of the framework for inclusion) would be inaccessible as well.

AssetManager publishes by default here:

root

— assets

— index.php

— otherfolders

If you wish to publish onto another folder you need to setup your AssetManager like this in your main.php config file:




return array(

        

   ...

        // application components

        'components'=>array(

                'assetManager'=>array(

                        'basePath'=>'/hosting/atw.hu-users/c/s/csepelszigeti/uj/assets',

                ),

   ...



Did you tried that? … Just trying -trial-&-error… It is actually very weird if you have set all your folders writable

It is currently like this:

root

–assets

–css

–files

–protected

–yii

nothing changes even if i add the right path.

I have just seen the ‘.’ in your path. Could it be that the asset manager get confused by that?

Could you drop here the line where that error occurs buddy so I could backtrack the problem through the code of Yii…

This is the full error message:

2011/01/09 16:06:31 [error] [exception.CException] exception ‘CException’ with message ‘CAssetManager.basePath “/hosting/atw.hu-users/c/s/csepelszigeti/assets” is invalid. Please make sure the directory exists and is writable by the Web server process.’ in /yii/framework/web/CAssetManager.php:92

Stack trace:

#0 /yii/framework/web/CAssetManager.php(77): CAssetManager->setBasePath(’/hosting/atw.hu…’)

#1 /yii/framework/web/CAssetManager.php(179): CAssetManager->getBasePath()

#2 /yii/framework/zii/widgets/CListView.php(162): CAssetManager->publish(’/yii/framework/…’)

#3 /yii/framework/web/CBaseController.php(140): CListView->init()

#4 /yii/framework/web/CBaseController.php(165): CBaseController->createWidget(‘zii.widgets.CLi…’, Array)

#5 /protected/views/site/view.php(62): CBaseController->widget(‘zii.widgets.CLi…’, Array)

#6 /yii/framework/web/CBaseController.php(119): require(’/protected/view…’)

#7 /yii/framework/web/CBaseController.php(88): CBaseController->renderInternal(’/protected/view…’, Array, true)

#8 /yii/framework/web/CController.php(833): CBaseController->renderFile(’/protected/view…’, Array, true)

#9 /yii/framework/web/CController.php(746): CController->renderPartial(‘view’, Array, true)

#10 /protected/controllers/SiteController.php(40): CController->render(‘view’, Array)

#11 /yii/framework/web/actions/CInlineAction.php(57): SiteController->actionView()

#12 /yii/framework/web/CController.php(300): CInlineAction->run()

#13 /yii/framework/web/filters/CFilterChain.php(133): CController->runAction(Object(CInlineAction))

#14 /yii/framework/web/filters/CFilter.php(41): CFilterChain->run()

#15 /yii/framework/web/CController.php(1084): CFilter->filter(Object(CFilterChain))

#16 /yii/framework/web/filters/CInlineFilter.php(59): CController->filterAccessControl(Object(CFilterChain))

#17 /yii/framework/web/filters/CFilterChain.php(130): CInlineFilter->filter(Object(CFilterChain))

#18 /yii/framework/web/CController.php(283): CFilterChain->run()

#19 /yii/framework/web/CController.php(257): CController->runActionWithFilters(Object(CInlineAction), Array)

#20 /yii/framework/web/CWebApplication.php(324): CController->run(‘view’)

#21 /yii/framework/web/CWebApplication.php(121): CWebApplication->runController(‘site/view’)

#22 /yii/framework/base/CApplication.php(135): CWebApplication->processRequest()

#23 /index.php(13): CApplication->run()

#24 {main} REQUEST_URI=/index.php?r=site/view&id=1

The corresponding code in Yii CAssetManager:




	public function getBasePath()

	{

		if($this->_basePath===null)

		{

			$request=Yii::app()->getRequest();

			$this->setBasePath(dirname($request->getScriptFile()).DIRECTORY_SEPARATOR.self::DEFAULT_BASEPATH);

		}

		return $this->_basePath;

	}


	/**

	 * Sets the root directory storing published asset files.

	 * @param string $value the root directory storing published asset files

	 * @throws CException if the base path is invalid

	 */

	public function setBasePath($value)

	{

		if(($basePath=realpath($value))!==false && is_dir($basePath) && is_writable($basePath))

			$this->_basePath=$basePath;

		else

			throw new CException(Yii::t('yii','CAssetManager.basePath "{path}" is invalid. Please make sure the directory exists and is writable by the Web server process.',

				array('{path}'=>$value)));

	}



EDIT: I hope it is not the dot, 'couse i’m sure they won’t fix it.

Since the condition that causes this exception does different tests at once, you should maybe first find out, which of the test is making the problem. This is the condition from the framework:


if(($basePath=realpath($value))!==false && is_dir($basePath) && is_writable($basePath))

So create a simple test.php with something like:




<?php

$dir='your/path/to/assets';


echo realpath($dir)===false ? 'Problem with realpath' : 'realpath ok';

echo '<br>';

echo !is_dir($dir) ? 'No dir' : 'dir ok';

echo '<br>';

echo !is_writeable($dir) ? 'not writeable' : 'writeable';



realpath ok

dir ok

writeable

If I use the ‘/assets’ for dir. Meaning relative path is ok, but absolute path is not.

I don’t know where does Yii gets the absolute path info, but that path is wrong in this context.

The absolute path Yii uses is ‘/hosting/atw.hu-users/c/s/csepelszigeti/assets’ which returns with error on realpath.

EDIT: Wait, does that mean I can set up Yii with a relative path, like in post#9?

UPDATE: Yes I can. HUH? So, i guess somewhere the paths get mixed up.

Explicitly setting the assets directory with relative-to-webroot path works.

This might be a special case where the server config is just wrong, plain stupid OR too-professional-for-others-to-understand.

Thanks for the help.

Now that’s the interesting part! Your main problem aren’t write permissions, but that realpath() returns false. You now should find out, why this is the case. To do this, check the PHP manual on realpath(). You probably use symlinks somewhere. Also concentrate on this note from the manual:

The realpath was the problem.

Somehow the path Yii gets back can’t be resolved by realpath, probably because of permissons on parent directories, as You quoted. I read that, but somehow skipped. Thanks

Uff… Mike was fast there :)

Congrats