Blog demo not working

I have been developing PHP for many years now and just recently started learning Yii.

I have installed Yii to a remote server following instructions in The Definitive Guide. Then I checked requirements using the built-in checker and everything seemed to be ok although i got warnings about these:

DOM extension	


PDO PostgreSQL extension	


Memcache extension	


APC extension	


Mcrypt extension	


SOAP extension	

Then i tried to run /demos/blog/ and it gave me Error 500 in the home, contact and about -pages:


copy(/path/to/yii-1.1.2.r2086/demos/blog/assets/8734a6e2/gridview/view.png)  [<a href='function.copy'>function.copy</a>]: failed to open  stream: No such file or directory

I think Yii is trying to use some jQuery component when this error occures…? So I checked /framework/vendors/ and found out that CGridView and CListView widgets uses jQuery BBQ Plugin 1.1.1. But /framework/vendors/bbq/ contains only LICENSE.TXT. Should there also be those .js files? Or do I have to upload & install those .js libraries manually?

Hi and welcome!

The error says, it can’t find the copy function of PHP, which is really strange as it’s a built in function. Do you maybe have safe mode enabled in PHP and restricted the available functions?

I’m sorry, i was wrong about the meaning of the error. It rather means, that the path couldn’t be found. Do you have the demos/blog/assets folder and is it writable for your webserver process?

Yes, the demos/blog/assets folder is there. It is empty and has 777 permissions so it should be writable.

I set the blog demo to debug mode and it gave me this output:




PHP Error

  

Description

copy(/var/www/html/yii-1.1.2.r2086/demos/blog/assets/8734a6e2/gridview/view.png)  [<a href='function.copy'>function.copy</a>]: failed to open  stream: No such file or directory

  

Source File

/var/www/html/yii-1.1.2.r2086/framework/utils/CFileHelper.php(123)


00111:         @mkdir($dst);

00112:         @chmod($dst,0777);

00113:         $folder=opendir($src);

00114:         while(($file=readdir($folder))!==false)

00115:         {

00116:             if($file==='.' || $file==='..')

00117:                 continue;

00118:             $path=$src.DIRECTORY_SEPARATOR.$file;

00119:             $isFile=is_file($path);

00120:             if(self::validatePath($base,$file,$isFile,$fileTypes,$exclude))

00121:             {

00122:                 if($isFile)

00123:                     copy($path,$dst.DIRECTORY_SEPARATOR.$file);

00124:                 else if($level)

00125:                     self::copyDirectoryRecursive($path,$dst.DIRECTORY_SEPARATOR.$file,$base.'/'.$file,$fileTypes,$exclude,$level-1);

00126:             }

00127:         }

00128:         closedir($folder);

00129:     }

00130: 

00131:     /**

00132:      * Returns the files found under the specified directory and subdirectories.

00133:      * This method is mainly used by {@link findFiles}.

00134:      * @param string the source directory

00135:      * @param string the path relative to the original source directory

   

Stack Trace

#0 /var/www/html/yii-1.1.2.r2086/framework/utils/CFileHelper.php(123): copy()

#1 /var/www/html/yii-1.1.2.r2086/framework/utils/CFileHelper.php(125): copyDirectoryRecursive()

#2 /var/www/html/yii-1.1.2.r2086/framework/utils/CFileHelper.php(61): copyDirectoryRecursive()

#3 /var/www/html/yii-1.1.2.r2086/framework/web/CAssetManager.php(162): copyDirectory()

#4 /var/www/html/yii-1.1.2.r2086/framework/zii/widgets/CListView.php(157): CAssetManager->publish()

#5 /var/www/html/yii-1.1.2.r2086/framework/web/CBaseController.php(148): CListView->init()

#6 /var/www/html/yii-1.1.2.r2086/framework/web/CBaseController.php(173): PostController->createWidget()

#7 /var/www/html/yii-1.1.2.r2086/demos/blog/protected/views/post/index.php(9): PostController->widget()

#8 /var/www/html/yii-1.1.2.r2086/framework/web/CBaseController.php(119): require()

#9 /var/www/html/yii-1.1.2.r2086/framework/web/CBaseController.php(88): PostController->renderInternal()

#10 /var/www/html/yii-1.1.2.r2086/framework/web/CController.php(748): PostController->renderFile()

#11 /var/www/html/yii-1.1.2.r2086/framework/web/CController.php(687): PostController->renderPartial()

#12 /var/www/html/yii-1.1.2.r2086/demos/blog/protected/controllers/PostController.php(136): PostController->render()

#13 /var/www/html/yii-1.1.2.r2086/framework/web/actions/CInlineAction.php(32): PostController->actionIndex()

#14 /var/www/html/yii-1.1.2.r2086/framework/web/CController.php(300): CInlineAction->run()

#15 /var/www/html/yii-1.1.2.r2086/framework/web/filters/CFilterChain.php(129): PostController->runAction()

#16 /var/www/html/yii-1.1.2.r2086/framework/web/filters/CFilter.php(41): CFilterChain->run()

#17 /var/www/html/yii-1.1.2.r2086/framework/web/CController.php(999): CAccessControlFilter->filter()

#18 /var/www/html/yii-1.1.2.r2086/framework/web/filters/CInlineFilter.php(59): PostController->filterAccessControl()

#19 /var/www/html/yii-1.1.2.r2086/framework/web/filters/CFilterChain.php(126): CInlineFilter->filter()

#20 /var/www/html/yii-1.1.2.r2086/framework/web/CController.php(283): CFilterChain->run()

#21 /var/www/html/yii-1.1.2.r2086/framework/web/CController.php(257): PostController->runActionWithFilters()

#22 /var/www/html/yii-1.1.2.r2086/framework/web/CWebApplication.php(320): PostController->run()

#23 /var/www/html/yii-1.1.2.r2086/framework/web/CWebApplication.php(120): CWebApplication->runController()

#24 /var/www/html/yii-1.1.2.r2086/framework/base/CApplication.php(135): CWebApplication->processRequest()

#25 /var/www/html/yii-1.1.2.r2086/demos/blog/index.php(11): CWebApplication->run()

2010-06-04 09:46:59 Apache/2.2.11 (Fedora) Yii Framework/1.1.2



Can you delete the content of this assets folder and try again?

The assets folder has always been empty. It still gives this error :huh:

Hmm, strange. You say, you have PHP experience, so maybe you can debug a little on your own. You should not really alter any framework files, but for debugging this might sometimes be necessary ;). Just be sure, to revert your changes afterwards again:

Check out, what’s going on in /framework/utils/CFileHelper.php and why it can’t copy to that path in line 123. It seems like @mkdir in line 111 is already failing, if your assets folder stays empty.

To make this clear: Things like these are very uncommon. So if you have another server available around, maybe try it there first.

I tried to install & run the blog demo in another server (debian) and it works ok there. So the problem is definitely now in the first test server (fedora). I’ll dive into CFileHelper.php later today and try to debug it more as you said.

Strange problem indeed… :mellow:

Okay, I have now found out that the servers SELinux feature is preventing the use of mkdir() function. I noticed than when I tried to run the blog demo, it inserts some error logs to SELinux log file in /var/log/audit/audit.log.

I then disabled selinux as instructed in http://www.crypt.gen…linux.html#DIS2

Then I ran Blog demo again and now it populates the /assets/ folder but crashes in the YiiBase.php:




PHP Error


Description

include(DOMDocument.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory


00326:      * @param string class name

00327:      * @return boolean whether the class has been loaded successfully

00328:      */

