1

I'm building a website with PHP framework "Slim" as my templating framework, and it recommends using composer as the package manager. SO... I'm now using composer for the first time, developing locally on 64 bit Ubuntu 16.04 and composer is not installing anything into my project.

I've followed the installation instructions on the Slim Framework & Composer websites to a tee.

Basically this is the order of what I've done:

  1. Installed composer into /var/www/html directory [1.]

  2. Created Slim project using Slim-Skeleton as a base

    php composer.phar create-project slim/slim-skeleton slimLittleTest

Note: the php composer.phar create-project slim/slim-skeleton command automatically creates a composer.json file, I will put the contents of that file down farther in my question.

  1. Change into that directory and run php composer.phar install

  2. Nothing is installed!

If I try to run php -S localhost:8080 -t public public/index.php as you're now supposed to able to (from the Slim framework website homepage tutorial) I get the following error:

[Tue Sep  5 18:55:04 2017] PHP Fatal error:  require(): Failed opening required '/var/www/html/slimLittleTest/public/../vendor/autoload.php' (include_path='.:/usr/share/php') in /var/www/html/slimLittleTest/public/index.php on line 12
[Tue Sep  5 18:55:05 2017] PHP Warning:  
require(/var/www/html/slimLittleTest/public/../vendor/autoload.php): failed to open stream: No such file or directory in /var/www/html/slimLittleTest/public/index.php on line 12

This error of course makes sense because nothing got installed! There is no vendor/autoload.php because Composer hasn't installed anything. (By default Composer installs dependencies into the vendor folder in the root of your project)

SEPTEMBER 7th QUESTION UPDATE

From some comments down below, I've been alerted to the fact that something must have gone wrong on the command composer create-project, that my solution of just re-requiring all packages shouldn't be necessary. Upon further inspection, I did get some errors upon running command php composer.phar create-project slim/slim-skeleton projectName. Below is exactly what got output from the console after running that command:

php composer.phar create-project slim/slim-skeleton tester
Installing slim/slim-skeleton (3.1.2)
  - Installing slim/slim-skeleton (3.1.2): Loading from cache
 Created project in tester
 Loading composer repositories with package information
 Updating dependencies (including require-dev)
 Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - phpunit/phpunit 5.7.9 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 5.7.8 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 5.7.7 requires ext-dom * -> the requested PHP extension dom is missing from your system.
   [.......]

 To enable extensions, verify that they are enabled in your .ini files:
- /etc/php/7.0/cli/php.ini
- /etc/php/7.0/cli/conf.d/10-mysqlnd.ini
- /etc/php/7.0/cli/conf.d/10-opcache.ini
- /etc/php/7.0/cli/conf.d/10-pdo.ini
- /etc/php/7.0/cli/conf.d/20-calendar.ini
- /etc/php/7.0/cli/conf.d/20-ctype.ini
- /etc/php/7.0/cli/conf.d/20-curl.ini
- /etc/php/7.0/cli/conf.d/20-exif.ini
- /etc/php/7.0/cli/conf.d/20-fileinfo.ini
- /etc/php/7.0/cli/conf.d/20-ftp.ini
- /etc/php/7.0/cli/conf.d/20-gettext.ini
- /etc/php/7.0/cli/conf.d/20-iconv.ini
- /etc/php/7.0/cli/conf.d/20-imagick.ini
- /etc/php/7.0/cli/conf.d/20-json.ini
- /etc/php/7.0/cli/conf.d/20-mbstring.ini
- /etc/php/7.0/cli/conf.d/20-mcrypt.ini
- /etc/php/7.0/cli/conf.d/20-mysqli.ini
- /etc/php/7.0/cli/conf.d/20-pdo_mysql.ini
- /etc/php/7.0/cli/conf.d/20-phar.ini
- /etc/php/7.0/cli/conf.d/20-posix.ini
- /etc/php/7.0/cli/conf.d/20-readline.ini
- /etc/php/7.0/cli/conf.d/20-shmop.ini
- /etc/php/7.0/cli/conf.d/20-sockets.ini
- /etc/php/7.0/cli/conf.d/20-sysvmsg.ini
- /etc/php/7.0/cli/conf.d/20-sysvsem.ini
- /etc/php/7.0/cli/conf.d/20-sysvshm.ini
- /etc/php/7.0/cli/conf.d/20-tokenizer.ini
You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.

Would either that .ini extensions issue or Problem 1 php unit requires ext-dom issue be the main source of my problem?

Zach Cook
  • 604
  • 12
  • 33
  • 1
    have you created a `composer.json` file to declare your project's dependencies ? – YvesLeBorg Sep 06 '17 at 00:18
  • yep. there is one created automatically by the `create-project slim/slim-skeleton [project_name]` command. I will edit the question to make that clearer! – Zach Cook Sep 06 '17 at 00:21
  • 1
    when installing , try `composer -vvv install` to get (highly verbose) status. Also run `composer info` in your directory , see what gives, and when in doubt, there is also the highly useful `composer -help` – YvesLeBorg Sep 06 '17 at 00:35
  • hey thanks mate, just found a solution moments ago though. @YvesLeBorg – Zach Cook Sep 06 '17 at 00:39

1 Answers1

0

I got lucky and stumbled upon an answer that worked in my situation.

I just had to run php composer.phar require [package_name], for each package name, and if it wasn't in composer.json yet that dependency would get installed. So what I needed to do was delete the composer.json file, then go back and require each package from it. Nothing else worked, such as php composer.phar update, or php composer.phar install.

So I ran php composer.phar require slim/php, php composer.phar require php, etc. from the command line and everything installed correctly.

This is potentially a failure of the getting started documentation from SlimFramework.com, It's not necessarily "wrong" because maybe it works in some/most situations, but they should at least address the potential for the problem I ran into, and a solution or way to avoid it.

EVEN BETTER SOLUTION

Turns out that the main error I was getting here is that I was missing ext-dom. Thank you to this badass @Anar Bayramov's answer on another StackOverflow question I know that I can get the missing ext-dom by simply downloading php7.0-xml.

sudo apt-get update
sudo apt-get install php7.0-xml

And BOOM! Now when I run php composer.phar create-project slim/slim-skeleton projectName all vendor packages are installed successfully and it works like a charm. Problem solved.

Zach Cook
  • 604
  • 12
  • 33
  • 1
    If that's necessary, something must have gone wrong before as `composer create-project` will automatically install all dependencies required by the application you are setting up. Are you sure that the `create-project` command did not run into any errors? – xabbuh Sep 07 '17 at 10:58
  • 1
    You do not need to do this. Something else went wrong n the beginning. – Mika Tuupola Sep 07 '17 at 12:57
  • Ok this I'll put what the console output in the question then – Zach Cook Sep 07 '17 at 19:15