How to Install Laravel on Ubuntu 22.04 / Ubuntu 20.04
It was developed by Taylor Otwell and based on Symfony. Taylor Otwell created Laravel to provide an alternative to the CodeIgniter framework.
Install PHP 8 on Ubuntu 22.04
Laravel requires PHP version 8 or newer. Since Ubuntu 22.04 comes with PHP 8.1, you do not need to get PHP packages from external repositories. However, for Ubuntu 20.04, you need to set up the Ondřej Surý repository to install PHP 8.1.
Install PHP and a few other extensions with the below command.
sudo apt update sudo apt install -y php php-common php-cli php-gd php-mysqlnd php-curl php-intl php-mbstring php-bcmath php-xml php-zip
Then, check the PHP version post the installation of packages.
PHP 8.1.2 (cli) (built: Apr 7 2022 17:46:26) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.2, Copyright (c) Zend Technologies with Zend OPcache v8.1.2, Copyright (c), by Zend Technologie
Install PHP Composer on Ubuntu 22.04
Install Composer, a dependency manager for PHP that will help download and install Laravel with the necessary components for the application development.
sudo apt install -y curl curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/bin --filename=composer
Then, verify the composer version.
Composer version 2.3.5 2022-04-13 16:43:00
Install Laravel on Ubuntu 22.04
After installing PHP composer on your system, create a Laravel project with the composer.
composer create-project laravel/laravel my_example_app
Now, go to the project directory.
Then, start Laravel’s local development server using the
artisan serve command.
php artisan serve
You will get the message something like this.
Starting Laravel development server: http://127.0.0.1:8000 [Wed Apr 27 23:28:24 2022] PHP 8.1.5 Development Server (http://127.0.0.1:8000) started
By default, Laravel listens on the localhost with port 8000. However, you can use the –host and –port options to change the listening IP address and port of Laravel, respectively.
php artisan serve --host 192.168.0.10 --port 8000
You can open up your browser and access the Laravel development server with the IP address and the port number displayed in the previous command output.
You will now get the below web page.