00329:     public static function autoload($className)

00330:     {

00331:         // use include so that the error PHP file may appear

00332:         if(isset(self::$_coreClasses[$className]))

00333:             include(YII_PATH.self::$_coreClasses[$className]);

00334:         else if(isset(self::$_classes[$className]))

00335:             include(self::$_classes[$className]);

00336:         else

00337:         {

00338:             include($className.'.php');

00339:             return class_exists($className,false) || interface_exists($className,false);

00340:         }

00341:         return true;

00342:     }

00343: 

00344:     /**

00345:      * Writes a trace message.

00346:      * This method will only log a message when the application is in debug mode.

00347:      * @param string message to be logged

00348:      * @param string category of the message

00349:      * @see log

00350:      */


stack trace:


#0 /var/www/path/to/yii/framework/YiiBase.php(338): autoload()

#1 unknown(0): autoload()

#2 unknown(0): spl_autoload_call()

#3 /var/www/path/to/yii/framework/vendors/htmlpurifier/HTMLPurifier.standalone.php(5849): class_exists()

#4 /var/www/path/to/yii/framework/vendors/htmlpurifier/HTMLPurifier.standalone.php(142): create()




Someone else had this problem as well. When you look at line 5849 of HTMLPurifier, it says:




                if (

                    class_exists('DOMDocument') &&

                    method_exists('DOMDocument', 'loadHTML') &&

                    !extension_loaded('domxml')

                ) {

                    // check for DOM support, because while it's part of the

                    // core, it can be disabled compile time. Also, the PECL

                    // domxml extension overrides the default DOM, and is evil

                    // and nasty and we shan't bother to support it

                    $lexer = 'DOMLex';

                } else {

                    $lexer = 'DirectLex';

                }



So blog demo is obviously using HTMLPurifier (?) and trys to load the xml dom extension which is not installed on your server.

// If you can’t install the dom extension or there is no other solution, simply modify the line like this:




                if (

                    false

                ) {



That should make it I guess. File is in /framework/vendors/htmlpurifier/HTMLPurifier.standalone.php

If local testing add the php_soap extension to your php.ini file… and restart your server ;)

If live you will need to ask you provider to include the extension…

I’m not sure if this is related… I hope this is a good place to post this.

I’m running Fedora, which uses SELinux. When I tried the “Web Service Stock Demo” - it didn’t work - giving a Permission Denied error. So I did a “setenforce 0” and tried again. It worked.

However, I want to be able to have SELinux enabled. So, I did some digging. To get SOAP to work correctly I found that I needed to do a "setsebool -P httpd_can_network_connect 1" command. Now, everything is working how it should and SELinux is still enforcing.

I hope someone will find this post useful, because it took me a long time to find the answer to this. Hence this post.