FedoraRHEL Based

How To Install Laravel on Fedora 42

Install Laravel on Fedora 42

Laravel stands as one of the most popular PHP frameworks for web development, offering elegant syntax and powerful features that streamline application development. Fedora 42, with its cutting-edge technology stack and robust security features, provides an excellent foundation for Laravel development. This comprehensive guide will walk you through the complete installation process, ensuring you have a fully functional Laravel environment ready for development.

Whether you’re a seasoned developer or just starting your journey with PHP frameworks, this tutorial covers everything from system preparation to final optimization. You’ll learn how to set up the perfect development environment that leverages Fedora’s advanced features while maintaining Laravel’s performance standards.

Prerequisites and System Requirements

Before diving into the installation process, understanding the system requirements ensures a smooth setup experience. Laravel requires specific software components and system configurations to function optimally on Fedora 42.

Hardware Specifications

Your Fedora 42 system should meet minimum hardware requirements for optimal Laravel performance. A modern Intel or AMD processor provides the computational power needed for PHP processing and database operations. At least 2GB of RAM is essential, though 4GB or more is recommended for development environments that run multiple services simultaneously.

Storage requirements include a minimum of 20GB available disk space to accommodate the operating system, development tools, and your Laravel projects. Consider using SSD storage for improved performance, especially when working with large datasets or multiple concurrent applications.

Software Dependencies Overview

Laravel’s dependency stack requires careful attention to version compatibility. PHP 8.0 or higher serves as the foundation, with PHP 8.2 being the recommended version for new projects. The framework supports multiple database systems including MySQL, PostgreSQL, SQLite, and SQL Server, giving you flexibility in choosing your preferred database solution.

Composer 2.x acts as the dependency manager, handling package installations and updates automatically. Node.js 14.x or higher becomes necessary when working with front-end assets, enabling modern JavaScript compilation and CSS preprocessing through tools like Vite or Laravel Mix.

Web server options include Nginx or Apache, both capable of handling Laravel applications effectively. Nginx often provides better performance for high-traffic applications, while Apache offers more extensive module support and easier configuration for beginners.

System Preparation and Updates

Proper system preparation forms the foundation of a successful Laravel installation. Fedora 42’s package management system ensures you have access to the latest software versions and security updates.

Updating System Packages

Begin by updating your Fedora 42 system to ensure all packages are current. This process involves refreshing the package database and installing available updates:

sudo dnf update

This command updates all installed packages to their latest versions, applying security patches and bug fixes. The process may take several minutes depending on your system’s current state and available updates. After completion, consider rebooting your system to ensure all updates take effect properly.

Installing Development Tools

Essential development tools enhance your Laravel development experience. Git provides version control capabilities, allowing you to track changes and collaborate with other developers:

sudo dnf install git

Text editors and IDEs improve code editing efficiency. Popular choices include Visual Studio Code, Sublime Text, or Vim for command-line editing. Install your preferred editor to ensure a comfortable development environment.

Security Configuration

Fedora 42’s security features require proper configuration for web development. The firewall needs appropriate rules to allow web traffic during development and testing phases. Configure firewall rules to permit HTTP and HTTPS traffic:

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

SELinux provides additional security layers but may require configuration adjustments for web applications. Understanding SELinux contexts helps prevent permission-related issues during Laravel development.

Installing PHP and Required Extensions

PHP installation on Fedora 42 involves selecting the appropriate version and ensuring all necessary extensions are available. Laravel’s requirements specify particular PHP extensions that enable framework functionality.

PHP Installation Process

Fedora 42 typically includes PHP 8.2 in its repositories, meeting Laravel’s minimum requirements. Install PHP along with essential extensions using the DNF package manager:

sudo dnf install php php-cli php-common php-json php-mbstring php-mysqlnd php-xml php-zip

This command installs the core PHP package and essential extensions. Each extension serves specific purposes:

  • php-cli enables command-line PHP execution
  • php-common provides shared files for PHP packages
  • php-json handles JSON data processing
  • php-mbstring supports multibyte string operations
  • php-mysqlnd optimizes MySQL database connections
  • php-xml processes XML documents
  • php-zip manages ZIP file operations

Additional PHP Extensions

Laravel applications often require additional PHP extensions depending on project requirements. Install commonly needed extensions:

sudo dnf install php-gd php-curl php-bcmath php-soap php-ldap php-xmlrpc php-gmp

