How To

Install Laravel on Ubuntu 18.04 with Composer: Setup Guide

Laravel is an open-source PHP web application framework built around an expressive, developer-friendly syntax. It is used to build REST APIs, full-featured web applications, and eCommerce platforms, and it is the most popular PHP framework in the world by adoption.

Laravel ships with built-in routing, authentication, sessions, caching, queues, and unit testing. This makes it possible to build production-ready applications without reaching for separate libraries for every common feature.

This guide covers how to install Laravel on Ubuntu 18.04 using Composer, the standard PHP dependency manager. The same steps work on Ubuntu 16.04, Linux Mint, Kubuntu, and Elementary OS.

<strong>Prerequisite:</strong>&nbsp;You need sudo access. Run&nbsp;<code>sudo apt update &amp;&amp; sudo apt upgrade</code>&nbsp;before starting.

Install Laravel on Ubuntu: Set Up PHP 7.2 and Composer

Install PHP 7.2 and all required extensions. PHP 7.2 is the default version in Ubuntu 18.04 and is fully supported by Laravel 5.7:

bashsudo apt install php7.2-common php7.2-cli php7.2-gd php7.2-mysql php7.2-curl \  php7.2-intl php7.2-mbstring php7.2-bcmath php7.2-imap php7.2-xml php7.2-zip

Each extension covers a specific Laravel function: php7.2-bcmath handles arbitrary-precision math for financial calculations, php7.2-imap enables email functionality, php7.2-intl handles internationalization, and php7.2-zip manages archive operations.

Install Composer globally. Composer is the PHP dependency manager required to create and manage Laravel projects. A global install lets you run the composer command from any directory on the system:

bashcurl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

Verify the installation:

bashcomposer --version

You should see the Composer version number printed in the output.

Create a New Laravel Project and Start the Development Server

Use composer create-project to scaffold a new Laravel application:

bashcomposer create-project --prefer-dist laravel/laravel my_app

The --prefer-dist flag tells Composer to download the packaged source archive for each dependency rather than cloning from git, which is significantly faster. The command fetches all required PHP packages, runs the post-install scripts, and generates the application encryption key automatically.

Navigate to the project directory and start the built-in development server:

bashcd ~/my_appphp artisan serve

Open http://127.0.0.1:8000 in a browser. The Laravel welcome page confirms the installation is working.

<strong>Note:</strong>&nbsp;<code>php artisan serve</code>&nbsp;uses PHP's built-in server and is intended for local development only. For production, configure Nginx or Apache to serve the Laravel&nbsp;<code>public/</code>&nbsp;directory.

Laravel Configuration, Database Support, and Next Steps

When Composer scaffolds the project, it generates a .env file in the project root. This file holds environment-specific values including database credentials, application URL, cache driver, and mail settings. Never commit .env to version control — add it to .gitignore instead.

Database support. Laravel works with several backends out of the box:

  • MySQL / MariaDB: the most common production database choice
  • PostgreSQL: preferred for applications that need advanced query features or full-text search
  • SQLite: practical for local development and lightweight deployments
  • MongoDB: available via the official mongodb/laravel-mongodb package

Set your database connection in .env under the DB_* variables, then run:

bashphp artisan migrate

This creates all the database tables defined in your migration files.

Laravel Mix. If your project includes front-end assets such as JavaScript or SASS, Laravel Mix can compile them. Mix requires Node.js and Yarn installed separately. Run npm install followed by npm run dev from the project root to compile assets.

Laravel 5.7 is now installed on your Ubuntu 18.04 system. Configure your .env file, connect your database, run migrations, and start building. Leave a comment below if you run into any issues.

Cyber Defence

Recent Posts

Install Kodi on Ubuntu 18.04: Add the Official PPA and Set Up

Kodi (formerly XBMC, short for Xbox Media Center) is a free, open-source, cross-platform media player and…

17 minutes ago

Install Tomcat 8.5 on Ubuntu 18.04: Java Servlet Container Setup

Apache Tomcat is an open-source Java servlet container that implements Java Servlet, JavaServer Pages (JSP), Java…

24 minutes ago

Install Sublime Text 3 on Ubuntu 18.04: APT Repository Setup

Sublime Text is one of the most widely used source code editors in the world, known…

30 minutes ago

Install Spotify on Ubuntu 18.04: APT Repository Setup Guide

Spotify is one of the world's most popular digital music streaming platforms, giving you on-demand access…

35 minutes ago

Install Nextcloud on Ubuntu 18.04 with Apache and MySQL

Nextcloud is a free, open-source, self-hosted file sharing and collaboration platform. It gives you a private…

1 day ago

Install Plex Media Server on Ubuntu 18.04: Step-by-Step Setup

Plex is a self-hosted streaming media server that organizes your video, music, and photo collections into…

1 day ago