Some people have had a hell of a time installing Composer on a shared DH account, well here's how I did it. I'm going to assume you know what a shell user is and how to use basic terminal.
DreamHost ocassionally introduces new PHP versions and removes older ones. To keep updated on what is supported, please check this link.
- A shared Dreamhost account
- Make sure your user is SFTP (shell access)
- I suggest updating your domain that your installing Composer on to run PHP 7.4.x w/ FastCGI
- Wait 5-10 minutes for everything to move to 7.4 (if your not there already)
-
Login via SSH (if you are not logged in already)
-
Navigate to ~/ (
$ cd ~/
) -
Create or edit the existing file (
$ nano .bash_profile
) -
On a new line copy and paste this code
export PATH=/usr/local/php74/bin:$PATH
-
Save the file and exit (CTRL+O then CTRL+X)
-
You may need to logout and log back in
-
If you've decided to run a different supported PHP version, make sure to update the export string in the path
-
Login via Putty or whatever flavor you like
-
Navigate to
$ cd ~/
-
Create the folder
$ mkdir -p ~/.php/7.4
-
Create the file
$ nano ~/.php/7.4/phprc
-
Pop these jewels into the file on seperate lines
extension = phar.so
suhosin.executor.include.whitelist = phar
pcre.jit=0NOTE: The first line may or may not be needed, in my case PHP 7.4 on Dreamhost already had the Phar extension enabled.
-
Save the file and exit (CTRL+O then CTRL+X)
-
After you've completed the above steps, log out of putty and then log back in, run the command
$ php -v
or of that does not work for you run$ php --version
and it should say that it's running PHP 7.4 CLI.It should look something like this:
PHP 7.4.3 (cli) (built: Feb 21 2020 00:45:59) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.3, Copyright (c), by Zend TechnologiesIf not, then you've messed up somewhere along the line.
-
Now you can run the following command in the directory you want to use Composer in (go to the directory first them run this command)
curl -sS https://getcomposer.org/installer | php
mv ~/.php/composer/composer.phar ~/.php/composer/composer -
You should see some installation success messages; this is good!
If you see the following error:
#!/usr/bin/env php
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-pharThis means you're on a DH server that has a different set of expectations for phrc. To fix it:
$ cd ~/.php $ mkdir 7.4 $ mv phprc 7.4/phprc
(or, if you're using PHP 7.4, that would be
$ mkdir 7.4
and$ mv phprc 7.4/phprc
) -
If you don't see any errors, it should have been installed correctly. Next add this handy line so we can access the Composer command globally: Run
$ nano ~/.bash_profile
and add this on a new line:export PATH=/home/your_username/.php/composer:$PATH
-
Try running
composer
, you should see a list of green and grey items, you've installed composer -
I'll assume from here on our you can read the Composer documentation and usage :)
You should not be able to run composer install
in your project folder.