Access composer.json /composer.phar - php

I have installed composer.phar in the following directory:
/public_html/composer
I have already added on package to the composer.json as below:
{
"require": {
"stripe/stripe-php": "2.*"
}
}
That was some time ago. I would now like to install another package, using composer. However, I cannot access it. I am trying to do the following in SSH/Terminal:
root#host [~]# composer.phar
-bash: composer.phar: command not found
Then I try to:
root#host [~]# cd public_html
root#host [~/public_html]# cd composer
-bash: cd: composer: No such file or directory
root#host [~/public_html]#
What am I doing wrong? In FTP I can see the composer is located in the /public_html/ folder, but I can't acccess it?
EDIT:
ls -l composer
gives me:
/bin/ls: Can't access composer: No such file or directory
Using ls -a I get:
./ .bwusage.sqlite error_log perl5/ .spamassassin/
../ .composer/ .forward php.ini.new .ssh/
.accesshash .cpanel/ .gnupg/ php.ini.orig support/
.bash_history cpanel3-skel/ .HttpRequest/ .pki/ .tcshrc
.bash_logout .cpanm/ .lesshst public_ftp/ tmp/
.bash_profile .cpobjcache/ .MirrorSearch/ public_html/ .trustwavereqs
.bashrc .cshrc .my.cnf .rnd .viminfo

The problem I believe is that /public_html/composer is under the root / and there is also a public_html under /root (home directory for root user) directory
use pwd to check where you are at the moment and use ls /public_html/composer to see if composer.phar is in this directory.
You can run: php /public_hmtl/composer/composer.phar.
In order to be able to run it as composer you must mv the composer.phar to a directory that is included in your PATH variable.
For example:
mv /public_html/composer/composer.phar /usr/bin/composer

So your structure is: public_html/composer/composer.phar
If so, then either navigate into the composer folder (cd public_html/composer), then issue the ./composer.phar or php ./composer.phar command.
You can excute it using relative/absolute paths (./public_html/composer/composer.phar or /srv/www/mysite/whatever/public_html/composer/composer.phar)
Please note, that you have to execute composer from the folder where your composer.json file is located.
In all cases you have to have access to the folder and the file itself.

Related

Unable to change file mode on bin: Operation not permitted

I'm trying to install Composer globally on Mac OS.
I tried to move the composer.phar file by using this command in Terminal as instructed in the Getting Started section:
mv composer.phar /usr/bin/composer
I get this error:
mv: rename composer.phar to /usr/bin/composer: No such file or
directory
When I try create the directory it says the operation is not permitted:
bash-3.2# mkdir -p /usr/bin/composer mkdir: /usr/bin/composer:
Operation not permitted
I even tried to navigate to the "bin" directory and it says:
bash-3.2# mkdir composer mkdir: composer: Operation not permitted
I've enabled root successfully but still I try and alter the permissions:
bash-3.2# chmod ugo+rwx "bin" chmod: Unable to change file mode on
bin: Operation not permitted bash-3.2#
What am I doing wrong here?
Thanks in advance!
EDIT:
Thanks for the responses!
When I type the following command:
ls -leO#d /usr/local/bin
It prints:
-rwxrwxr-x 1 username staff - 2212003 27 Mar 17:00 /usr/local/bin
Background: /usr/bin is generally for "standard" binaries, not things you install yourself; those generally belong someplace like /usr/local/bin. In recent versions of macOS, this is enforced by System Integrity Protection and by keeping "system" files/directories on a separate, read-only volume.
The problem: It looks like on your system, there's a file named /usr/local/bin rather than a directory. This can happen if some installer tries to install a program to /usr/local/bin (e.g. with mv someprogram /usr/local/bin) without first making sure a directory by that name exists.
How to solve it: The first thing to do is to move/rename whatever file got installed as /usr/local/bin, and then create it as a directory:
sudo mv /usr/local/bin /usr/local/bin-moved
sudo mkdir -p /usr/local/bin
Once that's straightened out, you should be able to install composer normally. According to this (and adding sudo to get access to the directory), you'd do that with:
sudo mv composer.phar /usr/local/bin/composer
Finally, if you want to, you can try to figure out what program got installed as (rather than in) /usr/local/bin. Or just delete the /usr/local/bin-moved file and don't worry about it.
/usr/bin is a protected system folder. Do not change its permissions.
Instead install it somewhere else, e.g. into /usr/local/bin. You may still need to run the copy command with sudo though: sudo mv composer.phar /usr/local/bin/composer

Cannot install "global" composer requirements because "composer.json is not writeable"

I want to install Laravel but again and again I got the below error,
rukon#rukon-HP-Notebook:~$ composer global require laravel/installer
Changed current directory to /home/rukon/.config/composer
./composer.json is not writable. rukon#rukon-HP-Notebook:~$
I tried to make writable composer.json by
$chmod 777 ./composer.json
but it's not working. my file owner is not root
When you run any composer global command, the composer.json used is the one at your HOME directory, not at your projects directory. E.g. at ~/.composer/composer.json.
Looks like your home directory composer is owned by root.
At some point you've executed composer with root and messed up your installation.
To find out where your composer's home directory is at, you should run this (as shown here):
composer config --list --global | grep home
E.g. given your output, it seems your home directory sits at "/home/rukon/.config/composer":
So you'd need to run:
sudo chown -R $USER: ~/.config/composer
To fix your "global" composer configuration directory.
You should be able to run composer global commands after that.
If you have more permissions problems, you'd better fix your home directory so everything in there is owned by your user, and nothing by root as shown here:
sudo find ~ -type d -user root -exec sudo chown -R $USER: {} +
For a regular installation the above should be safe (all the files in your home directory belong to to your own user), but if you have anything special in there you should probably be aware and take a more surgical approach (checking each directory).

