VPSWala Blog

How to Install and Deploy Laravel on Ubuntu with Apache (2025 Guide)

January 24, 2025, Written by 0 comment

Want to run your Laravel website on Ubuntu? This guide will walk you through every step of installing Laravel on Ubuntu with Apache. Perfect for beginners – no advanced Linux knowledge needed!

What You’ll Learn

  • How to prepare your Ubuntu server
  • Installing PHP and Apache
  • Setting up Laravel
  • Configuring your website
  • Testing everything works

⏱️ Time Needed: About 30 minutes

Skill Level: Beginner-friendly

What You Need Before Starting

  • A computer or VPS server running Ubuntu (any recent version works fine)
  • Internet connection
  • Basic knowledge of copy-pasting commands
  • Access to Terminal (don’t worry, we’ll show you how to open it!)

Step 1: Getting Your Computer Ready

First, let’s make sure your Ubuntu computer has all the latest updates. Think of this like getting fresh ingredients before cooking!

Open Terminal by pressing Ctrl + Alt + T on your keyboard. Then copy and paste these commands:

sudo apt update
sudo apt upgrade

When it asks for your password, type it in. Don’t worry if you don’t see any stars or dots – that’s normal!

Step 2: Installing PHP and Friends

Laravel needs PHP to work. Let’s install PHP and some helpful tools it needs:

sudo apt install php8.2 php8.2-common php8.2-mysql php8.2-xml php8.2-xmlrpc php8.2-curl php8.2-gd php8.2-imagick php8.2-cli php8.2-dev php8.2-imap php8.2-mbstring php8.2-opcache php8.2-soap php8.2-zip php8.2-intl -y

If this command seems long, don’t worry! It’s just installing all the pieces PHP needs to work properly with Laravel. Just copy and paste the whole thing.

Step 3: Installing Apache

Apache is like a waiter for your website – it serves your pages to visitors. Let’s install it:

sudo apt install apache2

After installing, let’s make sure Apache is running:

sudo systemctl start apache2
sudo systemctl enable apache2

Step 4: Installing Composer

Composer helps Laravel install its parts. Think of it like a helper who gets all your books from the library:

curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
sudo chmod +x /usr/local/bin/composer

Step 5: Creating Your Laravel Website

Now for the fun part – let’s create your Laravel website! First, go to Apache’s web folder:

cd /var/www/html

Then tell Composer to create a new Laravel project. Replace “my-website” with whatever name you want:

sudo composer create-project laravel/laravel my-website

This might take a few minutes. Time to grab a snack!

Step 6: Setting Permissions

We need to give Apache permission to use your Laravel files:

sudo chown -R www-data:www-data /var/www/html/my-website
sudo chmod -R 775 /var/www/html/my-website/storage

Step 7: Setting Up Apache for Your Website

Now we’ll tell Apache how to show your website. Create a new configuration file:

sudo nano /etc/apache2/sites-available/my-website.conf

Copy and paste this into the file (press Ctrl + Shift + V to paste):

<VirtualHost *:80>
 ServerName my-website.local
 DocumentRoot /var/www/html/my-website/public
 <Directory /var/www/html/my-website>
 AllowOverride All
 </Directory>
</VirtualHost>

Save the file by pressing: Ctrl + X, then Y, then Enter

Step 8: Activating Your Website

Let’s turn on your new website configuration:

sudo a2ensite my-website
sudo a2enmod rewrite
sudo systemctl restart apache2

Testing Your Website

Open your web browser and type:

http://localhost

You should see the Laravel welcome page!

Also Read: How to Install Docker on Ubuntu 22.04

Common Problems and Solutions

Error 1: No Page Found

If you encounter a “Page Not Found” condition:

Issue 1: Error – Unable to Locate Page

If you are receiving a message on your screen that says that the page cannot be located, then the following ways might solve it:

  • Make sure that Apache is running: sudo systemctl start apache2
  • See who is the owner of the file: ls -l /var/www/html/my-website
  • Search for errors: sudo tail /var/log/apache2/error.log

Issue 2: White Screen

If you see a white screen:

  • Check the logs of Laravel: sudo tail /var/www/html/my-website/storage/logs/laravel.log
  • Make storage writable: sudo chmod -R 775 /var/www/html/my-website/storage

Next Steps

Now that your Laravel website is running, you might be interested in:

  • Starting a database
  • Securing with SSL
  • Designing your first Laravel page
  • Understand the routes in Laravel

Congratulations! Laravel is set up on Ubuntu with Apache. We hope that you find this information useful for sharing with others in need.

FAQs

Do I have to pay to use Laravel?

No! it is completely free of charge.

Will it fit older versions of Ubuntu?

Yes, it will. However, it might require using a different version of PHP. It is recommended to adopt Ubuntu 22.04 or higher to work best.

How to Update Laravel later?

Use the command: composer update in your website folder.

This is pretty much fine for a real website, doesn’t it?

Yes! Many real websites use the exact same settings. Just configure HTTPS before going online.

vpswala Admin

Savita Sathe is an experienced writer and editor with over 10+ years of professional experience creating engaging content across industries. Whether it's blogs, whitepapers, website copy, emails, social media posts, or more. She develops effective hosting and tech content that helps brands connect with their audiences and achieve business goals.

Leave a reply

Your email address will not be published. Required fields are marked *