Laravel is a powerful and popular PHP framework designed to make web development easier and more efficient. This quick start guide will help you set up Laravel on your PHP server.
Prerequisites:
Before installing Laravel, ensure that the following requirements are met:
- PHP >= 8.1
- Composer (a PHP dependency manager)
- A web server such as Apache or Nginx
- MySQL or PostgreSQL (optional, for database-driven projects)
Step 1: Install Composer
Laravel is installed using Composer, so you'll need to have it on your system.
-
Download Composer:
Visit getcomposer.org to download and install Composer for your operating system. -
Verify Composer Installation:
Open your terminal or command prompt and run the following command:composer
If Composer is installed correctly, you should see a list of Composer commands.
Step 2: Create a New Laravel Project
Once Composer is set up, you can create a new Laravel project.
-
Navigate to the directory where you want to create the project:
cd /path/to/your/directory
-
Run the following command to create a new Laravel project:
composer create-project --prefer-dist laravel/laravel project-name
Replace
project-name
with your desired project name.
Step 3: Set Up Environment Variables
Laravel uses an .env
file to store environment variables such as database credentials, the app URL, and more.
-
In the root directory of your project, you'll find a
.env
file. Open it and configure your database settings:DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=your_database DB_USERNAME=your_username DB_PASSWORD=your_password
-
Update other environment variables as needed, such as
APP_URL
for the correct URL of your application.
Step 4: Set Permissions
On a Unix-based system, ensure that the storage and bootstrap/cache directories are writable:
sudo chmod -R 775 storage
sudo chmod -R 775 bootstrap/cache
Step 5: Start Laravel Development Server
You can quickly start Laravel’s built-in development server to test your application.
-
Navigate to your project directory:
cd project-name
-
Start the Laravel development server:
php artisan serve
-
Open your browser and go to
http://localhost:8000
. You should see the default Laravel welcome page.
Step 6: Set Up a Database (Optional)
If your project requires a database, run the following migrations to set up the database schema:
-
Ensure your
.env
file is correctly configured for your database. -
Run the migration command:
php artisan migrate
Step 7: Deploying to a Live Server
When deploying to a production environment, ensure your server meets Laravel's requirements.
-
Copy your project files to the server and set the necessary environment variables in your
.env
file. -
Set up a Virtual Host (for Apache or Nginx) pointing to the
public
directory of your Laravel project. -
Run Composer to install the project’s dependencies:
composer install --optimize-autoloader --no-dev
-
Run the following Artisan commands:
php artisan key:generate php artisan config:cache php artisan route:cache php artisan view:cache
-
Ensure correct permissions for the
storage
andbootstrap/cache
directories as mentioned earlier.
You have now successfully set up a Laravel application on a PHP server. You can begin developing your web application, utilising Laravel’s powerful tools and features.
For further details, visit the official Laravel documentation: Laravel Docs.
Ready to elevate your website?
Whether you're launching a new site, strengthening security, or adding a new feature, I can help transform your vision into a high-performing online presence.
More Website Development posts
—
Structured data for SEO
Adding structured data to a website is one of those steps that often gets overlooked, yet it can make a real difference to how a site performs in search engines.…
—
Ensuring a smooth deployment of a PHP website application
Deploying a PHP website application requires meticulous planning, a solid understanding of the environment, and a thorough execution process. To ensure a smooth deployment, it is essential to follow best…
Continue reading "Ensuring a smooth deployment of a PHP website application"
—
Knack API Integration
Knack is a powerful low-code platform that allows you to build online databases and custom web applications. When integrating Knack with your own systems or custom front ends, you can…
—
Popular PHP frameworks
Here’s detailed look at some of the most popular PHP frameworks, each of which can help speed up development, improve code organisation, and enhance application performance. Laravel Laravel is one…
More Laravel posts
—
Combining Laravel with WordPress
Combining Laravel with WordPress offers a unique and powerful approach to web development, blending the strengths of both platforms to create highly efficient, flexible, and scalable applications. Laravel, a modern…
—
Quick start guide for Laravel on a PHP server
Laravel is a powerful and popular PHP framework designed to make web development easier and more efficient. This quick start guide will help you set up Laravel on your PHP…
Continue reading "Quick start guide for Laravel on a PHP server"
—
What is Laravel?
Laravel is an open-source web application framework written in PHP, designed to make the development process faster, easier, and more streamlined. It follows the Model-View-Controller (MVC) architectural pattern and offers…
—
Laravel tutorial: Rest API call
To build a Laravel application that pulls posts from a REST API and displays them on a WordPress website, the process involves a few main steps: creating the Laravel application,…