composer require is not working on git bash(Wamp)

i have an issue that's occur,when i tried to use this command
composer require
in git bash this error occurs
enter image description here
Please tell me how i install my vendor packages.
I'll just leave this here. This worked for me.
Assuming composer is already available globally(if not, install composer globally first) in your path and it is working perfectly fine in your cmd.
And you are only having problems on git bash.
open cmd.
where composer
//outputs something like: C:\xampp\php\composer.bat
//mine is located in C:\xampp\php directory
go to composer directory
cd C:\xampp\php
make sure composer.phar is inside the directory
ls
outputs something like:
.
..
composer.bat
composer.phar
etc.
composer.phar is found. jackpot.
Your cmd is running the composer.bat file. git bash doesn't run .bat files so it throws an error.
Now just copy composer.phar into composer (no extension)
cp composer.phar composer
open git git bash and then:
composer --version
You're all set.

Uploading laravel project to cPanel

I'm trying to upload my laravel project to cPanel. But till now, it doesn't seems to be working.
I have moved following directories and files from my project into the directory 'lavravel' in root.
app/
bootstrap/
config/
database/
resources/
storage/
artisan
composer.json
composer.lock
.env
And moved files from my public folder to public_html
Now my directory looks like this.
I have made changes in following files.
laravel/bootstrap/app.php
/*
|--------------------------------------------------------------------------
| Public Path
|--------------------------------------------------------------------------
|
| Set the path to the Laravel "public" directory so that any files/packages
| that use app('path.public') to get the "public" path find the right path.
| DO NOT include a trailing slash on the path.
|
*/
$app->bind('path.public', function ()
{
return __DIR__.'/../../public_html';
});
public_html/index.php
require __DIR__.'/../laravel/bootstrap/autoload.php';
$app = require_once __DIR__.'/../laravel/bootstrap/app.php';
But, it doesn't seems to work. It displays a blank page. As you can see via this URL. nepalride.com
You should take a look at the Laravel
After uploading the files, make sure you set the correct permissions on the storage and bootstrap/cache folders.
Also, you need to run composer install to install the vendor packages required by Laravel. Your uploaded laravel folder doesn't have a vendors folder.
Look through the error logs and you will see all the issues you're encountering.
The easiest way to do it if you have ssh access is create a laravel directory with your app in. Then:
rm -rf public_html
ln -s laravel/public public_html
This deletes the current public_html (make sure there is nothing inside it you need before running it) and creates a symbolic link from public_html to your apps public folder.
manual path configuration of index.php will lead to problems down the road and so the proper way of configuring it would be to have ssh or terminal access. First make sure you have shell or terminal access(not usually accessible in shared hosting accounts).
Open terminal and check for php version
$ php -v
make sure php version is above the required version of your laravel app. if not change it to the latest available version.
Configure shell environment to use composer
$ echo 'alias composer="php -d allow_url_fopen=On /home/username/composer.phar"' >> ~/.bashrc
$ source ~/.bashrc
after that download and install composer on your cpanel account
$ cd ~
$ curl -k -O https://getcomposer.org/installer
$ php -d allow_url_fopen=On installer
make sure you have installed it
$ composer -v
go to the uploaded project either using ftp or git and run
$ composer install
to install dependencies
make sure your .env files are properly configured
run
$ php artisan key:generate
run migrations
$php artisan migrate
make sure you have proper access
$ chmod -R 775 storage
optimize your app
$ php artisan optimize
make app accessible to public by running
$ mv public_html public_html_old
create the symlink
$ ln -s /home/user/app/public /home/user/public_html
and all should be good and app should be running.

Running "sudo composer" won't work after installing properly

I have been trying to install composer on my Mac (running macOS Sierra). The composer.phar file is now located in /usr/local/bin/composer/ and it works properly when I'm not running composer as a root.
$ composer -V
Composer version 1.2.4 2016-12-06 22:00:51
However, when I try to run composer as a root (which of course is required to install dependencies), I get this:
$ sudo composer
sudo: composer: command not found
I have no single clue how to fix it, has anyone else had this?
it must be a composer.phar renamed to composer into /usr/local/bin/ , not a directory composer/
From : https://getcomposer.org/doc/00-intro.md
Globally#
You can place the Composer PHAR anywhere you wish. If you put it in a directory that is part of your PATH, you can access it globally. On unixy systems you can even make it executable and invoke it without directly using the php interpreter.
After running the installer following the Download page instructions you can run this to move composer.phar to a directory that is in your path:
mv composer.phar /usr/local/bin/composer
Note: If the above fails due to permissions, you may need to run it again with sudo.
Note: On some versions of OSX the /usr directory does not exist by default. If you receive the error "/usr/local/bin/composer: No such file or directory" then you must create the directory manually before proceeding:
mkdir -p /usr/local/bin
Note: For information on changing your PATH, please read the Wikipedia article and/or use Google.
Now just run composer in order to run Composer instead of php composer.phar.

Categories