These extensions provide:

  • Image processing capabilities (php-gd)
  • HTTP client functionality (php-curl)
  • Arbitrary precision mathematics (php-bcmath)
  • SOAP web service support (php-soap)
  • LDAP directory access (php-ldap)
  • XML-RPC communication (php-xmlrpc)
  • GNU Multiple Precision arithmetic (php-gmp)

PHP Configuration

Verify your PHP installation and check the installed version:

php -v

The output should display PHP 8.2 or higher, confirming successful installation. Review PHP configuration by examining the php.ini file, typically located at /etc/php.ini. Key settings include memory limits, execution time, and error reporting levels.

Web Server Installation and Configuration

Laravel applications require a web server to handle HTTP requests and serve application content. Both Nginx and Apache provide excellent performance for Laravel applications, with Nginx often preferred for its efficiency and configuration simplicity.

Installing Nginx

Install Nginx using Fedora’s package manager:

sudo dnf install nginx

Start and enable the Nginx service to ensure it runs automatically on system boot:

sudo systemctl start nginx
sudo systemctl enable nginx

Nginx Configuration for Laravel

Create a virtual host configuration for your Laravel application. Create a new configuration file:

sudo nano /etc/nginx/conf.d/laravel.conf

Add the following configuration:

server {
    listen 80;
    server_name laravel.yourdomain.com;
    root /var/www/html/laravelsite/public;
    index index.php;
    charset utf-8;
    
    gzip on;
    gzip_types text/css application/javascript text/javascript application/x-javascript image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon;
    
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    
    location ~ \.php {
        include fastcgi.conf;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/run/php-fpm/www.sock;
    }
    
    location ~ /\.ht {
        deny all;
    }
}

This configuration sets up URL rewriting, PHP processing, and security measures for your Laravel application.

PHP-FPM Configuration

Laravel applications benefit from PHP-FPM (FastCGI Process Manager) for improved performance. Install and configure PHP-FPM:

sudo dnf install php-fpm
sudo systemctl start php-fpm
sudo systemctl enable php-fpm

PHP-FPM handles PHP requests efficiently, separating web server processes from PHP execution for better resource management and security.

Database Server Setup

Laravel supports multiple database systems, with MySQL/MariaDB being the most popular choice for development and production environments. Proper database configuration ensures reliable data storage and retrieval for your applications.

MariaDB Installation

Install MariaDB server on Fedora 42:

sudo dnf install mariadb-server

Start and enable the MariaDB service:

sudo systemctl start mariadb
sudo systemctl enable mariadb

Database Security Configuration

Secure your MariaDB installation using the security script:

sudo mysql_secure_installation

This interactive script guides you through important security configurations:

  • Setting a root password
  • Removing anonymous users
  • Disabling remote root login
  • Removing test databases
  • Reloading privilege tables

Creating Laravel Database

Create a dedicated database and user for your Laravel application:

mysql -u root -p

Execute the following SQL commands:

CREATE DATABASE laravel_db;
CREATE USER 'laravel_user'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON laravel_db.* TO 'laravel_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

This creates a database named laravel_db with a dedicated user having appropriate permissions.

Composer Installation

Composer serves as PHP’s dependency manager, essential for Laravel installation and package management. Proper Composer installation ensures smooth dependency resolution and project management.

Installing Composer Globally

Download and install Composer globally on your system:

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

This process downloads the Composer installer, executes it, and moves the resulting binary to a globally accessible location. Verify the installation:

composer --version

The output should display the Composer version, confirming successful installation.

Composer Configuration

Configure Composer for optimal performance and security. Set up global configuration directory:

mkdir -p ~/.config/composer

Configure Composer to use system-wide packages when possible, reducing download times and disk usage. Update your PATH environment variable to include Composer’s global bin directory:

echo 'export PATH="$HOME/.config/composer/vendor/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

Laravel Installation

With all prerequisites installed and configured, you can now install Laravel and create your first application. Laravel offers multiple installation methods, with Composer create-project being the most reliable approach.

Creating Laravel Project

Create a new Laravel project using Composer:

composer create-project --prefer-dist laravel/laravel my-laravel-app

This command downloads the latest Laravel version and creates a new project directory named my-laravel-app. The --prefer-dist flag ensures you receive the stable distribution packages rather than development versions.

Navigate to your project directory:

cd my-laravel-app

Setting File Permissions

Laravel requires specific file permissions for proper operation. Set appropriate permissions for storage and cache directories:

