Laravel installation on VPS / Server Centos 6.x

Before laravel installation on Server Centos 6, login in to your server to ensure that all packages are up to date. Run the following command with root user.

 [root@techstriders /]# yum update

This command will ensure that all packages are up to date if not then update those. After update all packages make sure to complete laravel requirement as shown

  • PHP >= 5.5.9
  • OpenSSL PHP Extension
  • PDO PHP Extension
  • Mbstring PHP Extension
  • Tokenizer PHP Extension

By default CentOS may have older packages of PHP version, to check which PHP version is currently active, run the following command.

[root@techstriders /]# php -v
PHP 5.6.14 (cli) (built: Jan 14 2016 05:37:19)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
[root@techstriders /]#

If you have PHP version according to laravel requirement then it’s good to start laravel installation.

Laravel Installation

Start the apache/httpd service

[root@techstriders ~]# service httpd start

Starting httpd:                                            [  OK  ]
[root@techstriders ~]#

And mysqld service

[root@techstriders ]# service mysqld start
Starting mysqld:                                           [  OK  ]
[root@techstriders ]#

In the end, make sure that appache and mysql service should automatically start after server reboot

[root@techstriders /]# chkconfig httpd on

[root@techstriders /]# chkconfig mysqld on

Installing laravel Composer

Laravel use Composer to manage it’s dependency. So if you are going to install laravel, please install Composer first. Composer can be download from https://getcomposer.org/. Run the following command in your VPS CLI

[root@techstriders  /]# curl -sS https://getcomposer.org/installer | php

#!/usr/bin/env php
All settings correct for using Composer
Downloading...

Composer successfully installed to: //composer.phar
Use it: php composer.phar
[root@techstriders  /]#

Now make sure that composer can be access globally move the composer to /usr/local/bin/composer by run the following command.

mv composer.phar /usr/local/bin/composer

After run the following command and check that composer is working fine type composer it will return something like,

[root@techstriders /]# composer
   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer version 1.0-dev (070ee506937170bb81a2e352aa444eaf29f0a2f6) 2016-02-28 14:08:43

Usage:
  command [options] [arguments]

Options:
  -h, --help                     Display this help message
  -q, --quiet                    Do not output any message
  -V, --version                  Display this application version
      --ansi                     Force ANSI output
      --no-ansi                  Disable ANSI output
  -n, --no-interaction           Do not ask any interactive question
      --profile                  Display timing and memory usage information
  -d, --working-dir=WORKING-DIR  If specified, use the given directory as working directory.
  -v|vv|vvv, --verbose           Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  about           Short information about Composer
  archive         Create an archive of this composer package
  browse          Opens the package's repository URL or homepage in your browser.
  clear-cache     Clears composer's internal package cache.
  clearcache      Clears composer's internal package cache.
  config          Set config options
  create-project  Create new project from a package into given directory.
  depends         Shows which packages cause the given package to be installed
  diagnose        Diagnoses the system to identify common errors.
  dump-autoload   Dumps the autoloader
  dumpautoload    Dumps the autoloader
  exec            Execute a vendored binary/script
  global          Allows running commands in the global composer dir ($COMPOSER_HOME).
  help            Displays help for a command
  home            Opens the package's repository URL or homepage in your browser.
  info            Show information about packages
  init            Creates a basic composer.json file in current directory.
  install         Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json.
  licenses        Show information about licenses of dependencies
  list            Lists commands
  prohibits       Shows which packages prevent the given package from being installed
  remove          Removes a package from the require or require-dev
  require         Adds required packages to your composer.json and installs them
  run-script      Run the scripts defined in composer.json.
  search          Search for packages
  self-update     Updates composer.phar to the latest version.
  selfupdate      Updates composer.phar to the latest version.
  show            Show information about packages
  status          Show a list of locally modified packages
  suggests        Show package suggestions
  update          Updates your dependencies to the latest version according to composer.json, and updates the composer.lock file.
  validate        Validates a composer.json and composer.lock
  why             Shows which packages cause the given package to be installed
  why-not         Shows which packages prevent the given package from being installed
[root@techstriders /]#

After complete the installation of composer we need to install laravel installer by running the following command

[root@techstriders /]# composer global require "laravel/installer=~1.1"

Add the `~/.composer/vendor/bin` directory to the PATH. In case to prevent lost if centOS releases an update to the PATH file we will add this to a separate profile file.

Type the following.

echo 'pathmunge ~/.composer/vendor/bin' > /etc/profile.d/laravel.sh
chmod +x /etc/profile.d/laravel.sh

Reload the profile to taking effect.

. /etc/profile

Creating a new project

To create new laravel project just run the following command in CLI

composer create-project laravel/laravel  /path/to/directory/new_project_name

After sometime of loading you will see something like

Application key [df3re7ehefhHU94f92r3ftf565fdsf3f] set successfully.
Application ready! Build something amazing.
[root@techstriders /]#

If you are seeing something like this it’s means Laravel successfully installed on your VPS.
Run the following command in laravel project to change the storage permission.

chmod -R 777 storage/

Now go to installed laravel project directory and take a look on freshed project.

[root@techstriders /]# cd /path/to/new/project/laravel

and type

[root@techstriders laravel]# ls

It will return something like

app      bootstrap      composer.lock  database     package.json  phpunit.xml  readme.md  server.php  tests artisan  composer.json  config         gulpfile.js  phpspec.yml   public       resources  storage     vendor

That’s all folks.

laravel installation

Author: Mujahid Ali

Mujahid Ali is the experience Laravel Developer and Server Administrator at Techstriders. He's managing different projects and doing server related tasks simultaneously.