This tutorial is about How to Install Laravel on CentOS 6/7
Laravel is a free, open-source MVC PHP web framework intended for the development of full-featured web applications. This framework is robust and easy to understand. By using Laravel, we can reuse the existing components of different frameworks to create a web application. The web application designed with Laravel is more structured and realistic, and the features offered by Laravel can boost the speed of web development. The namespaces and interfaces included in Laravel can help you organize and manage the resources. The use of the Laravel framework can make your web application more scalable.
Install Laravel on CentOS 6/7
To install the Laravel 6 PHP Framework on CentOS/RHEL 6/7 system, you can follow the below-given steps.
1) Setup Yum Repositories
First, we need to add the REMI and EPEL rpm repositories in your system. These repositories contain the updated packages. You can use the following commands to set up the rpm repositories.
On CentOS/RHEL – 6:
On CentOS/RHEL – 7:
2) Install Apache, MySQL, and PHP
To run the Laravel framework, we need to install the LAMP stack. LAMP stands for Linux, Apache, MySQL, and PHP. This stack is used to host web applications written with PHP programming language and if they are using the MySQL database server in the backend.
Install Apache Server
To install the Apache web server, you can run the following command:
# yum –enablerepo=epel,remi install httpd
After installing the server, you need to start and enable the httpd service on boot using the following commands.
# systemctl enable httpd.service
# systemctl start httpd.service
Install MySQL Server
First, we need to add MySQL yum repository in your system using the below command.
# rpm -Uvh https://repo.mysql.com/mysql80-community-release-el7-1.noarch.rpm
Then, you need to install MySQL server and other dependency packages by using the following command.
# yum install mysql-server
After installation, we need to enable the MySQL service and then start the service.
# systemctl enable mysqld.service
# systemctl start mysqld.service
Once the MySQL service starts, we need to secure your newly installed server by using the following command.
This command prompts you to change the temporary password with a new password.
Change the password for root? – y
Remove anonymous users? – y
Disallow root login remotely? – y
Remove test database and access to it? – y
Reload privilege tables now? – y
After installing MySQL, you need to install PHP on the server. First, you need to install PHP packages with enabling EPEL and REMI repositories using the below command.
# yum –enablerepo=epel,remi-php73 install php
After installing the packages, you need to install all the required PHP modules. First, you need to list the available modules and then install it.
# yum –enablerepo=remi-php73 list php-*
# yum –enablerepo=remi-php73 install php-mysql php-xml php-xmlrpc php-soap php-gd
After installation PHP and other PHP modules, you need to restart the Apache service.
# systemctl restart httpd.service
3) Install Composer
A composer is a tool that includes all the dependencies and libraries. For installing Laravel dependencies, we require the composer tool. You can run the following commands to install the composer.
# curl -sS https://getcomposer.org/installer | php
# mv composer.phar /usr/bin/composer
# chmod +x /usr/bin/composer
4) Install Laravel
To install the latest version of Laravel, you can use the following command to clone the master repo of Laravel from GitHub.
# cd /var/www
# git clone https://github.com/laravel/laravel.git
Next, you need to move to the Laravel code directory and then install all the dependencies required for the Laravel framework by using the composer install command.
# cd /var/www/laravel
# composer install
After installing the dependencies, you need to set the proper permissions on the files.
# chown -R apache.apache /var/www/laravel
# chown -R 755 /var/www/laravel
# chown -R 755 /var/www/laravel/storage
To allow SELinux enabled systems to write on storage directory, you can run the following command.
# chcon -R -t httpd_sys_rw_content_t /var/www/laravel/storage
5) Set Encryption Key
To set the environment configuration, you can use the Laravel .evn file. You can use this file to configure all the environment variables for your application, such as the database, SMTP, security key, and more. You can create an environment file for your application, using the sample file provided.
# cp .env.example .env
Laravel uses an application key to secure user sessions and other data, so you can use the following command to generate and set your application key to a random string. This application key set gets configured into the .env file after generation.
# php artisan key:generate
6) Create Apache Virtual Host
To access the Laravel framework from a web browser, you can add a Virtual Host in your Apache configuration file.
# vim /etc/httpd/conf/httpd.conf
To access the Laravel framework, you need to edit the Apache configuration file and add the below code at the end of the file.
After adding the above code, save the file. Restart the Apache service using the following command.
# service httpd restart
After the restart, you can access the Laravel framework from any web browser. After accessing the framework, you can start developing the web application.
You can open the Laravel using either the IP address or the domain name in the browser using the below address.