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 server.

Prerequisites:

Before installing Laravel, ensure that the following requirements are met:

Step 1: Install Composer

Laravel is installed using Composer, so you'll need to have it on your system.

  1. Download Composer:
    Visit getcomposer.org to download and install Composer for your operating system.

  2. 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.

  1. Navigate to the directory where you want to create the project:

    cd /path/to/your/directory
    
  2. 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.

  1. 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
    
  2. 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.

  1. Navigate to your project directory:

    cd project-name
    
  2. Start the Laravel development server:

    php artisan serve
    
  3. 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:

  1. Ensure your .env file is correctly configured for your database.

  2. 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.

  1. Copy your project files to the server and set the necessary environment variables in your .env file.

  2. Set up a Virtual Host (for Apache or Nginx) pointing to the public directory of your Laravel project.

  3. Run Composer to install the project’s dependencies:

    composer install --optimize-autoloader --no-dev
    
  4. Run the following Artisan commands:

    php artisan key:generate
    php artisan config:cache
    php artisan route:cache
    php artisan view:cache
    
  5. Ensure correct permissions for the storage and bootstrap/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.

Discuss your web development project