
Laravel is an open-source PHP framework used to build modern, feature-rich web applications. It offers clean and expressive syntax, along with a wide range of built-in components for tasks like authentication, testing, and database management. You can integrate Laravel with multiple applications, including databases and dynamic processors to serve modern web applications.
This article explains how to deploy Laravel with Apache on Ubuntu 24.04. You will set up Laravel, create a new project, and serve the application for access in a web browser.
Before you begin, you need to:
app.example.com.Laravel is built on PHP and requires several PHP extensions along with Composer to manage project dependencies. Follow the steps below to install PHP and all required dependencies for Laravel.
Update the server's package index.
Install PHP and required extensions.
Verify the installed PHP version.
Output:
Download the Composer installer script.
Get the latest SHA hash for the installer.
Verify the integrity of the installer script.
Output:
Install Composer globally.
The above command installs Composer under the /usr/local/bin directory and makes it available as a shell command with the name composer.
Output:
Verify the installed Composer version.
Your output should be similar to the one below.
Follow the steps below to install Laravel in your project environment.
Navigate to the user home directory.
Create a new myproject Laravel project.
Output:
Switch to the project directory.
Verify the installed Laravel version using Artisan.
Artisan is a command-line utility included with Laravel and exists at the root of the project as a script. Your output should be similar to the one below if Laravel is installed.
Laravel requires a database backend to store the application data. Follow the steps below to create a new MySQL database to use in your Laravel project:
Install the MySQL server package if it's not installed on your workstation.
View the MySQL service status and verify that it's running.
Output:
Log in to MySQL as the root database user.
Create a new laravel_db database to use with Laravel.
Create a new laravel_user MySQL user with a strong password.
Grant the laravel_user user full privileges to the laravel_db database.
Flush the MySQL permissions table to apply the changes.
Exit the MySQL shell.
Laravel uses a .env file to manage environment-specific configurations, including database credentials. Follow the steps below to update the file and migrate sample project data to the database.
Open the .env file in your Laravel project directory.
Update the database configuration to include the MySQL credentials you created earlier.
Save and close the file.
The above database configurations enable Laravel to connect and write data to the backend MySQL database server
Migrate the Laravel project tables to your database.
Output:
Apache is an open-source web server application that serves web applications using your instance's IP address or domain. Follow the steps below to configure Laravel with Apache to serve your Laravel application using a virtual host configuration.
Install Apache if it's not installed.
View the Apache service status and verify that it's running.
Output:
Navigate back to the user home directory.
Move the Laravel project directory to the Apache web root path.
Set proper permissions for the Laravel project directory.
Create a new laravel.conf virtual host configuration file.
Add the following configurations to the file. Replace app.example.com with your actual domain pointing to the instance's IP address.
Save and close the file.
Activate the rewrite module to enable Laravel to support clean URLs.
Disable the default virtual host configuration.
Enable the Laravel virtual host configuration.
Reload Apache to apply configuration changes.
Allow HTTP traffic on port 80 through the default firewall configuration.
Install UFW and allow essential connections if it's not installed.
Reload UFW to apply the firewall changes.
Visit your app.example.com domain using a web browser such as Chrome and verify that the default Laravel welcome page displays.
You have deployed Laravel with Apache on Ubuntu 24.04. You installed PHP and created a dedicated database to use with Laravel. You can modify the default application configurations with your models, views, and controllers (MVC) supported by Laravel. Visit the Laravel documentation for more information and usage options.
0 Comments
Be the first to comment and share your perspective with the community.