Laravel 10x installation

Author
By Darío Rivera
Posted On in Laravel

Laravel is one of the most popular PHP frameworks worldwide today and has maintained its position for several years. Not only because of its elegant code style, but also because it implements a large number of design patterns and advanced programming tools that, as you know, make developers' lives easier.

Requirements

To install Laravel 10.x, you must consider the following requirements.

- PHP >= 8.1
- Composer

Additionally, you must have the following enabled PHP libraries.

- BCMath
- Ctype
- Fileinfo
- JSON
- Mbstring
- OpenSSL
- PDO
- Tokenizer
- XML

If you want to make sure you have the necessary libraries installed, we recommend you to check the following posts depending on the operating system you are using.

- Install PHP extensions for Laravel 8 on Ubuntu
- Install PHP extensions for Laravel 8 on Debian
- Install PHP extensions for Laravel 8 on Arch Linux

In addition to this, you must have the following Apache modules enabled

- mod_rewrite

Optionally, you may require the following software packages.

- Apache 2
- MySQL >=5.7

You can also see related articles on how to install Apache, PHP, and MySQL according to the operating system you use.

- Install Apache, PHP and MySQL on Ubuntu 20.04 (Focal Fossa)
- Install Apache, PHP, and MySQL in Debian 10 (Buster)
- Install Apache, PHP and MySQL on Arch Linux

Laravel Project Installation from Scratch

There are basically two ways to create a project in Laravel. The first one involves using composer with the argument create-project. The second way is to use an official Laravel package called Laravel Installer

Creating a new project with composer

To create a Laravel project using only composer, you must use the following command.

composer create-project laravel/laravel my_new_project

If you have a PHP version older than what Laravel 10.x requires, the above command will install an older version of Laravel suitable for the PHP version on your system.

With this method, the .env file and the encryption key will also be created.

Creating a "laravel/laravel" project at "./my_new_project"
Info from https://repo.packagist.org: #StandWithUkraine
Installing laravel/laravel (v10.1.1)
  - Downloading laravel/laravel (v10.1.1)
  - Installing laravel/laravel (v10.1.1): Extracting archive
Created project in /var/www/vhosts/pleets/my_new_project
> @php -r "file_exists('.env') || copy('.env.example', '.env');"
Loading composer repositories with package information
Updating dependencies
Lock file operations: 106 installs, 0 updates, 0 removals
  - Locking brick/math (0.11.0)
  - Locking dflydev/dot-access-data (v3.0.2)
...
80 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
> @php artisan vendor:publish --tag=laravel-assets --ansi --force

   INFO  No publishable resources for tag [laravel-assets].  

No security vulnerability advisories found
> @php artisan key:generate --ansi

   INFO  Application key set successfully. 

Creating a new project with Laravel installer

After having composer installed, you must ensure that the composer binaries are properly configured to be able to execute these commands globally. Depending on the operating system you have installed, the following path should be added to the PATH variable.

Windows %USERPROFILE%\AppData\Roaming\Composer\vendor\bin
GNU/Linux $HOME/.config/composer/vendor/bin
MacOS $HOME/.composer/vendor/bin

If you're not sure what the composer binaries directory is, you can find out with the following command:

composer global config bin-dir --absolute

Once the requirements on the machine where we will install Laravel have been verified, you must globally install Laravel Installer. To do this, simply execute the following command in the console:

composer global require laravel/installer

Once this is done, you will have the laravel command available in your terminal. To create a new project in Laravel, you can run the following command:

laravel new my_new_project

If you have a PHP version older than what Laravel 10.x requires, the above command will install an older version of Laravel suitable for the PHP version on your system..

If everything has gone well so far, you should see a message in the terminal similar to the following:

   _                               _
  | |                             | |
  | |     __ _ _ __ __ ___   _____| |
  | |    / _` | '__/ _` \ \ / / _ \ |
  | |___| (_| | | | (_| |\ V /  __/ |
  |______\__,_|_|  \__,_| \_/ \___|_|

Creating a "laravel/laravel" project at "./my_new_project"
Installing laravel/laravel (v10.1.1)
  - Installing laravel/laravel (v10.1.1): Extracting archive
Created project in /var/www/vhosts/pleets/my_new_project
> @php -r "file_exists('.env') || copy('.env.example', '.env');"
Loading composer repositories with package information
Updating dependencies
Lock file operations: 106 installs, 0 updates, 0 removals
  - Locking brick/math (0.11.0)
  - Locking dflydev/dot-access-data (v3.0.2)
...
80 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
> @php artisan vendor:publish --tag=laravel-assets --ansi --force

   INFO  No publishable resources for tag [laravel-assets].  

No security vulnerability advisories found
> @php artisan key:generate --ansi

   INFO  Application key set successfully. 

Configuration

Since Laravel uses certain folders to generate cache, views, and other utilities, it is necessary to assign the necessary permissions.

chmod -R a+w storage
chmod a+w bootstrap/cache

Installation of an existing project

Keep in mind that some steps of the Laravel project installation are automated when creating a new project. If you already have a Laravel project uploaded to GitHub, Bitbucket, GitLab, or others, and you download it to install, you should follow these steps.

The first step is to install the dependencies.

composer install

The next step is to make a copy of the environment configuration file. As an example, Laravel includes the .env.example file that contains the necessary configurations for the application to work correctly.

cp .env.example .env

Finally, we need to generate a unique key for the application, which will also be used to encrypt certain data managed by the framework.

php artisan key:generate

When running this command, Laravel will automatically configure a value similar to the following in the configuration file .env.

APP_KEY=base64:8veiqlPhUQlfvofFGfARw7M4tHvqumRT223tXoq5JDz0=

If the project has migrations and data, you can run the following command to create the entire database structure and necessary data.

php artisan migrate --seed

Finally, we need to configure the necessary permissions.

chmod -R a+w storage
chmod a+w bootstrap/cache

Running the application

To see our application in action, simply use the following command in the root of the project.

php artisan serve

After this, we will generally access the application at the address http://127.0.0.1:8000 or on the port that Artisan finds available.

If you want Laravel to work on your WAMP, LAMP web server, or custom Apache and PHP installation, you need additional configuration. You can refer to the following post if you want to configure a virtual host for Laravel on Apache.

- Configuring virtual host for Laravel with Apache

At this point, we will know that we have successfully completed the installation if we see the main screen of our application at the address of our localhost. See you soon!.


Acerca de Darío Rivera

Author

Application Architect at Elentra Corp . Quality developer and passionate learner with 10+ years of experience in web technologies. Creator of EasyHttp , an standard way to consume HTTP Clients.

LinkedIn Twitter Instagram

Sólo aquellos que han alcanzado el éxito saben que siempre estuvo a un paso del momento en que pensaron renunciar.