Viewed   663 times

I have installed Laravel using composer without problems, but when I try to execute "laravel" in my terminal I have this typical error:

-bash: laravel: command not found

If I read the documentation of the official site I need to do that:

Make sure to place the ~/.composer/vendor/bin directory in your PATH so the laravel executable is found when you run the laravel command in your terminal.

But I don't know how to do (I'm new on terminal console commands).

Can you help me with that? Thanks!!

 Answers

1

Ok, I did that and it works:

nano ~/.bash_profile 

And paste

export PATH=~/.composer/vendor/bin:$PATH

do source ~/.bash_profile and enjoy ;)

Important: If you want to know the difference between bash_profile and bashrc please check this link

Note: For Ubuntu 16.04 running laravel 5.1, the path is: ~/.config/composer/vendor/bin

On other platforms: To check where your Composer global directory is, run composer global about. Add /vendor/bin to the directory that gets listed after "Changed current directory to ..." to get the path you should add to your PATH.

Sunday, September 4, 2022
4

tl;dr

Run composer install in your project's root folder.

Explanation

This happens when you create a project by downloading and extracting the laravel/laravel repo from GitHub, not by using the Composer command:

composer create-project laravel/laravel your-project-name

In this case the dependencies are not installed, so the vendor folder that contains Artisan doesn't exist. Running composer install in your project's root folder will install the dependencies vendor folder.

For more, see my other answer on how to install Artisan.

Side note

This is independent from your problem but your Artisan command is a bit deficient. You forgot =users (the table name) from the end. Also if you create a table you dont have to specify the table name again with the --table option so this command would be enough:

php artisan migrate:make create_users_table --create=users
Thursday, November 17, 2022
 
4

Whenever you install XAMPP, you get all of the Apache, MySQL, PHP stack. The problem is, XAMPP won't link binaries to your PATH, because your could have another version of that software already installed.

Composer needs a PHP version available on your PATH, so the easier option is to link your already installed version of PHP.

I think you can find your PHP binary in /opt/lamp/bin so you can link it this way:

sudo ln -s /opt/llamp/bin/php /usr/bin/php

Hope it works!

If you want to double check your PHP binary location you can go to files then at the end you can find "other locations" click it and then go and check it.

Tuesday, December 6, 2022
1

You have to gain access over STDERR and, probably, STDOUT. Use proc_open, e.g.:

$desc = [
  1 => ['pipe', 'w'], // STDOUT
  2 => ['pipe', 'w'], // STDERR
];

$proc = proc_open('ls -l . something', $desc, $pipes);
if (is_resource($proc)) {

  if ($out = stream_get_contents($pipes[1])) {
    echo $out;
  }
  fclose($pipes[1]);


  if ($err = stream_get_contents($pipes[2])) {
    fprintf(STDERR, "Error: %sn", $err);
  }
  fclose($pipes[2]);

  // You can also check the process exit status
  // 0 means success, otherwise error.
  $exit_status = proc_close($proc);
}

Of course, there is no need in STDOUT pipe, if the command redirects it to a file.

And yes, system() won't throw exceptions. Obviously, you can implement your own class which will throw an exception in case if the process exit status is non-zero, or there is something caught in the STDERR pipe:

class MyShellException extends Exception {}

class MyShell {
  public static function execute($command, &$out = null) {
    if (func_num_args() > 1) {
      $desc[1] = ['pipe', 'w'];
    } else {
      $desc[1] = ['file', '/dev/null'];
    }

    $desc[2] = ['pipe', 'w'];

    $proc = proc_open($command, $desc, $pipes);
    if (is_resource($proc)) {
      if (isset($pipes[1])) {
        $out = stream_get_contents($pipes[1]);
        fclose($pipes[1]);
      }

      if ($err = stream_get_contents($pipes[2])) {
        fclose($pipes[2]);
        throw new MyShellException("Command $command failed: $err");
      }

      if ($exit_status = proc_close($proc)) {
        throw new MyShellException("Command $command exited with non-zero status");
      }
    }
  }
}


try {
  MyShell::execute('ls -l . something', $out);
  echo "Output: $outn";
} catch (MyShellException $e) {
  if (!empty($out)) {
    echo "Output: $outn";
  }
  fprintf(STDERR, "MyShell error: " . $e->getMessage());
  exit(1);
}
Monday, December 26, 2022
3

Got fixed after setting path for composer vendors.So the correct step which worked is,

Download laravel installer: composer global require "laravel/installer=~1.1"

Setup PATH: export PATH="~/.composer/vendor/bin:$PATH"

Then run command : laravel new project-name or sudo laravel new project-name

For mac,

echo 'export PATH="$HOME/.composer/vendor/bin:$PATH"' > ~/.bashrc
source ~/.bashrc

Ubuntu 16.04 with latest laravel installer

Install composer if not exists,

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '55d6ead61b29c7bdee5cccfb50076874187bd9f21f65d8991d46ec5cc90518f447387fb9f76ebae1fbbacf329e583e30') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
sudo mv composer.phar /usr/local/bin/composer

Install laravel installer,

composer global require "laravel/installer"

Edit environment config,

nano .bashrc

Then add,

export PATH="$PATH:$HOME/.config/composer/vendor/bin"

Then reload path config,

source ~/.bashrc

Ubuntu 17.04 and 17.10:

export PATH="~/.config/composer/vendor/bin:$PATH"

Ubuntu 18.04

export PATH="$HOME/.composer/vendor/bin:$PATH"
Tuesday, November 29, 2022
 
camelcc
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :