To install Laravel in Ubuntu 20.04, you’ll first need to install composer. To install composer, execute the commands below.
sudo apt update
sudo apt upgrade -y
sudo apt install composer php-zip php-xml -y
I assume you had read through my previous stories on how to install Apache and how to install PHP, directory permission should have been configured correctly.
cd /var/www
laravel new blog
sudo chown -R www-data: blog
If you are unable to execute the command “laravel”. Verify if “$HOME/.config/composer/vendor/bin” is in your PATH. To check your PATH, use the command below
echo $PATH
If not found, you can add it in with the command below. After adding it you will need to logout and login again for the PATH to take effect.
echo 'PATH="$HOME/.config/composer/vendor/bin:$PATH"'|tee -a ~/.profile
I’m assuming you do not own a domain yet. We will be editing the default Apache sites enabled config file. Change the DocumentRoot path like the screenshot below
cd /etc/apache2/sites-available
sudo cp 000-default.conf 000-default.conf.bak
sudo vim 000-default.conf
Reboot Apache after saving the configuration. With your web browser, you should see something similar to the screenshot below.
sudo systemctl restart apache2