How to Install Laravel on CentOS 7

r00t August 19, 2017

Install Laravel on CentOS 7

In this tutorial we’ll learn how to install Laravel on CentOS 7. We will also install and configure its prerequisites. Laravel is an open source PHP framework based on the MVC (Model View Controller). Laravel makes it easier for a developer to write web applications. Laravel is considered the best framework to write PHP applications together with other frameworks. Laravel provides a modular packaging system and a dedicated dependency manager. It supports many different relational databases and provides different ways for accessing them.

I recommend to use a minimal Ubuntu server setup as a basis for the tutorial, that can be a virtual or a root server image with an CentOS 7 minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.

Install Laravel on CentOS 7

Step 1. First, ensure your system is fully up-to-date by running the following:

yum -y update

Step 2. Installing LAMP on CentOS 7.

You should check out this LAMP stack install tutorial for CentOS 7, if you haven’t installed LAMP yet. Once it’s installed, come back here and read on. We also will install the required packages for LAMP stack and the important PHP extension that Laravel relies on:

yum install php70w php70w-dom php70w-mbstring php70w-gd php70w-pdo php70w-json php70w-xml php70w-zip php70w-curl php70w-mcrypt

Step 3. Installing Composer.

Composer is required for installing Laravel dependencies. So use below commands to download and use as a command in our system:

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

Run the following command to check if composer is installed and working correctly:

composer -V

Step 4. Installing Laravel.

Download the latest version of Laravel using the commands below:

cd /var/www
git clone https://github.com/laravel/laravel.git

After than move to the laravel code directory and use composer to install all dependencies required for Laravel framework:

cd /var/www/laravel
composer install

After composer finishes the installation, you will have to set the appropriate permissions for Laravel directory, so that it can be owned and managed by Apache:

chown -R apache.apache /var/www/laravel
chmod -R 755 /var/www/laravel

Step 5. Set Encryption Key.

Now set the 32 bit long random number encrypption key, which used by the Illuminate encrypter service:

php artisan key:generate
Application key [WRAGp0Pu9kTHiZBMWe46KGXDjSWNL76iF] set successfully.

Then update the above generated application key into the config/app.php configuration file. Also make sure that cipher is set properly:

'key' => env('WRAGp0Pu9kTHiZBMWe46KGXDjSWNL76iF')/ This key is used by the Illuminate encrypter service and should be set. 
'cipher' => 'AES-256-CBC',

Step 6. Create Apache Virtual Host.

Now create a Virtual Host in your Apache configuration file to access Laravel framework from web browser:

### nano /etc/httpd/conf/httpd.conf

<VirtualHost *:80>
 ServerName laravel.example.com
 DocumentRoot /var/www/laravel/public

<Directory /var/www/laravel>
 AllowOverride All
 </Directory>
</VirtualHost>

Once done it’s time restart Apache in order to put your changes into effect:

systemctl start httpd

Step 7. Accessing Laravel Web Installation.

Now you can access the Laravel web install wizard in your browser by entering the domain name or http://your ip/ and you will see the application running.

Congratulation’s! You have successfully install and configured Laravel on your CentOS 7 server.

Save

The Tags:

Leave a Comment

Comments are closed.