DEV Community

Cover image for Laravel 101: Everything You Need to Know to Get Started with This Popular PHP Framework
Kazem
Kazem

Posted on • Updated on

Laravel 101: Everything You Need to Know to Get Started with This Popular PHP Framework

Hey there! Welcome to my Laravel tutorial series! In this series, I'll cover everything you need to know to create a powerful and modern web application using Laravel, the most popular PHP framework out there.
So, what is Laravel, you ask? Well, it's a free, open-source PHP web framework that's been gaining popularity in recent years. It was created by Taylor Otwell and has since been improved and developed further by a team of contributors. One of the coolest things about Laravel is its huge and active community, which is always working to make it better and more powerful.
Now, before we dive into the tutorial, there's one thing you need to know: to install Laravel, you'll need a software called Composer. It's like the npm or yarn for PHP, and it helps you manage the libraries and packages you need for your project. Composer was created by Nils Adermann and Jordi Boggiano, and it's a game-changer for PHP developers.

Image description

So, how do you install Composer? Well, if you're on Windows, you can download the installation file from the official Composer website and follow the installation prompts. If you're on Linux, you can use the command line to install it quickly and easily:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'e21205b207c3ff031906575712edab6f13eb0b361f2085f1f1237b7126d785e826a450292b6cfd1d64d92e6563bbde02') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
mv composer.phar /usr/local/bin/composer
Enter fullscreen mode Exit fullscreen mode

After installing you should see something similar to the image below when running the composer command:

Image description

Once you have Composer installed, you can use it to install Laravel and other PHP packages with just a few commands. It's super easy and efficient, and it'll save you a ton of time and hassle in the long run.

Let me briefly explain it similar to npm for JavaScript package there is somewhere called Packagist for PHP packages. Developers can upload their packages to Packagist, making them easily accessible to others.

Now that we've got Composer installed, let's dive into the tutorial and start building our Laravel application! 🚀


Install the first Laravel project

for installing the first Laravel project, you will have two ways. The first method is to use the Laravel Installer, which you can install using the following command:

composer global require laravel/installer
Enter fullscreen mode Exit fullscreen mode

Then, you can create a new project using the installer with the following command:

laravel new <your-project-name>
Enter fullscreen mode Exit fullscreen mode

The second method is to use Composer directly without installing the Laravel Installer. You can do this by running the following command:

composer create-project laravel/laravel <your-project-name>
Enter fullscreen mode Exit fullscreen mode

If you want to use a specific version of Laravel, you can specify the version number in the command. For example, if you want to use Laravel 7.4, you can run the following command:

composer create-project --prefer-dist laravel/laravel:7.4 <your-project-name>
Enter fullscreen mode Exit fullscreen mode

Note that when working on projects, it's possible that you may need to use packages from other sources and sometimes the versions of the packages that you want to use in your Laravel project may not support the latest version of PHP, then you have to Go down! Of course, it is possible to change the php version after installation, but in general, dependencies are effective in choosing the best configuration you need!

After installing the project, you can access it using the terminal by running the following command to start the Artisan server:

php artisan serve
Enter fullscreen mode Exit fullscreen mode

Image description

This will create a local development environment for your project. If you click the created link in your browser, you should see something similar to the image below:

Image description

Congratulations on successfully installing and setting up your first Laravel project! That's a great accomplishment! 👌👌
The first article in our Laravel tutorial series has now been completed, covering the installation and basic setup of a PHP project using the popular and powerful Laravel framework. I hope you found the tutorial helpful and informative.
Stay tuned for the next article in the series, where we'll build upon what we've learned so far and explore more exciting features of Laravel! 🤩

Top comments (0)