Laravel is an open source PHP framework designed for the faster development of MVC web applications in PHP. This article will help you to install Laravel 8 PHP Framework on Fedora system.
Suggested tutorials:
Step 1 – Install Packages
PHP is required to run the Laravel applications. As a backend database, you can use the MySQL/MariaDB server. Here is a short instruction for the installation of the LAMP stack on Fedora. It’s required to run the Laravel framework on your Fedora system. You can also use this guide for the detailed instructions to setup LAMP environment on Fedora systems.
Install Apache
sudo dnf install httpd
Install MySQL
sudo dnf install mariadb-server sudo systemctl start mariadb.service /usr/bin/mysql_secure_installation
Install PHP
sudo dnf install php php-zip php-mysqlnd php-mcrypt php-xml php-mbstring
Install Composer
sudo dnf install composer unzip
Step 2 – Install Laravel on Fedora
To download latest version of Laravel, Use below command to clone master repo of laravel from github.
cd /var/www/ git clone https://github.com/laravel/laravel.git
Navigate to the Laravel code directory and use the composer to install all dependencies required for the Laravel framework.
cd /var/www/laravel composer install
Dependency installation will take some time. After that set proper permissions on files.
chown -R username:apache /var/www/laravel chmod -R 755 /var/www/laravel chmod -R 755 /var/www/laravel/storage
SELinux enabled systems also run the below command to allow writing on the storage directory.
chcon -R -t httpd_sys_rw_content_t /var/www/laravel/storage
Step 3 – Configure Laravel Environment
Laravel uses .env
file for environment configuration. Use .env file for configuring all the environment variables for your application like the database, SMTP, security key, etc.
cp .env.example .env
Now set the 32-bit long random number encryption key, which is used by the Illuminate encrypter service.
php artisan key:generate Application key set successfully.
You can view the .env
file to find the Application key is configured. In addition, you can also update the MySQL database configuration details in .env file as below.
DB_HOST=localhost DB_DATABASE=laravel DB_USERNAME=username DB_PASSWORD=password
Step 4 – Run Laravel with Artisan
For the development purpose, you can run a Laravel application with Artisan command-line interface. Artisan starts a Laravel development server on your system, which you can access in a web browser.
php artisan serve Laravel development server started: http://127.0.0.1:8000
The default Artisan starts Laravel on port 8000 for localhost only. To access Laravel over the network specify your system IP with –host option or use IP 0.0.0.0 for public access.
You can also use –port followed by the port number to use another port to serve the Laravel application. For example, use the below command.
php artisan serve --host 0.0.0.0 --port 8000 Laravel development server started: http://0.0.0.0:8000
Step 5 – Setup Laravel with Apache
Now add a Virtual Host in your Apache configuration file to access the Laravel framework in a web browser. To create an Apache configuration file /etc/httpd/conf.d/laravel.conf
sudo vi /etc/httpd/conf.d/laravel.conf
and add the following settings:
<VirtualHost *:80> ServerName laravel.tecadmin.net DocumentRoot /var/www/laravel/public <Directory /var/www/laravel> AllowOverride All </Directory> </VirtualHost>
Save your file and restart Apache service:
sudo systemctl restart httpd.service
Then access the Laravel website in a web browser with the specified domain name. Make sure the domain/subdomain is correctly pointed to the Laravel server in DNS.
Conclusion
In conclusion, you have configured Laravel on your Fedora system. Now, you can follow our tutorials like: Clear Laravel Cache, Check Laravel Version and Remove index.php from URL in Laravel.