Menu
in , ,

Laravel 5 Installation On CentOS

Repo Installation

we’ll need to Install REMI and EPEL repositories, so open up a SSH connection to your server and run the following commands (make sure you run as sudo if you need to).

For CentOS 7

# wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
# wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
# rpm -Uvh remi-release-7*.rpm epel-release-7*.rpm

For EPEL Repository, you can enable extras repo @ /etc/yum.repos.d/CentOS-Base.repo, then using yum command to install it as usual.

# yum install epel-release

For CentOS 6

# wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
# wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
# rpm -Uvh remi-release-6*.rpm epel-release-6*.rpm

Enabling the Repos

To Enable Repos, @ /etc/yum.repos.d directory,
For REMI REPO, we need to enable latest PHP 7 Version and Core REMI Repo Packages.

# vim remi.repo

And set enabled=1

[remi]
name=Les RPM de remi pour Enterprise Linux 6 - $basearch
#baseurl=http://rpms.famillecollet.com/enterprise/6/remi/$basearch/
mirrorlist=http://rpms.famillecollet.com/enterprise/6/remi/mirror
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
# vim remi-php72.repo

And set enabled=1

[remi-php72]
name=Remi's PHP 7.2 RPM repository for Enterprise Linux 6 - $basearch
#baseurl=http://rpms.remirepo.net/enterprise/6/php72/$basearch/
#mirrorlist=https://rpms.remirepo.net/enterprise/6/php72/httpsmirror
mirrorlist=http://cdn.remirepo.net/enterprise/6/php72/mirror
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi

Installing LAMP Stack && Needed Software Packages

AMP Stack (Apache, Mysql, and PHP)

# yum install php php-devel php-zip php-pdo php-json php-xml php-xmlrpc php-openssl php-gd php-mysql php-mcrypt php-dom php-mbstring httpd httpd-devel mysql mysql-server

Installing Composer and Git

# yum install composer git

PS: You can install Composer manually instead of using yum as following:

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

Setting-Up Process:

1- Adding Laravel User,Download Laravel Framework, Set directory permission

# adduser laravel     
# passwd laravel   
# usermod -a -G apache laravel    # This line to add Laravel User to the Apache User Group
#### Download Laravel and Set Permissions ####
#### To download latest version of Laravel, Use below command to clone master repo of laravel from github. ####
# cd /home/laravel
# git clone https://github.com/laravel/laravel.git
# chmod 755 /home/laravel/laravel
# chown -R laravel.apache /home/laravel/laravel/public && chmod -R 2750 /home/laravel/laravel/public
# chmod -R 777 /home/laravel/laravel/storage

2- VirtualHost Configs

Creating a VirtualHosts with the following configuration for the new laravel user.

Create the file ~ /etc/httpd/conf.d/vhost.conf

# vim /etc/httpd/conf.d/vhost.conf

 

NameVirtualHost *:80

      DocumentRoot /home/laravel/laravel/public
      ServerAdmin laravel@server.com
      ServerName server.com
      ServerAlias *.server.com
      ErrorLog /home/laravel/error_log
      CustomLog /home/laravel/access_log common
<Directory "/home/laravel/laravel/public">
    Options Indexes FollowSymLinks
    AllowOverride All
    Order Allow,Deny
    Allow from All


3- Confiure Mysql for laravel User

Starting MySQL and using it’s CLI to create a Database called “laravel”, then seure your mysql server using mysql_secure_installation and set mysql root password.

  • create laravel user and database.
# service mysqld start
# mysql_secure_installation
# mysql -u root -p
# CREATE USER 'laravel'@'localhost' IDENTIFIED BY '@lara01PW';
# GRANT ALL PRIVILEGES ON laravel.* To 'laravel'@'hostname' IDENTIFIED BY '@lara01PW';
# FLUSH PRIVILEGES;

4– Install Laravel

Using composer as the following, to install all dependencies required for Laravel framework.

# composer install

When we’re ready, we’ll need to adjust DB into Larave’s .env configuration file:

5- Adjusting DB Settings

# mv .env.example .env
# vim .env
### Adjustment DB info in .env file ###

DB_HOST=localhost

DB_DATABASE=laravel

DB_USERNAME=laravel

DB_PASSWORD=@lara01PW

6- set the encryption key

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

# php artisan key:generate		#That will generate the new key to your .env file

7- SeLinux Settings 

If SELinux enabled for your system, running the below command to allow write on storage directory.

# chcon -R -t httpd_sys_rw_content_t /home/laravel/laravel/storage

8- Fix permissions

In case of permissions issue you can make sure of following permissions are sets.

# chown -R laravel.apache /home/laravel/laravel
# chmod -R 755 /home/laravel/laravel
# chmod -R 777 /home/laravel/laravel/storage

 

Starting httpd Service service httpd start and check out your Laravel web application.

Hope That’s Help. Thanks.

Leave a Reply

Exit mobile version