Laravel is the best and most popular PHP framework nowadays. The features it provides and the support it gets really helps the developers. You can easily build a full stack web application or an API with Laravel. You can even integrate SPA (Single Page Application) with it.
There are several ways to set up a Laravel project, but I’ll show you the 2 simplest ways to do it and they’re really similar. You can do it with Composer or the Laravel Installer.
Before you can make a Laravel project, there are some stuffs you need to have installed first. Don’t worry, they just need a few clicks to install.
If you want to use Laravel, most likely you already have PHP set up. If you haven’t, I recommend you use XAMPP, it’s kind of an environment that enables you to use PHP and MySQL when activated. Just click that link and you’ll be redirected to the download page. (As of the time of writing this blog, the latest version of Laravel is Laravel 9 which requires PHP 8. If you use PHP 7, you can use only up to Laravel 8)
In case of Composer, it is a dependency manager for PHP. You can install packages and Laravel with it. Like NPM (Node Package Manager), but for PHP. To install it, just go to the Composer download page and download the Windows Installer.
Setting Up Laravel
To set up a Laravel project is very simple.
You can just run this command in your terminal. Don’t for get to cd into your desired directory where you want to place the folder in. In my case, I name my project newProject, change it as you see fit.
composer create-project laravel/laravel newProject
And your project is set up. You just need 1 line to make the folder with all the skeleton in it. That is how you do it with Composer. If you prefer to do it with Laravel Installer, you have to first install the Laravel Installer.
composer global require laravel/installer
You just have to install it once and then the next time you want to make a Laravel project, you don’t need to repeat that command again. Now, to set up the project, you just need to run this command in your terminal.
laravel new newProject
And that is another way or command to set up Laravel. Don’t worry about which one to use, it is completely up to your preference as they give the same result.
Running the Laravel Project
Now that your Laravel project is set up, you need to run it.
First, get into your project directory, in this case, I name it newProject.
Now, just run this code to tell Laravel to run your web locally.
php artisan serve
Your web is already run locally. In your terminal you should be able to see this message.
Starting Laravel development server: http://127.0.0.1:8000
That’s where your web is run locally. Just go to that URL and you can see your page which looks something like this if you haven’t modified any of the code yet.
That’s the default Laravel page. You can visit any of the links if you are interested and it also shows you your current Laravel and PHP version.
Now you’ve installed Laravel successfully and easily! It’s simple, right? Well, there are other ways to install it now as new updates come up, but this is still the simplest way.
You can try walking through the project structure, try to understand it and modify things. There are a lot to explore in Laravel. If you want to learn more about the project structure, you can read it here.
If you’re just starting to learn Laravel and happen to be using a low end laptop at the moment, hopefully this article will be helpful to you, go ahead and read about Can Low End Laptops Be Used For Web Development?
Now that you understand more about Laravel, if you’re looking for where to host your Laravel App, I recommend Cloudways. It is compatible, fast, reliable and has a specific option for Laravel. There are also tons of resources about Laravel hosting on Cloudways. Go ahead and check it out!
If you’re looking to refresh your PHP skill, you can try Codecademy’s free PHP course. Go ahead and check out the syllabus to see if it fits you. If you’re interested, go and try it for free!
Now, go explore Laravel!