Menu
User

DropVPS Team

Writer: Cooper Reagan

how to install laravel 11 on ubuntu 24.04

how to install laravel 11 on ubuntu 24.04

Publication Date

05/11/2025

Category

Articles

Reading Time

3 Min

Table of Contents

You can check if PHP is installed by running:

php -v

If PHP is not installed, you can install it by executing:

sudo apt update
sudo apt install php php-cli php-mbstring php-xml php-mysql

Step 1: Install Composer

Composer is essential for managing Laravel’s dependencies. To install Composer, run the following commands:

cd ~
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

To verify the installation of Composer, check its version:

composer --version

Step 2: Install Laravel 11

Now that Composer is installed, you can create a new Laravel project. Navigate to your desired directory where you want to install Laravel:

cd /var/www

Then, use Composer to create a new Laravel project:

composer create-project --prefer-dist laravel/laravel laravel-app "11.*"

This command will create a new directory called laravel-app containing Laravel 11.

Step 3: Set Permissions

Next, you need to set the proper permissions for your Laravel application. Navigate into the project directory:

cd laravel-app

Set the permissions using the following command:

sudo chown -R www-data:www-data storage bootstrap/cache

Step 4: Configure Environment File

Laravel comes with a .env.example file for environment configuration. You should copy this file to create your .env file:

cp .env.example .env

Next, generate an application key:

php artisan key:generate

Open the .env file in a text editor to configure your database and other settings. For example:

nano .env

Update the database credentials:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_database_name
DB_USERNAME=your_username
DB_PASSWORD=your_password

Step 5: Set Up the Web Server

For Apache

If you are using Apache, make sure to enable the mod_rewrite module:

sudo a2enmod rewrite

Then, configure your Apache virtual host. Create a new configuration file:

sudo nano /etc/apache2/sites-available/laravel-app.conf

Add the following configuration:

<VirtualHost *:80>
    ServerName your-domain.com
    DocumentRoot /var/www/laravel-app/public

    <Directory /var/www/laravel-app/public>
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/laravel-app-error.log
    CustomLog ${APACHE_LOG_DIR}/laravel-app-access.log combined
</VirtualHost>

Enable the new site and restart Apache:

sudo a2ensite laravel-app
sudo systemctl restart apache2

For Nginx

For Nginx, create a new configuration file:

sudo nano /etc/nginx/sites-available/laravel-app

Add the following configuration:

server {
    listen 80;
    server_name your-domain.com;
    root /var/www/laravel-app/public;

    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }

    error_log /var/log/nginx/laravel-app-error.log;
    access_log /var/log/nginx/laravel-app-access.log;
}

Create a symbolic link to enable the site and restart Nginx:

sudo ln -s /etc/nginx/sites-available/laravel-app /etc/nginx/sites-enabled/
sudo systemctl restart nginx

Step 6: Run Migrations

If you have set up your database, you can run the migrations to create the necessary tables:

php artisan migrate

You have successfully installed Laravel 11 on your Ubuntu 24.04 server. Now you can start building your application with the power and elegance of Laravel. For more details, refer to the official Laravel documentation.

Linux VPS
U
Loading...

Related Posts

how to install laravel 11 on ubuntu 24.04