How to Install Laravel?

7 minutes read

To install Laravel, you need to follow these steps:

  1. Install Composer: Laravel utilizes Composer, a dependency manager for PHP. Install Composer by downloading and running the Composer-Setup.exe/Composer-Setup.php file from the official website.
  2. Install Laravel Installer: Laravel provides a command-line tool called "Laravel Installer" to simplify the installation process. Open a command prompt and run the following command to install the Laravel Installer globally: composer global require laravel/installer
  3. Create a New Laravel Project: Navigate to the directory where you want to create your Laravel project using the command prompt. Run the command laravel new projectName to create a new Laravel project. Replace "projectName" with your desired project name.
  4. Serve the Laravel Application: Change to the project's directory using the command prompt. Run the command php artisan serve to start the Laravel development server at http://localhost:8000.
  5. Validate Installation: Open a web browser and visit http://localhost:8000 to ensure that Laravel is running properly. You will see the default Laravel welcome page if the installation was successful.


That's it! You have successfully installed Laravel and are ready to start developing your web applications using this powerful PHP framework.

Best Laravel Frameworks Books to Read in 2024

1
Laravel: Up and Running: A Framework for Building Modern PHP Apps

Rating is 5 out of 5

Laravel: Up and Running: A Framework for Building Modern PHP Apps

2
Beginning Laravel: Build Websites with Laravel 5.8

Rating is 4.9 out of 5

Beginning Laravel: Build Websites with Laravel 5.8

3
Laravel: Up & Running: A Framework for Building Modern PHP Apps

Rating is 4.8 out of 5

Laravel: Up & Running: A Framework for Building Modern PHP Apps

4
Laravel: Up & Running

Rating is 4.7 out of 5

Laravel: Up & Running

5
Practical Laravel: Develop clean MVC web applications

Rating is 4.6 out of 5

Practical Laravel: Develop clean MVC web applications

6
Laravel - Un framework efficace pour développer vos applications PHP

Rating is 4.5 out of 5

Laravel - Un framework efficace pour développer vos applications PHP


How to install Laravel on Docker?

To install Laravel on Docker, follow these steps:

  1. Install Docker on your system and ensure it is running properly.
  2. Create a new directory for your Laravel project.
  3. Open a terminal window and navigate to the project directory.
  4. Run the following command to create a new Laravel project using the Laravel installer:
1
docker run --rm -v $(pwd):/app composer create-project --prefer-dist laravel/laravel .


This will create a new Laravel project inside your current directory.

  1. After the project is created, create a new Dockerfile in your project directory and add the following content:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
FROM php:7.4-apache

# Update package list and install required extensions
RUN apt-get update && apt-get install -y \
        libpng-dev \
        libonig-dev \
        libxml2-dev \
        libzip-dev \
        zip \
        unzip

# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd zip

# Enable Apache mod_rewrite
RUN a2enmod rewrite

# Set working directory
WORKDIR /var/www/html

# Copy composer files and install dependencies
COPY composer.lock composer.json ./
RUN composer install --no-autoloader --no-scripts

# Copy Laravel project files
COPY . .

# Generate the autoloader and update permissions
RUN composer dump-autoload
RUN chown -R www-data:www-data /var/www/html/storage

# Update Apache configuration
COPY docker/apache.conf /etc/apache2/sites-available/000-default.conf

# Run the Apache server
CMD ["apache2-foreground"]


  1. Create a new directory named "docker" in your project directory, and create a new file named "apache.conf" inside the "docker" directory. Add the following content to the "apache.conf" file:
1
2
3
4
5
6
7
<VirtualHost *:80>
    DocumentRoot /var/www/html/public

    <Directory /var/www/html>
        AllowOverride All
    </Directory>
</VirtualHost>


  1. In the terminal, navigate to your project directory and run the following command to build the Docker image:
1
docker build -t my-laravel-app .


  1. After the build process is complete, run the following command to start a new Docker container with the Laravel app:
1
docker run -p 8000:80 my-laravel-app


This will start the Docker container with your Laravel app running on port 8000.


You can now access your Laravel app by opening http://localhost:8000 in your browser.


Note: Make sure your Docker daemon is running before executing the Docker commands.


What is the command to install a specific version of Laravel via Composer?

To install a specific version of Laravel via Composer, you can use the following command:

1
composer create-project --prefer-dist laravel/laravel your-project-name "version"


Replace your-project-name with your desired project name and "version" with the specific Laravel version you want to install (e.g., "6.0.*" for Laravel 6.0.X).


What is the recommended PHP version for Laravel installation?

The recommended PHP version for Laravel installation is PHP 7.3 or higher. It is always recommended to use the latest stable version of PHP for better performance and security.

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

Related Posts:

API authentication is an essential aspect of securing your Laravel application. Laravel provides various built-in mechanisms to implement API authentication effortlessly. One widely used method is to leverage Laravel Passport, a full OAuth2 server implementati...
To create a new Laravel project, you can follow these steps:Open your command-line interface (CLI) or terminal.Navigate to the directory where you want to create the Laravel project.Run the following command: composer create-project --prefer-dist laravel/larav...
To properly install packages in Laravel, you need to follow these steps:Open the terminal or command prompt and navigate to your Laravel project directory.Open the &#34;composer.json&#34; file located in the root directory of your Laravel project.In the &#34;r...