I am trying to install composer on my shared host for the first time.
When I run curl -sS https://getcomposer.org/installer | php
I am getting a Composer successfully installed
User it: php composer.phar
when I run php composer.phar i am getting this warring error:
Warning: Composer should be invoked via the CLI version of PHP, not the cgi-fcgi SAPI
any ideas on how to fix this ? and why i am getting this error ? :(
when I run php -v i get this back
PHP 5.4.39 (cgi-fcgi) (built: Mar 25 2015 14:20:20)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
with Zend Guard Loader v3.3, Copyright (c) 1998-2013, by Zend Technologies
Do I need to run this using CLI version if so how would i do this ?
Any help would be nice thank you.
I resolved this by explicitly calling the version of PHP it asked for. Keep in mind that on a shared server environment there is often multiple versions of PHP running and even though you may have set up your default in your cPanel config, bash commands often resolve to another (lower) version.
First, I created a bin directory and moved composer.phar into it. Then, I added this alias to my .bash_profile and it worked like a charm:
alias composer="/usr/php/54/usr/bin/php-cli ~/bin/composer.phar"
Hope this helps!
As Composer is now available via WHM you can use this to find it:
which composer
This returned path "/opt/cpanel/composer/bin/composer" for me. If this returns nothing then disregard the rest of this answer, as Composer is not available to you at system level.
You can now use php-cli to call this with Composer's absolute path:
php-cli /opt/cpanel/composer/bin/composer install
php-cli /opt/cpanel/composer/bin/composer update
php-cli /opt/cpanel/composer/bin/composer require whatever/example
You may however need to alias php-cli if your system claims this isn't found. It very much depends how PHP has been deployed on the WHM server. You can do this by adding a user alias to the end of your ".bashrc" file as follows:
alias php-cli=/opt/cpanel/ea-php72/root/usr/bin/php
Replace ea-php72 with the release of PHP you want to use. Submit this as a command in the shell to make it available immediately, otherwise it'll become available when you open your next Bash session.
If you want to make this available with just composer alone you could create this alias again in ".bashrc":
alias composer=/opt/cpanel/ea-php72/root/usr/bin/php /opt/cpanel/composer/bin/composer
Or
php-cli $(which composer) ...
The location of the php versions installed will vary from host to host. Try finding them with:
locate /bin/php
For me this lists all php versions and I can then replace php with, for example:
/usr/bin/php71-cli
To access the command line interface version rather than the default cgi one. Then as stated by #Diggery you can create an alias.
alias composer='/usr/bin/php71-cli bin/composer.phar'
There are many suggestions on StackOverflow on how to test for a cli installation but the above is the only one that worked for me.
I have made a script to handle changes in composer/vendor. The script works with ftp-only servers, sends/removes only the changed files. Maybe someone will find it useful.
https://github.com/psad73/tune-composer
Related
Hello i'm trying to run my laravel project on live server using shared hosting after i upload all project file and directory and open my domain address it gives me error
Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.1.8".
and yes i was set up the php version on composer.json as "php": "^8.1.8", and "php": "^8.1.8" on composer.lock and when i run the project in local machine it's running as expected without any error. i also check my php version on my shared hosting by using php -v and it's return:
PHP 8.1.8 (cli) (built: Jul 14 2022 13:17:16) (NTS)
Copyright (c) The PHP Group
and on my local machine using php -v it return:
PHP 8.1.8 (cli) (built: Jul 5 2022 23:04:29) (ZTS Visual C++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.1.8, Copyright (c) Zend Technologies
i'm already find similar problem but none help to solve this...
Thanks to suggestion from #TeachMe and #ErDiablo, i finally know way to encounter this errors, first the composer installed on the project will need to regenerate using composer install
but since i'm using shared hosting so i using composer install --no-scripts insteed because the limitation to access the direcetory from hosting providers and after using that commands, continue with type:
php -r "file_exists('.env') || copy('.env.example', '.env');"
php artisan key:generate
php artisan cache:clear
php artisan view:clear
php artisan package:discover
This will help to generate key, package, .env file, and clear cache.
after using all that commands, open your domain and everything should be done.
Notes:
if still got the same error it can be possible caused by the php selector that provided by cPanel i once get this error, it seems that the composer was confused to get php version (maybe that the shared hosting have multi php version installed) or host / domain was loaded the different php version with that provided from php -v so you will need to make your domain to use php version selector that provided by cpanel and make sure your domains not using multiPHP Manager and also make sure that the php version from php version selector point to the same version on composer.json (if you not using cpanel, you will need to find way to change the version via termial or ssh)
I'm a begginer in Laravel and I installed XAMPP as local server. I noticed that my XAMPP already install php 7.4 as it's dependency. But when I tried php -v in www dir in php it shown.
'php' is not recognized as an internal or external command, operable
program or batch file.
But in php directory is shown
PHP 7.4.15 (cli) (built: Feb 2 2021 20:47:45) ( ZTS Visual C++ 2017
x64 ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c)
Zend Technologies
So, should I install additional php in my system for development? Should the version of the php matche with XAMPP php 7.4?
php -v will only tell you if you have PHP installed as a command line interface (PHP-CLI) which would enable you to run php code in cmd.exe or powershell. You'd normally not need this, but for reference here's how to enable it: https://stackoverflow.com/a/10753133 (mind the comment on Windows 10).
To check if PHP runs in your webserver environment (which is by default available in xampp), create a file test.php in your www folder with the following content:
<?php
phpinfo();
?>
Call this file in a browser, you will get an overview of all php features available. Delete the file before you go productive, because it will also give hackers a lot of information (which you don't want).
Try to add XAMPP PHP to Environment Variables
here is an instructions for Windows 10
I'm currently using Raspbian Wheezy 7.0 right now. Since PHP 5.6 is not available on the apt repositories for wheezy, I decided to build it from source. The build worked perfectly, I didn't receive any errors from it.
So when I used php -v it gave me the following output.
PHP 5.6.10 (cli) (built: Sep 18 2016 09:23:21)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
Ok, I thought. Perfect, everything is updated like it should be.
Here's where the problem comes in. For some reason, when I use phpinfo() on my apache2 server. It says that I'm still on version 5.4.45.
My first guess was that the module apache was using libphp5.so located in /usr/lib/apache2/modules/ was out of date. But, I have no idea where the libphp5.so module is for the new php version that I just installed is.
It'd be great if anyone could help me with this or point me in the right direction. I'm using Apache version 2.2.
As you can see from your console, php -v is the CLI binary. When building PHP you can build many different binaries for different SAPIs (Server APIs), one of them being CLI. Apache2 Handler or mod_php would be another one. In order to build your PHP as an Apache httpd module you need to make sure you include the --with-apxs2 configuration option when compiling from source. This means running ./configure --with-apxs2 before you make; make install; the binary. You then need to make sure to load the newly built libphp5.so or mod_php.so (however you built it) to the appropriate directly and load it from your Apaache httpd config. Where your newly compiled binaries are stored, depends on your compile time configuration options and environment, but typically they are located in $PREFIX/$HOME/bin. So for example, if you compiled --with-prefix=/usr you might get /usr/php/bin/libphp5.so, but typically the binary is moved for you by make install. You do need to make sure you restart httpd for the newly built binary to be loaded.
See the PHP manual on installation for more details.
I'm using CentOS 7's remi and remi.safe repository. Remi installs PHP 5.4 to /bin/php and Remi Safe installs PHP 5.6 to /bin/php56.
When php is executed from the console, I want it to reference php56. Yesterday I set alias php=/etc/php56 which seemed to have resolved the issue. Today, when I execute php -v it outputs:
PHP 5.4.16 (cli) (built: Jun 23 2015 21:17:27)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
Edit:
I added alias php=/bin/php56 to /home/{user}/.bashrc, logged out and logged back in and it did resolve it for that user.
Is it recommended, to set this globally, to do so via /etc/bashrc?
Do you need both version (5.4 and 5.6) ?
If you want a single version, enable "remi-php56" and yum update.
See: http://rpms.remirepo.net/wizard/
Else run "scl enable php56 bash" before other commands to switch to php 5.6.
See: http://blog.remirepo.net/post/2014/08/25/PHP-5.6-en-Software-Collection
Permanent solutions:
in .bashrc => source /opt/remi/php56/enable
ln -s /usr/bin/php56 /usr/bin/php
But again, if you need a single version, seems much more simpler to use "base" packages instead of "SCL" packages, designed for parallel installation of multiple versions.
use this to run the PHP command from the command line
php -c /etc/php5.4/cli/php.ini -f scripts.php
The problem:
I have installed Composer and followed the Quick start guide in the Laravel 4 documentation.
I get the following error when I run composer install or composer update:
Script php artisan optimize handling the post-install-cmd event
returned with an error...
I tried to run the following composer command:
composer create-project laravel/laravel myproject --prefer-dist
Or use their laravel.phar:
laravel new myproject
Or get the zip version from git: https://github.com/laravel/laravel?source=c
And I still fail to update via composer.
Additional information:
My PHP version on my Mac is:
PHP 5.4.17 (cli) (built: Aug 25 2013 02:03:38)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0,
Copyright (c) 1998-2013 Zend Technologies
PHP version on MAMP: 5.4.10
I found some solutions on Google / Stack Overflow but those did not work well in my case.
It says:
MCrypt PHP extension required
So it looks like you're missing the Mcrypt extension, which is required by Laravel (actually, I think it's used only by the Authentication class for password handling, not for the rest of the components of the framework).
I haven't got a Mac, but the command to install it should be something like this, using Homebrew
brew tap josegonzalez/php
brew install mcrypt php54-mcrypt
These links might help you:
http://www.jorble.com/2013/04/install-php-mcrypt-in-macosx/
http://coolestguidesontheplanet.com/install-mcrypt-php-mac-osx-10-9-mavericks-development-server/
Having the setting xdebug.scream = 1 in the configuration was the cause of the problem for me. I fixed it by doing the following:
Find XDebug configuration file.
$ sudo find / -name xdebug.ini
Edit file using any text editor.
$ sudo vi /your_path/xdebug.ini
Set xdebug.scream = 0
Reload the server (Apache/Nginx/whatever).
$ sudo service nginx reload
You might have Mcrypt installed already on your computer, if you are using MAMP or any other application. So, you don't need to install Mcrypt again. Add the following code to a php file and place it in your htdocs directory. See the info about the PHP you are running. You can see whether Mcrypt is already installed or not.
<?php
phpinfo();
If it shows Mcript, then do the following:
Check which PHP version you are using. You can see different directories for different PHP versions in this directory: /Applications/MAMP/bin/php/.
Move to the user's home directory. Use this command on terminal: cd ~.
Edit (or create a new one if not exists) .bash_profile file.
Add the following line:
where php5.5.10 is the directory of the PHP version you are using.
export PATH=/Applications/MAMP/bin/php/php5.5.10/bin:$PATH
Now restart your computer. And you can use php artisan command of Laravel.
Source of information: Laravel requires the Mcrypt PHP extension