How to create a project in Laravel on Rocky Linux 8.6
To create a project in Laravel on Rocky Linux 8.6
Introduction
Laravel Framework is a free and open-source web application framework for creating high-end applications. It comes with a strong collection of tools and provides application architecture that encloses different characteristics of technologies like ASP.NET MVC, CodeIgniter, and Ruby on Rails. It facilitates developers by saving a huge time and helps reduce thinking and planning to develop the entire website from scratch.
Pre-requisites:
LAMP Stack
Apache 2.4.6
MariaDB 5.5
PHP 7.2
Composer ----> To Install Laravel Dependencies
PHP Modules:
Php php-pecl-zip php-mysql php-mcrypt php-xml php-mbstring
Create the Laravel project by using the below command
composer create-project --prefer-dist laravel/laravel
LAMP Stack version verification Check the versions of PHP, MariaDB and Apache by using the below command.
[root@linuxhelp ~]# php -v
PHP 7.2.17 (cli) (built: Apr 3 2019 10:02:16) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
[root@linuxhelp ~]# mysql -V
mysql Ver 15.1 Distrib 5.5.60-MariaDB, for Linux (x86_64) using readline 5.1
[root@linuxhelp ~]# httpd -V
Server version: Apache/2.4.6 (CentOS)
Server built: Nov 5 2018 01:47:09
Install Composer to install the Laravel dependencies by using the below command
[root@localhost ~]# curl -sS https://getcomposer.org/installer | php
All settings correct for using Composer
Downloading...
Composer (version 2.4.3) successfully installed to: /root/composer.phar
Use it: php composer.phar
Rename the Composer php.archive to the /usr/local/bin location.
[root@localhost ~]# mv composer.phar /usr/local/bin/composer
Assign the Executing permission to the composer file by using the below command
[root@localhost ~]# chmod +x /usr/local/bin/composer
Laravel Project Creation process Navigate to the Apache’s Document Root Directory by using the below command
[root@linuxhelp ~]# cd /var/www
Create the laravel project using composer as follows
[root@linuxhelp www]# composer create-project --prefer-dist laravel/laravel linuxhelp1
Installing laravel/laravel (v5.8.17)
- Installing laravel/laravel (v5.8.17): Downloading (100%)
Created project in linuxhelp1
> @php -r "file_exists('.env') || copy('.env.example', '.env');"
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 80 installs, 0 updates, 0 removals
- Installing symfony/polyfill-ctype (v1.12.0): Downloading (100%)
- Installing phpoption/phpoption (1.5.0): Downloading (100%)
- Installing vlucas/phpdotenv (v3.4.0): Downloading (100%)
.
.
.
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
> @php artisan key:generate --ansi
Application key set successfully.
List the directories inside the www directory to verify the created project
[root@linuxhelp www]# ls -la
total 8
drwxr-xr-x 5 root root 51 Aug 22 12:08 .
drwxr-xr-x. 22 root root 4096 Apr 15 10:40 ..
drwxr-xr-x 2 root root 6 Nov 5 2018 cgi-bin
drwxr-xr-x 2 root root 22 Apr 15 11:10 html
drwxr-xr-x 12 root root 4096 Aug 22 12:11 linuxhelp1
Change the directory to linuxhelp1 by using the below command
[root@linuxhelp www]# cd linuxhelp1/
List the directories inside the linuxhelp1 project
[root@linuxhelp linuxhelp1]# ls -la
total 228
drwxr-xr-x 12 root root 4096 Aug 22 12:11 .
drwxr-xr-x 5 root root 51 Aug 22 12:08 ..
drwxr-xr-x 6 root root 84 May 14 18:58 app
-rwxr-xr-x 1 root root 1686 May 14 18:58 artisan
drwxr-xr-x 3 root root 34 May 14 18:58 bootstrap
-rw-r--r-- 1 root root 1550 May 14 18:58 composer.json
-rw-r--r-- 1 root root 167767 Aug 22 12:11 composer.lock
drwxr-xr-x 2 root root 247 May 14 18:58 config
drwxr-xr-x 5 root root 72 May 14 18:58 database
-rw-r--r-- 1 root root 213 May 14 18:58 .editorconfig
-rw-r--r-- 1 root root 790 Aug 22 12:11 .env
-rw-r--r-- 1 root root 739 May 14 18:58 .env.example
-rw-r--r-- 1 root root 111 May 14 18:58 .gitattributes
-rw-r--r-- 1 root root 151 May 14 18:58 .gitignore
-rw-r--r-- 1 root root 1125 May 14 18:58 package.json
-rw-r--r-- 1 root root 1156 May 14 18:58 phpunit.xml
drwxr-xr-x 4 root root 116 May 14 18:58 public
-rw-r--r-- 1 root root 4151 May 14 18:58 readme.md
drwxr-xr-x 6 root root 53 May 14 18:58 resources
drwxr-xr-x 2 root root 75 May 14 18:58 routes
-rw-r--r-- 1 root root 563 May 14 18:58 server.php
drwxr-xr-x 5 root root 46 May 14 18:58 storage
-rw-r--r-- 1 root root 174 May 14 18:58 .data-styleci.yml
drwxr-xr-x 4 root root 83 May 14 18:58 tests
drwxr-xr-x 40 root root 4096 Aug 22 12:11 vendor
-rw-r--r-- 1 root root 538 May 14 18:58 webpack.mix.js
Assign Ownership and Writable permissions to the linuxhelp1 project recursively by using the below command
[root@linuxhelp linuxhelp1]# chown -R apache. .
[root@linuxhelp linuxhelp1]# chmod -R 775 .
Verify the permissions assigned to the files and directories of LinuxHelp1 project by using the below command
[root@linuxhelp linuxhelp1]# ls -la
total 228
drwxrwxr-x 12 apache apache 4096 Aug 22 12:11 .
drwxr-xr-x 5 root root 51 Aug 22 12:08 ..
drwxrwxr-x 6 apache apache 84 May 14 18:58 app
-rwxrwxr-x 1 apache apache 1686 May 14 18:58 artisan
drwxrwxr-x 3 apache apache 34 May 14 18:58 bootstrap
-rwxrwxr-x 1 apache apache 1550 May 14 18:58 composer.json
-rwxrwxr-x 1 apache apache 167767 Aug 22 12:11 composer.lock
drwxrwxr-x 2 apache apache 247 May 14 18:58 config
drwxrwxr-x 5 apache apache 72 May 14 18:58 database
-rwxrwxr-x 1 apache apache 213 May 14 18:58 .editorconfig
-rwxrwxr-x 1 apache apache 790 Aug 22 12:11 .env
-rwxrwxr-x 1 apache apache 739 May 14 18:58 .env.example
-rwxrwxr-x 1 apache apache 111 May 14 18:58 .gitattributes
-rwxrwxr-x 1 apache apache 151 May 14 18:58 .gitignore
-rwxrwxr-x 1 apache apache 1125 May 14 18:58 package.json
-rwxrwxr-x 1 apache apache 1156 May 14 18:58 phpunit.xml
drwxrwxr-x 4 apache apache 116 May 14 18:58 public
-rwxrwxr-x 1 apache apache 4151 May 14 18:58 readme.md
drwxrwxr-x 6 apache apache 53 May 14 18:58 resources
drwxrwxr-x 2 apache apache 75 May 14 18:58 routes
-rwxrwxr-x 1 apache apache 563 May 14 18:58 server.php
drwxrwxr-x 5 apache apache 46 May 14 18:58 storage
-rwxrwxr-x 1 apache apache 174 May 14 18:58 .data-styleci.yml
drwxrwxr-x 4 apache apache 83 May 14 18:58 tests
drwxrwxr-x 40 apache apache 4096 Aug 22 12:11 vendor
-rwxrwxr-x 1 apache apache 538 May 14 18:58 webpack.mix.js
Navigate to the Apache Configuration File by using the below command
[root@linuxhelp public]# cd /etc/httpd/conf.d/
Create a virtual host for linuxhelp1 Project as follows
[root@linuxhelp conf.d]# vim linuxhelp1.conf
<virtualhost *:80>
servername www.linuxhelp1.com
documentroot /var/www/linuxhelp1/public/
</virtualhost>
Next Enter the Virtual host by using the below command
[root@linuxhelp conf.d]# vim /etc/hosts
Restart the service of Apache by using the below command
[root@linuxhelp conf.d]# systemctl restart httpd
Open the Browser and enter the server name that has configured inside the linuxhelp1 virtual host as shown in the below image
Check the version of Laravel by using the below command Navigate to the LinuxHelp project location
[root@linuxhelp ~]# cd /var/www/linuxhelp1/
Now check the version of Laravel using Artisan File by using the below command
[root@linuxhelp linuxhelp1]# php artisan --version
Laravel Framework 5.8.33
Conclusion:
We have reached the end of this article. In this guide, we have walked you through the steps required to create a project in Laravel on Rocky Linux 8.6. Your feedback is much welcome.