Laravel is a robust, feature-rich PHP framework used for creating high-quality web applications. It simplifies tasks like routing, authentication, caching, and sessions, making it a popular choice for developers worldwide. If you are using Ubuntu 22.04 and planning to set up Laravel, this comprehensive guide is all you need.
Before we start, make sure that you have administrative access to an Ubuntu 22.04 system.
Before installing any new packages, it’s recommended to update your Ubuntu system. Open a terminal window and type:
sudo apt update
sudo apt upgrade
Laravel requires PHP to run. You can install PHP along with necessary extensions by typing:
sudo apt install php php-xml php-gd php-zip php-mbstring php-curl php-tokenizer php-json
Your can install specific PHP version using the article: How To Install PHP (8.3, 8.2, 7.4) on Ubuntu 22.04
Composer is a dependency management tool for PHP. It will help you download and install Laravel in your system. You can install Composer with the following commands:
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
Navigate to the directory where you want your new Laravel project to reside, then run:
composer create-project laravel/laravel my_project
Replace “my_project” with the name you wish to give your Laravel project.
This command will create a new directory with the specified name, download a fresh Laravel installation into that directory, and install all of Laravel’s dependencies.
Move into the Laravel project directory and use the Artisan command-line utility included with Laravel to start the Laravel server:
cd my_project
php artisan serve
You’ll see Laravel development server started on http://localhost:8000. Open your browser and visit this URL to see your new Laravel application in action.
The last step in setting up Laravel is configuring the environment file (.env). This file contains settings like database credentials, mail server credentials, and other sensitive settings. You can edit this file to match your specific settings.
Apache is a popular web server and a good choice for hosting Laravel applications. After installing Laravel and Apache on your Ubuntu 22.04 system, you’ll need to configure Apache to serve your Laravel application. Follow these steps:
sudo apt update
sudo apt install apache2
sudo a2enmod rewrite
sudo nano /etc/apache2/sites-available/my_project.conf
Replace “my_project” with your Laravel project’s name.
Add the following configuration to the file:
ServerName my_project.com
ServerAlias www.my_project.com
DocumentRoot /var/www/my_project/public
AllowOverride All
Order allow,deny
Allow from all
ErrorLog ${APACHE_LOG_DIR}/my_project_error.log
CustomLog ${APACHE_LOG_DIR}/my_project_access.log combined
Replace my_project.com with your domain or subdomain and /var/www/my_project with the path to your Laravel project. The DocumentRoot should point to the public directory of your Laravel application.
Press CTRL+X followed by Y and ENTER to save and close the file.
sudo a2ensite my_project.conf
sudo systemctl restart apache2
Your Laravel application should now be accessible from your web browser via the domain or subdomain you specified in your virtual host configuration. Remember to replace “my_project.com” with your actual domain or IP address. If you’re developing locally, this may be localhost or a local IP.
Note: If you’re deploying your application to production server, you need to have a domain pointing to your server’s IP address. Also, always ensure that your server’s firewall rules allow traffic on HTTP and HTTPS.
This step-by-step guide aimed to help you understand how to install Laravel on Ubuntu 22.04. The installation process can seem daunting, but with these steps, you should have been able to navigate it easily. Enjoy coding with Laravel!
Note: This tutorial assumes you have a basic knowledge of the Linux command line interface. If you’re new to it, you might want to familiarize yourself with basic Linux commands and how to use the terminal.
Remember, the best way to learn is by doing. Now that you have Laravel set up on your Ubuntu system, it’s time to start building!
The post How to Setup Laravel on Ubuntu 22.04 appeared first on TecAdmin.
Welcome to the Ubuntu Weekly Newsletter, Issue 883 for the week of March 9 –…
In this article, we will see how to install nvidia-smi on Ubuntu or Debian Linux.…
In this article, we will see how to install clang tool on Ubuntu or Debian…
When working with Docker containers on Raspberry Pi devices, you might encounter frustrating signature verification…
You’ve recently upgraded to Ubuntu 18.04 and found that your OpenVPN connection no longer resolves…
Have you ever tried to open System Monitor on your Ubuntu 18.04 system only to…