How to Create Laravel Project

Walnut Software
5 min readDec 1, 2023

--

In this article, I will explain the things you need when creating a Laravel project. Thanks to this article, you will be able to create a Laravel project and establish the project-database connection. Let’s get started!

Creating a Laravel Project(Step by Step)

For Windows

●Step 1:Download PHP

Start by downloading the latest version of PHP from the official website. You can find the official download page here.

  • Choose the version on the download page, usually opting for the “Thread Safe” (TS) version.
  • Download the appropriate ZIP file for Windows.

a-) Extract Files: Unzip the downloaded ZIP file into a folder. The recommended directory is often something like C:\php, but you can use any folder you prefer.

b-) Configure php.ini: In the extracted folder, copy the php.ini-development file and rename it to php.ini.

c-) PATH Configuration: Add the directory containing PHP’s executable files to the system PATH variable. This ensures that you can run the PHP command from the command prompt.

  • Right-click on your computer and select “Properties.”
  • Click on “Advanced system settings.”
  • Click on the “Environment Variables” button.
  • In the opened window, under the “System variables” section, find “Path” (or “PATH”) and click on the “Edit” button.
  • In the new window, click on “New” and add the path to the PHP directory (e.g., C:\php).

d-) Web Server Configuration (Optional): If you’re using a web server (like Apache, Nginx, etc.), you need to integrate PHP’s configuration file with the server. The steps vary depending on the type of server. For example, for Apache, you’ll need to edit the httpd.conf file.

e-) Testing: After successfully completing the installation, open a command prompt and run the php -v command to check the PHP version.

●Step 2: Install Composer

Install Composer: If you haven’t already, download and install Composer, which is a dependency manager for PHP. You can find instructions on how to install Composer on the official website: Composer Installation.

●Step 3: Install Laravel Installer

Open your command line or terminal and run the following command to install the Laravel installer globally on your system:

composer global require laravel/installer

●Step 4: Create a New Laravel Project

After installing the Laravel installer, navigate to the htdocs directory within the directory where XAMPP is installed in your terminal, and run the following command. This will allow you to create a new Laravel project. Creating your Laravel projects within the htdocs directory ensures more stable functionality.

laravel new project-name

Replace project-name with the name of your project. Laravel will set up a new project folder and install all the necessary dependencies.

📌Database Connection

●Step 5: Download and Install XAMPP

Download: Visit the official XAMPP website at XAMPP Downloads, select the version for your operating system (Windows, macOS, Linux), and download it.

Installation: Run the downloaded XAMPP installer, and follow the on-screen instructions to complete the installation. Once done, XAMPP is installed on your computer.

●Step 6: XAMPP Control Panel

Open the XAMPP control panel and start Apache and MySQL.

●Step 7: Create a New DataBase

Go to http://localhost/phpmyadmin click on “new,” enter a database name, and click “create.”

●Step 8: Laravel — Database Connection

Open your Laravel project in a development environment like VSCode, and in the root directory of your Laravel project, locate the “.env” file. Update the DB_DATABASE value in the “.env” file with the name of the database you created in the previous step, and save the changes.

●Step 9: Run Migration

If you want to use a database, run the migration command to create the necessary tables:

php artisan migrate

●Step 10: Serve Your Application

To run your Laravel application, you can use the built-in development server. Run the following command:

php artisan serve

For Mac

●Step 1:Install Homebrew

If Homebrew is not already installed on your Mac, you can install it by running the following command in your terminal:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

●Step 2: Install PHP

Use Homebrew to install the latest version of PHP by running the following command in your terminal:

brew install php

●Step 3: Install Composer

Composer is used to manage Laravel projects and their dependencies. You can download and install Composer by running the following commands in your terminal:

brew install composer

●Step 4: Install Laravel

Use Composer to create a new Laravel project by running the following command in your terminal:

composer create-project --prefer-dist laravel/laravel project-name

Replace “project-name” with a suitable name for your project.

📌Database Connection

●Step 5:Install MySQL

You can install MySQL on Mac using Homebrew. Run the following command in your terminal to install MySQL:

brew install mysql

●Step 6: Start MySQL Server

Start the MySQL server by using the following command:

brew services start mysql

This command starts the MySQL server and ensures it starts automatically on system boot.

●Step 7:MySQL Root User and Password

After starting MySQL, you need to set up a root user and password. Enter the MySQL shell with the following command in your terminal:

mysql -u root -p

You’ll be prompted to enter the password for the root user.

●Step 8: Create a Database

Create a new database for your Laravel project using the following SQL command in the MySQL terminal:

CREATE DATABASE laravel_database;

This command creates a database named “laravel_database.” You can adjust the name and other settings based on your project’s requirements.

●Step 9: Laravel — Database Connection

Open your Laravel project in a development environment like VSCode, and in the root directory of your Laravel project, locate the “.env” file. Update the DB_DATABASE value in the “.env” file with the name of the database you created in the previous step, and save the changes.

●Step 10: Run Migration

If you want to use a database, run the migration command to create the necessary tables:

php artisan migrate

●Step 11: Serve Your Application

To run your Laravel application, you can use the built-in development server. Run the following command:

php artisan serve

By following these steps, you can create a Laravel project. Happy coding!

--

--

Walnut Software
Walnut Software

No responses yet