Learn how to install Laravel Framework on Rocky Linux 8 with this comprehensive guide. Follow our step-by-step instructions to set up Laravel, configure your environment, and get your development project started seamlessly. #centlinux #linux #laravel
Table of Contents
What is Laravel Framework?
Laravel is a popular open-source PHP framework designed for web application development. It follows the Model-View-Controller (MVC) architectural pattern, providing developers with a structured and efficient way to build robust web applications. Here are some key features and benefits of Laravel:
- Elegant Syntax: Laravel is known for its clean and expressive syntax, making it accessible and enjoyable to use for developers.
- Built-in Tools: It comes with a variety of built-in tools and features such as routing, authentication, caching, and sessions, which streamline common tasks and enhance productivity.
- Eloquent ORM: Laravel includes Eloquent, an advanced Object-Relational Mapping (ORM) system, which simplifies database interactions and makes it easier to work with data.
- Blade Templating Engine: The Blade templating engine allows developers to create dynamic, reusable templates with a straightforward syntax.
- Artisan CLI: The Artisan command-line interface offers a range of commands to automate repetitive tasks, such as database migrations and scaffolding.
- Security: Laravel provides robust security features, including protection against common vulnerabilities such as SQL injection, cross-site request forgery (CSRF), and cross-site scripting (XSS).
- Community and Ecosystem: Laravel has a large and active community, offering extensive documentation, tutorials, and a wide range of packages available through Composer.
Overall, Laravel is a powerful and versatile framework that simplifies the process of developing modern web applications, making it a preferred choice for many developers.
PHP Laravel Alternatives:
There are several alternatives to the PHP Laravel framework, each with its own strengths and features. Here are some popular ones:
- Symfony:
- Description: A robust and flexible PHP framework, Symfony is known for its reusable components and extensive documentation.
- Strengths: High flexibility, large ecosystem, highly customizable, enterprise-grade applications.
- Use Cases: Suitable for large-scale applications and projects requiring extensive customization.
- CodeIgniter:
- Description: A lightweight PHP framework known for its simplicity and ease of use.
- Strengths: Simple and small footprint, easy to learn, good performance.
- Use Cases: Ideal for small to medium-sized projects and developers looking for a straightforward framework.
- CakePHP:
- Description: A mature framework with a focus on convention over configuration and rapid development.
- Strengths: Built-in ORM, form validation, and authentication, rapid prototyping.
- Use Cases: Suitable for developers who prefer convention over configuration and rapid development cycles.
- Yii:
- Description: A high-performance PHP framework that is component-based and follows the MVC pattern.
- Strengths: High performance, security features, easy integration with third-party libraries.
- Use Cases: Good for large-scale applications requiring high performance and security.
- Zend Framework / Laminas:
- Description: A full-featured, object-oriented PHP framework, now continued as Laminas.
- Strengths: Enterprise-grade, extensive documentation, flexible architecture.
- Use Cases: Suitable for enterprise applications and projects requiring a robust and scalable framework.
- Phalcon:
- Description: An open-source PHP framework implemented as a web server extension written in C, providing exceptional performance.
- Strengths: High performance, low overhead, rich feature set.
- Use Cases: Ideal for performance-critical applications and projects where speed is a priority.
- FuelPHP:
- Description: A flexible, community-driven PHP framework supporting the MVC pattern as well as the Hierarchical Model-View-Controller (HMVC) pattern.
- Strengths: Modular, extendable, supports multiple types of routing.
- Use Cases: Suitable for projects that need a modular architecture and flexible routing.
- Slim:
- Description: A micro-framework for PHP, Slim is minimalist and focuses on rapid development of small web applications and APIs.
- Strengths: Lightweight, fast, easy to learn, and integrates well with other components.
- Use Cases: Best for small applications, RESTful APIs, and developers looking for a lightweight solution.
Each of these frameworks offers unique advantages, making them suitable for different types of projects and developer preferences.
Recommended Online Training: Laravel Database Queries – From Beginner to Highly Advanced
Environment Specification
We are using a minimal Rocky Linux 8 virtual machine with following specifications.
- CPU – 3.4 Ghz (2 cores)
- Memory – 2 GB
- Storage – 20 GB
- Operating System – Rocky Linux 8.5 (Green Obsidian)
- Hostname – laravel-01.centlinux.com
- IP Address – 192.168.116.131 /24
Update Rocky Linux OS
By using a SSH client, connect with laravel-01.centlinux.com machine as root user.
Rebuild yum cache of enabled repositories.
# dnf makecache
Execute following command to update already installed software packages on your Rocky Linux Operating System.
# dnf update -y
If the above command updates your Linux Kernel, then you should reboot your Linux Operating System before moving forward.
# reboot
After reboot, check Linux Operating System and Linux Kernel versions as follows.
# cat /etc/rocky-release && uname -r Rocky Linux release 8.5 (Green Obsidian) 4.18.0-348.20.1.el8_5.x86_64
Install PHP 8.1 on Rocky Linux 8
PHP 8.1 is the latest release of the most popular server-side programming language at the time of this writing.
PHP 8.1 is currently not available in standard yum repositories.
Therefore, you have to install Remi yum repository to grab the latest version of PHP.
Execute following command to install Remi yum repository on Rocky Linux 8.
# dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm
Rebuild yum cache of newly installed repositories.
# dnf makecache
Get list of available PHP modules in installed yum repositories.
# dnf module list php Last metadata expiration check: 0:00:31 ago on Sat 02 Apr 2022 10:01:23 PM PKT. Rocky Linux 8 - AppStream Name Stream Profiles Summary php 7.2 [d] common [d], devel, minimal PHP scripting language php 7.3 common [d], devel, minimal PHP scripting language php 7.4 common [d], devel, minimal PHP scripting language Remi's Modular repository for Enterprise Linux 8 - x86_64 Name Stream Profiles Summary php remi-7.2 common [d], devel, minimal PHP scripting language php remi-7.3 common [d], devel, minimal PHP scripting language php remi-7.4 common [d], devel, minimal PHP scripting language php remi-8.0 common [d], devel, minimal PHP scripting language php remi-8.1 common [d], devel, minimal PHP scripting language Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
You can now easily install PHP 8.1 by executing following command on Linux bash prompt.
# dnf module install -y php:remi-8.1
Install PHP Composer on Rocky Linux 8
PHP composer is needed to install and configure the Laravel framework.
But before installing PHP Composer, you must also install git and unzip packages. These packages are required during PHP Composer installation.
# dnf install -y git unzip
Download and install PHP Composer by executing following command at Linux bash prompt.
# cd /tmp # curl -sS https://getcomposer.org/installer | php All settings correct for using Composer Downloading... Composer (version 2.3.3) successfully installed to: /tmp/composer.phar Use it: php composer.phar
Rename and move the composer.phar file to location that is included in your PATH variable. So you can execute composer command from anywhere. Also set execution permissions of composer file.
# mv composer.phar /usr/local/bin/composer # chmod +x /usr/local/bin/composer
Now. execute following command to check the PHP Composer version.
# composer -V Composer version 2.3.3 2022-04-01 22:15:35
How to install Laravel Framework on Rocky Linux 8
Download and install Laravel Framework and dependent libraries by using composer command.
# composer global require "laravel/installer" Changed current directory to /root/.config/composer Using version ^4.2 for laravel/installer ./composer.json has been updated Running composer update laravel/installer Loading composer repositories with package information Updating dependencies Nothing to modify in lock file Installing dependencies from lock file (including require-dev) Package operations: 10 installs, 0 updates, 0 removals - Downloading symfony/process (v6.0.7) - Downloading symfony/polyfill-mbstring (v1.25.0) - Downloading symfony/polyfill-intl-normalizer (v1.25.0) - Downloading symfony/polyfill-intl-grapheme (v1.25.0) - Downloading symfony/polyfill-ctype (v1.25.0) - Downloading symfony/string (v6.0.3) - Downloading psr/container (2.0.2) - Downloading symfony/service-contracts (v3.0.0) - Downloading symfony/console (v6.0.7) - Downloading laravel/installer (v4.2.10) - Installing symfony/process (v6.0.7): Extracting archive - Installing symfony/polyfill-mbstring (v1.25.0): Extracting archive - Installing symfony/polyfill-intl-normalizer (v1.25.0): Extracting archive - Installing symfony/polyfill-intl-grapheme (v1.25.0): Extracting archive - Installing symfony/polyfill-ctype (v1.25.0): Extracting archive - Installing symfony/string (v6.0.3): Extracting archive - Installing psr/container (2.0.2): Extracting archive - Installing symfony/service-contracts (v3.0.0): Extracting archive - Installing symfony/console (v6.0.7): Extracting archive - Installing laravel/installer (v4.2.10): Extracting archive Generating autoload files 8 packages you are using are looking for funding. Use the `composer fund` command to find out more!
Composer downloads the Laravel and other libraries in ~/.config/composer/vendor/bin directory.
Therefore, to make laravel command executable from anywhere, you need to include this location in PATH variable.
# echo 'export PATH="$PATH:$HOME/.config/composer/vendor/bin"' >> ~/.bash_profile
Execute .bash_profile once to load these changes.
# source .bash_profile
Now, execute following command to get Laravel version.
# laravel -V Laravel Installer 4.2.10
You have successfully install Laravel on Rocky Linux 8.
Create a New Laravel Project
Go to your home directory and create a new Laravel project as follows.
# cd
# laravel new helloworld
_ _
| | | |
| | __ _ _ __ __ ___ _____| |
| | / _` | '__/ _` / / _ |
| |___| (_| | | | (_| | V / __/ |
|________,_|_| __,_| _/ ___|_|
Creating a "laravel/laravel" project at "./helloworld"
Installing laravel/laravel (v9.1.3)
- Downloading laravel/laravel (v9.1.3)
- Installing laravel/laravel (v9.1.3): Extracting archive
Created project in /root/helloworld
> @php -r "file_exists('.env') || copy('.env.example', '.env');"
Loading composer repositories with package information
Updating dependencies
...
...
...
Package manifest generated successfully.
78 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
> @php artisan vendor:publish --tag=laravel-assets --ansi --force
No publishable resources for tag [laravel-assets].
Publishing complete.
> @php artisan key:generate --ansi
Application key set successfully.
Application ready! Build something amazing.
You have successfully create a new Laravel project.
Typically, you may use a web server such as Apache or Nginx to serve your Laravel applications. If you are on PHP 5.4+ and would like to use PHP’s built-in development server, you may use the serve Artisan command.
Artisan is the command line interface included with Laravel. Artisan exists at the root of your application as the artisan script and provides a number of helpful commands that can assist you while you build your application.
Execute the following command to start Laravel development server.
# php artisan serve --host=laravel-01.centlinux.com & [1] 5727 Starting Laravel development server: http://laravel-01.centlinux.com:8000 [Sat Apr 2 22:20:46 2022] PHP 8.1.4 Development Server (http://laravel-01.centlinux.com:8000) started
Linux Firewall Settings
Artisan default service port is 8000/tcp. Therefore, you need to allow it in Linux Firewall.
# firewall-cmd --permanent --add-port=8000/tcp success # firewall-cmd --reload success
Open URL: http://laravel-01.centlinux.com:8000/ in a web browser.
Your Laravel application server has been started successfully.
To start building some amazing application, you may read Laravel: Up & Running: A Framework for Building Modern PHP Apps 2nd Edition (PAID LINK) by Matt Stauffer.
Read Also: How to install Laravel on Rocky Linux 9
Final Thoughts
Installing the Laravel Framework on Rocky Linux 8 can seem daunting, but with the right guidance, it becomes a straightforward process. By following this guide, you should now have a fully functional Laravel environment ready for your development projects. If you encounter any issues or need further assistance, I offer professional services to help you set up and customize your Laravel projects.
Feel free to visit my Fiverr profile to check out my services and get expert help with your Laravel installation and development needs. Let’s get your project up and running smoothly!