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.