sudo chown -R www-data:www-data storage bootstrap/cache
sudo chmod -R 775 storage bootstrap/cache

These permissions allow the web server to write log files, cache data, and store uploaded files while maintaining security.

Generating Application Key

Laravel requires a unique application key for security purposes. Generate this key using Artisan:

php artisan key:generate

This command creates a random 32-character string and updates your .env file automatically. The application key encrypts session data and other sensitive information.

Laravel Configuration

Proper configuration ensures your Laravel application connects to services correctly and operates according to your requirements. The .env file contains environment-specific settings that should be customized for your setup.

Environment Configuration

Edit the .env file in your project root:

nano .env

Configure database connection parameters:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_db
DB_USERNAME=laravel_user
DB_PASSWORD=your_password

Update the application URL to match your development environment:

APP_URL=http://laravel.yourdomain.com

Running Database Migrations

Laravel includes database migrations for creating essential tables. Run these migrations to set up your database structure:

php artisan migrate

This command creates tables for user authentication, password resets, and other Laravel features. The migration system tracks which migrations have been applied, preventing duplicate executions.

Cache Configuration

Clear and optimize Laravel’s configuration cache:

php artisan config:cache
php artisan route:cache
php artisan view:cache

These commands improve application performance by caching configuration files, routes, and compiled view templates.

Testing Laravel Installation

Verifying your Laravel installation ensures everything works correctly before beginning development. Laravel provides multiple testing methods to confirm proper functionality.

Starting Development Server

Laravel includes a built-in development server for testing purposes:

php artisan serve

This command starts a development server on http://localhost:8000. Visit this URL in your web browser to see Laravel’s welcome page, confirming successful installation.

Accessing Through Web Server

If using Nginx, access your application through the configured domain name. Ensure your /etc/hosts file includes an entry for local development:

127.0.0.1 laravel.yourdomain.com

Visit http://laravel.yourdomain.com to view your Laravel application through the web server configuration.

Install Laravel on Fedora 42

Running Laravel Tests

Laravel includes PHPUnit for testing. Execute the test suite to verify framework functionality:

php artisan test

All tests should pass, indicating a properly configured Laravel installation. Test failures may indicate configuration issues requiring attention.

Optimization and Best Practices

Optimizing your Laravel installation improves performance and security. These practices ensure your development environment operates efficiently and securely.

Performance Optimization

Enable PHP OPcache for improved performance. Edit /etc/php.ini and configure OPcache settings:

opcache.enable=1
opcache.memory_consumption=256
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=2
opcache.fast_shutdown=1

Restart PHP-FPM to apply these changes:

sudo systemctl restart php-fpm

Security Best Practices

Keep your system updated regularly to receive security patches. Enable automatic security updates:

sudo dnf install dnf-automatic
sudo systemctl enable dnf-automatic.timer
sudo systemctl start dnf-automatic.timer

Configure file permissions appropriately, ensuring web server processes can access necessary files while maintaining security boundaries.

Development Workflow

Initialize Git repository for version control:

git init
git add .
git commit -m "Initial Laravel installation"

Create a .gitignore file to exclude unnecessary files from version control. Laravel includes a comprehensive .gitignore file by default.

Troubleshooting Common Issues

Even with careful installation, you may encounter issues. Understanding common problems and their solutions saves development time and frustration.

Permission Errors

Storage and cache permission errors are common. Verify and correct permissions:

sudo chown -R $USER:www-data storage bootstrap/cache
sudo chmod -R 775 storage bootstrap/cache

Ensure the web server user can write to these directories while maintaining security.

Database Connection Issues

Database connection problems often stem from incorrect credentials or service status. Verify MariaDB is running:

sudo systemctl status mariadb

Check .env file database settings and test connection manually:

mysql -u laravel_user -p laravel_db

SELinux Conflicts

SELinux may prevent web server access to Laravel files. Check SELinux status:

sestatus

If SELinux is enforcing, configure appropriate contexts for web content:

sudo setsebool -P httpd_can_network_connect 1
sudo restorecon -Rv /var/www/html/

PHP Extension Missing

Missing PHP extensions cause Laravel functionality issues. Install any missing extensions:

sudo dnf install php-extension-name
sudo systemctl restart php-fpm

Verify extension loading:

php -m | grep extension-name

Congratulations! You have successfully installed Laravel. Thanks for using this tutorial for installing Laravel on Fedora 42 Linux system. For additional help or useful information, we recommend you check the official Laravel website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button