0

In my symfony 2.2 app I wanted to use PHPExcel library. So I downloaded it, and copied contents of Classes library to /vendor/phpexcel directory:

vendor/
    phpexcel/
        PHPExcel/
        PHPExcel.php

After that I added the following to app/autoload.php directly below $loader = require ... line:

$loader = require __DIR__.'/../vendor/autoload.php';

//The following was added
$loader->registerPrefixes(array(
    'PHPExcel' => __DIR__ . '/../vendor/phpexcel'
));

// intl
...

Now if I browse to my web app, it returns HTTP Error 500 (Internal Server Error). I read the following post, but wasn't able to solve the problem: How to use PHPExcel correctly with Symfony 2 Can someone help me correct this?

Community
  • 1
  • 1
synergetic
  • 7,756
  • 8
  • 65
  • 106

3 Answers3

4

You should never manually download something and put it in the vendor directory. Composer manages the vendor directory, and hence it should be save to delete this directory and run composer install again. The vendor directory also is excluded from Git by default.

To install PHPExcel using composer, add it to composer.json:

"require": {
    ...
    "phpexcel/phpexcel": "1.7.*"
}

When installed with Composer, you should not need to worry about the autoloading either.

Gerry
  • 6,012
  • 21
  • 33
  • I followed your advice, and after "php composer.phar update" there is still the same server error. – synergetic Mar 29 '13 at 07:57
  • @synergetic, without knowing what the actual error is, it's impossible to comment. Are you getting the error in 'dev' environment? That should give some more detailed exception? If not, check your server logs. – Gerry Mar 29 '13 at 08:01
  • I checked error_log. It says Failed opening required '/var/www/html/taden/php/vendor/kriswallsmith/assetic/src/functions.php'. Maybe [this](https://github.com/composer/composer/issues/1714) one is related, but still didn't help me. – synergetic Mar 29 '13 at 10:52
  • By the way, if I just do "php composer.phar update phpexcel/phpexcel", then the error goes away. But now I have another problem: my code (new \PHPExcel()) doesn't find PHPExcel class. – synergetic Mar 29 '13 at 11:06
  • You probably need to revert the changes you made in autoload.php if you haven't already. – Gerry Mar 29 '13 at 11:47
  • @Gerry is right. Composer takes care of updating vendor/autoload.php for you. So just need the standard app/autoload.php file. – Cerad Mar 29 '13 at 13:14
1

I installed https://github.com/liuggio/ExcelBundle for PHPExcel. Bundle includes PHPExcel (addes related links to composer). You can easily use PHPExcel without wondering what the bundle says. Call new \PHPExcel(); then you move. I hope this bundle helps.

tigris
  • 404
  • 1
  • 5
  • 17
0

Composer seems to have a problem with SELinux. See this. Though not recommended, setting SELinux to permissive can be a workaraound.

synergetic
  • 7,756
  • 8
  • 65
  • 106