0

I'm a new linux user been trying to install laravel on opensuse. It took me a while because of permissions but was able to install it to a directory then moving it to htdocs. The problem is I can't run php command so I always use this

user@linux:/opt/lampp/bin> ./php -v
PHP 5.6.30 (cli) (built: Feb  1 2017 01:41:45)

user@linux:/opt/lampp/bin> ./php /opt/lampp/composer.phar create-project --prefer-dist laravel/laravel /any_directory_path/blog 

now i'm trying to run

php artisan serve

But i get this

If 'php' is not a typo you can use command-not-found to lookup the package that contains it

I tried

sudo apt-get install php5-cli

but I get

Package 'php5-cli' not found.

So how to fix this issue to be able to use php and composer as commands in the console

PHP User
  • 2,350
  • 6
  • 46
  • 87

1 Answers1

2

Installing the cli version of php wont be enough if you actually want to use this beyond development, you need to install as an apache module. There also doesn't seem to be a specific cli package on opensuse which is why you are getting this error.

php artisan serve is intended just for development purposes, it uses the inbuit php web server, which for many reasons should note be used on production servers (those used by actual users, available on the internet or even a private network).

The reason it's erroring is the php binary is not in your path - if you specify the full path it would run: /opt/lampp/bin/php artisan serve

You could add this to your path - this question/answer covers how to do this well: https://unix.stackexchange.com/questions/26047/how-to-correctly-add-a-path-to-path

You probably want to edit your ~/.profile file by editing or adding the following line PATH=$PATH:/opt/lampp/bin/ which would mean any commands inside /opt/lamp/bin/ would work without the full path needing to be entered each time.

Try sudo apt-get install php5

This tutorial should walk you through all the steps.

Also worth noting there is now php7 - are you specifically installing the older version for a reason?

Try sudo apt-get install php7

There are a number of modules which you may also require, you can see available packages on opensuse website

From comments it sounds like you will need openssl and phar at least, these can be installed like so:

sudo apt-get install php7-openssl php7-phar

Looking at the requirements for laravel

  • PHP >= 5.6.4
  • OpenSSL PHP Extension
  • PDO PHP Extension
  • Mbstring PHP Extension
  • Tokenizer PHP Extension
  • XML PHP Extension

You will also need to run:

sudo apt-get install php7-pdo php7-mbstring php7-tokenizer php7-xml


Regarding composer you should be able to get this installed by running

/opt/lampp/composer.phar install

If this doesn't solve it for you then this question should provide you with various options to try:

Community
  • 1
  • 1
Theo
  • 1,608
  • 1
  • 9
  • 16
  • I can use php as a command but there's a problem: I used "/opt/lampp/bin/php /opt/lampp/composer.phar create-project --prefer-dist laravel/laravel blog" it was installed but got an error: "PHP Parse error: syntax error, unexpected '.', expecting '&' or variable (T_VARIABLE) in PATH HERE/Illuminate/Foundation/helpers.php on line 477 Script php artisan optimize handling the post-update-cmd event returned with error code 255" Then: "php artisan PHP Parse error: syntax error, unexpected '.', expecting '&' or variable (T_VARIABLE) in PATH HERE/Illuminate/Foundation/helpers.php on line 477 – PHP User Feb 26 '17 at 17:56
  • and still can't use 'composer' as a command too. Thanks for your help so far and hope you can help me fixing this all. – PHP User Feb 26 '17 at 17:56
  • The syntax error sounds like it may be todo with the php version, as I doubt you have a copy of Illuminate/Foundation with a syntax error. if you type `/opt/lampp/bin/php -v` it will tell you your version, if it is less than 5.3 then this may well be your problem, but even if it is less than 5.6 then you are running an unsupported version that may have security issues. – Theo Feb 26 '17 at 18:06
  • @PHPUser I have updated my answer with some help on the composer side of things. – Theo Feb 26 '17 at 18:10
  • remved php5 installed php 7 and "/opt/lampp/composer.phar install" returns "PHP Fatal error: Uncaught Error: Class 'Phar' not found in /opt/lampp/composer.phar:23" – PHP User Feb 26 '17 at 18:13
  • That removed composer my bad i'll try to install it again then try what you mentioned – PHP User Feb 26 '17 at 18:24
  • trying to install composer php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" but i get "PHP Warning: copy(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? in Command line code on line 1 PHP Warning: copy(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? in Command line code on line 1 PHP Warning: copy(https://getcomposer.org/installer): failed to open stream: No such file or directory in Command line code on line 1" – PHP User Feb 26 '17 at 18:42
  • also tried "sudo curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer" but I get "Some settings on your machine make Composer unable to work properly. Make sure that you fix the issues listed below and run this script again: The phar extension is missing. Install it or recompile php without --disable-phar. The openssl extension is missing, which means that secure HTTPS transfers are impossible. If possible you should enable it or recompile php with --with-openssl" – PHP User Feb 26 '17 at 18:45
  • you need to install the openssl and the phar modules try `apt-get install php7-openssl php7-phar` – Theo Feb 26 '17 at 21:15
  • I have updated the answer with a link to laravel requirements and the other modules you will likely need. – Theo Feb 26 '17 at 21:25