
Laravel is a dynamic, object-oriented programming framework based on PHP for creating applications from basic to complex web solutions. Laravel offers a modern syntax for productivity, runs with an interpreter instead of a compiler, and integrates with multiple frameworks for use in various projects.
This article explains how to install Laravel on Ubuntu 24.04 and configure the server to run Laravel applications.
Before you begin, you need to:
laravelapp.example.com.Laravel supports multiple database engines you can configure and integrate to store application data. Follow the steps below to create a new dedicated MySQL database to use with Laravel on your server.
Verify that the MySQL database server is active and running.
Output:
Log in to the MySQL database server.
Create a new laravelapp database for your Laravel project.
Create a new laravelapp user with a strong password to use with the Laravel application. Replace password with a strong password of your choice.
Grant the new laravelapp user full privileges to the Laravel database.
Flush the MySQL privileges table to apply the database changes.
Exit the MySQL database console.
Laravel requires composer dependency manager and specific PHP extensons to run and deliver dynamic web applications on a server. Follow the steps below to install Composer and all required PHP extensions on your server.
Update the server's package index.
Install Composer and all required extensions.
View the installed PHP version.
Output:
View the installed Composer version.
Output:
View the Apache service status and verify that it's active.
Output:
Create a new info.php file in the default /var/www/html web root directory to display all PHP configuration details.
Add the following phpinfo function to the file.
Save and close the file.
Allow HTTP connections through the default firewall configuration.
Reload UFW to apply the firewall changes.
Restart the Apache web server to apply your PHP application changes.
Access your server's IP address using the /info.php path in a web browser such as Chrome.
View all installed extensions on your server and verify that thefileinfo, mbstring, and openssl are available on the PHP information page.
Follow the steps below to set up all required project directories and create a new Laravel project using Composer with all necessary dependency packages.
Create all required project directories in the /var/www/ directory.
The above command create the /var/www/.cache directory to store the Composer cache files, while /var/www/.config stores configuration files for Composer, and /var/www/laravelapp works as the main Laravel project directory.
Grant the Apache www-data user and group ownership privileges to all files in the Laravel project directory.
Navigate to the laravelapp project directory.
Create a new project using Composer and the default Laravel application template.
Output:
Open the .env file using a text editor such as nano to set up the Laravel database connection information.
Find the following DB_CONNECTION directive.
Change the default value from sqlite to mysql.
Uncomment the DB_ directives and replace the default values with your actual Laravel database information.
Save and close the file.
Run the database migration script to create the default database structure for your Laravel project.
Output:
Apache serves web application files using virtual host configurations in the /etc/apache2 directory. Follow the steps below to create a new Apache virtual host configuration to serve the Laravel project files using your laravelapp.example.com domain.
Enable the Apache rewrite module mod_rewrite to enable Laravel to process clean URLs.
Create a new laravelapp.conf virtual host configuration file.
Add the following contents to the file. Replace laravelapp.example.com with your actual domain.
Save and close the file.
The above apache virtual host configuration listens for connection requests on the HTTP port 80 and serves the Laravel web application files from the /var/www/laravelapp directory.
Enable the Laravel virtual host configuration.
Disable the default Apache virtual host configuration to avoid port conflicts.
Test the Apache configuration for errors.
Output:
If you see Syntax OK, the configuration is valid.
Restart the Apache service to apply the configuration changes.
Follow the steps below to access your Laravel application using your laravelapp.example.com virtual host domain on your server.
Access the Laravel application using your domain in a web browser such as Chrome. Replace laravelapp.example.com with your actual domain.
Output:
You have installed Laravel on Ubuntu 24.04 and set up a default project to run on your server. You can create new models, views and controller files in your Laravel project directory to run frameworks such as Blade and customize your dynamic Laravel web application functionalities.
0 Comments
Be the first to comment and share your perspective with the community.