How to Install Composer and Laravel in Ubuntu

Installing the composer in Ubuntu is simple and requires no extra required plugins, you only need a working PHP 7.2 and above, and a MySQL. To get started, let’s assume you already access your SSH console to your Ubuntu Server.

To get started, you need to be in the home directory cd /~. Then download the composer by entering this command. You can also grab the latest command at https://getcomposer.org/download/.

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'e0012edf3e80b6978849f5eff0d4b4e4c79ff1609dd1e613307e16318854d24ae64f26d17af3ef0bf7cfb710ca74755a') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

To test it is working, just do this command php composer.phar.

Once done, it will leave a file called composer.phar.

In order for us to call the command composer, we need to move this file at the /usr/local/bin directory. To move it, run this command.

mv composer.phar /usr/local/bin/composer

To see if it works, fire up the composer command. That’s it! By now, you finally installed a composer on your server.

Laravel

To install laravel in your system, run this command.

composer global require laravel/installer

Note, it will pop-up some security message like “Do not run Composer as root/super user! See https://getcomposer.org/root for details”. Since we only use Laravel for composer there will no problem and we think it’s secure enough. But when we use the composer for other frameworks, make sure to create a dedicated user to install this and do not log in as root.

It will then create a composer folder in ~/.config/composer.

So let’s proceed. In order for you to create a project by just calling laravel new your_new_project, we need to add in the path directory.

To see what’s currently in the path directory, just run echo $PATH. The output should be similar below.

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

For ubuntu, you can edit it at /etc/environment. So run vim /etc/environment.

Then add the :/root/.config/composer/vendor/bin. It should look like:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/root/.config/composer/vendor/bin"

To save the changes, run this command . /etc/environment.

To check if changes are made, run echo $PATH.

Right now, you can now call laravel in the command anywhere you want. To check if it’s working, run laravel -V. The output should look like below.

Laravel Installer 3.0.1

Leave a Comment

trabzon escort yalova escort Samsun escort izmit escort nazilli escort