How I set up Laravel Development Environment on Ubuntu 20.04?
P.S. I have included all the things I have done step by step so at first, skim through the steps and then you will get a clear idea from where you need to start also at the end I have included straight-forward steps :)
These are the steps that I used to setup Laravel Environment👨🏼💻
Before we install Laravel we need to set up our Ubuntu with Apache and MySql so without further ado let’s dive into the topic:
- Here, I am using XAMPP instead of installing different packages of Apache and MySql which you can also do by clicking here,
- There are different ways of installing Laravel but here I have used composer to install Laravel as it’s one of the trouble-free methods
- First, we need to download Composer.
$ curl -sS https://getcomposer.org/installer | php
Next, we have to make sure Composer can be used globally and make it executable. The following commands will take care of that.
$ sudo mv composer.phar /usr/local/bin/composer
$ sudo chmod +x /usr/local/bin/composer
Then after doing this make sure that while entering composer you get certain results as in the image attached below:
$ composer
If the command is working then create a project using:
$ composer create-project — prefer-dist laravel/laravel [project_name]
OR,
$ composer create-project laravel/laravel [project_name]
I got some errors while creating the project so I found that Composer is not globally accessible so, 🤥
Make sure to place Composer’s system-wide vendor bin directory in your $PATH so the Laravel executable can be located by your system:
For that open Bashrc by:
$ sudo nano .bashrc
then add:
$ export PATH=”$PATH:$HOME/.config/composer/vendor/bin”
And make sure that the ‘laravel’ command also gives you results as:
but it didn’t work so I had to do:
$ composer global require “laravel/installer=~1.1”
And now I was able to create my project with the name gca-laravel-project and go to the project directory by
$ cd gca-laravel-project
Then to run our project:
$ php artisan serve
Also after this, the server was not running and it threw the error as:
So I found that this error has appeared because of using XAMPP on my local for PHP,
But in our server, we’re missing ext-dom. php-xml which has all the related packages you need. So, you can simply install it by running:
sudo apt-get update
sudo apt install php-xml
Nextly, I had to update the composer using:
$ composer update
And finally, after this, I was able to run my project successfully 🥳
$ php artisan serve
Then you can use the address http://127.0.0.1:8001/ since 8000 port is already used to make your project live on the browser as in picture 😇
Straight-forward Steps:🕵️
Make sure that you have installed Apache and MySQL through the method you prefer then,
1) Install Composer: https://getcomposer.org/download/
php -r “copy(‘https://getcomposer.org/installer', ‘composer-setup.php’);”
php -r “if (hash_file(‘sha384’, ‘composer-setup.php’) === ‘756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3’) { echo ‘Installer verified’; } else { echo ‘Installer corrupt’; unlink(‘composer-setup.php’); } echo PHP_EOL;”
php composer-setup.php
php -r “unlink(‘composer-setup.php’);”
check whether the composer is installed or not by :
$ composer
2) After that we need to install laravel:
$ composer global require laravel/installer
check whether laravel is on the path or not through :
$ laravel
If it’s not seen then you need to do add composer on your path, so to verify if the path has been added or not, enter:
$ echo $PATH
you need to see a composer on the path if it’s included in the bin
else do a quick google search to add composer on the path
Then finally you are all set if the ‘laravel’ command is working ;)
to run the project after entering into the project directory,
$ sudo artisan serve
Then you can run the server from the desired IP address: In this case enter URL as http://127.0.0.1:8000/ then you will find your project running, Congratulations🥳
Thank you ;)
Hope it helps✌️