How To Install Laravel on Fedora 41
Laravel is a powerful PHP framework designed for building web applications with an elegant syntax. It simplifies common tasks such as routing, authentication, sessions, and caching, making it a popular choice among developers. Fedora, known for its cutting-edge features and stability, provides an excellent environment for developing Laravel applications. This guide will walk you through the step-by-step process of installing Laravel on Fedora 41, ensuring you have everything you need to get started with your development journey.
Prerequisites
Before diving into the installation process, it’s essential to ensure that your system meets the necessary prerequisites. This section outlines the system requirements and software dependencies needed for a successful installation.
System Requirements
- Minimum Hardware Specifications: A modern processor (Intel or AMD), at least 2 GB of RAM, and 20 GB of available disk space.
- Recommended Software Versions: PHP 8.0 or higher, Composer 2.x, and Node.js 14.x or higher.
Software Dependencies
- PHP: Laravel requires PHP to function. The recommended version is PHP 8.0 or later.
- Composer: This dependency manager for PHP is essential for managing Laravel’s libraries.
- Node.js and NPM: These are required for compiling assets like CSS and JavaScript.
User Permissions
It is crucial to perform installations as a non-root user with sudo privileges to maintain system security. This practice helps prevent accidental changes to critical system files.
Step 1: Update Your System
The first step in preparing your Fedora system for Laravel installation is to ensure all packages are up-to-date. This not only enhances security but also ensures compatibility with the latest software versions.
sudo dnf update
This command will refresh your package database and install any available updates. After running it, reboot your system if prompted.
Step 2: Install PHP and Required Extensions
Laravel relies on several PHP extensions to function correctly. To install PHP along with the necessary extensions, run the following command:
sudo dnf install php php-cli php-common php-json php-mbstring php-mysqlnd php-xml php-zip
This command installs:
- php: The core PHP package.
- php-cli: Command-line interface for PHP.
- php-common: Common files for PHP packages.
- php-json: JSON support in PHP.
- php-mbstring: Multibyte string support.
- php-mysqlnd: MySQL Native Driver for improved performance.
- php-xml: XML support in PHP.
- php-zip: ZIP file handling support.
You can verify your PHP installation by running:
php -v
Step 3: Install Composer
Composer is a vital tool for managing dependencies in PHP projects. To install Composer globally on your Fedora system, execute the following commands:
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
This downloads the Composer installer script and moves the Composer binary to a directory included in your system’s PATH. You can confirm that Composer was installed successfully by checking its version:
composer --version
Step 4: Install Laravel
You are now ready to create a new Laravel project. Use Composer to create a fresh Laravel installation by running this command:
composer create-project --prefer-dist laravel/laravel my-laravel-app
This command will download the latest version of Laravel and set up a new project named “my-laravel-app
“. Once the installation completes, navigate into your project directory:
cd my-laravel-app
Step 5: Configure Environment Variables
The next step involves configuring environment variables for your application. Laravel uses an `.env
` file located in the root of your project directory to manage environment-specific settings like database connections and application keys.
Edit the `.env
` file using a text editor of your choice (e.g., nano
or vim
):
nano .env
You’ll need to set up database connection parameters. Here’s an example configuration for a MySQL database:
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
This configuration allows Laravel to connect to your MySQL database using the specified credentials.
Step 6: Set Up Web Server
Your Laravel application needs a web server to be accessible over the internet or locally. You can choose between Apache and Nginx as your web server. Below are instructions for both options.
Nginx Setup
If you prefer Nginx, install it using the following command:
sudo dnf install nginx
Create a new server block configuration file for your Laravel application:
sudo nano /etc/nginx/conf.d/my-laravel-app.conf
Add the following configuration settings to serve your Laravel application:
server {
listen 80;
server_name your_domain.com;
root /var/www/html/my-laravel-app/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
This configuration sets up Nginx to serve files from the public directory of your Laravel application while routing requests through `index.php` for processing by Laravel’s routing engine.
Apache Setup
If you prefer Apache, install it using this command:
sudo dnf install httpd
Create a new virtual host configuration file for Apache:
sudo nano /etc/httpd/conf.d/my-laravel-app.conf
Add the following configuration settings:
<VirtualHost *:80> DocumentRoot "/var/www/html/my-laravel-app/public" ServerName your_domain.com <Directory "/var/www/html/my-laravel-app/public"> AllowOverride All Require all granted </Directory> </VirtualHost>
This configuration tells Apache where to find your Laravel application and allows `.htaccess` files within the public directory to override default settings.
Step 7: Set Permissions
The final setup step involves adjusting permissions on specific directories within your Laravel application. Proper permissions are crucial for ensuring that Laravel can write logs and cache data effectively.
sudo chown -R nginx:nginx /var/www/html/my-laravel-app/storage/
sudo chown -R nginx:nginx /var/www/html/my-laravel-app/bootstrap/cache/
sudo chmod -R 775 /var/www/html/my-laravel-app/storage/
sudo chmod -R 775 /var/www/html/my-laravel-app/bootstrap/cache/
If you are using Apache instead of Nginx, replace `nginx:nginx
` with `apache:apache
` in the commands above.
Step 8: Start the Server and Access Laravel
Your web server needs to be running to access your newly installed Laravel application. Start Nginx or Apache using one of these commands:
sudo systemctl start nginx # For Nginx
sudo systemctl start httpd # For Apache
You can also enable it to start automatically on boot with these commands:
sudo systemctl enable nginx # For Nginx
sudo systemctl enable httpd # For Apache
Your application should now be accessible via a web browser at `http://your-IP-address
` or `http://your-domain.com
`. You should see the default Laravel welcome page if everything is set up correctly.
Troubleshooting Tips
- If you encounter a “403 Forbidden” error when accessing your application, check that you have set correct permissions on the storage and bootstrap/cache directories as outlined in Step 7.
- If you see a “500 Internal Server Error,” check your server logs (located at `
/var/log/nginx/error.log
` or `/var/log/httpd/error_log
`) for more information about what went wrong during processing. - If Composer commands fail due to missing extensions, ensure that all required PHP extensions are installed correctly as mentioned in Step 2.
- If you experience issues with database connectivity, double-check your `.env` file settings against your actual database credentials and ensure that MySQL is running.
- If changes made in `.env` do not reflect immediately, run `php artisan config:cache` within your project directory to clear cached configurations.
Congratulations! You have successfully installed Laravel. Thanks for using this tutorial for installing Laravel on Fedora 41 system. For additional help or useful information, we recommend you check the Laravel website.