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. The Laravel framework is also very easy to install and deploy. In this tutorial we will learn to install Laravel framework on a CentOS 7.x server.
Laravel does not need any special hardware. All the required dependencies will be installed throughout the tutorial. You will only need root or sudo access on your server. If you are logged in as non root user, run sudo -i to switch to root user or you can also use sudo command before all administrative commands.
Before installing any package on your system, it is recommended to update the system and the packages. Run the following command to do so.
yum -y update
Now you will need to add the EPEL repository into your server as the EPEL repository has the most update packages of the dependecies required.
yum -y install epel-release
yum -y update
yum clean all
Now we will need to install the LAMP stack so that we can serve the Laravel web application. Install the required package for Apache and MariaDB, which is a fork of MySQL using the following command.
yum -y install httpd mariadb-server mariadb
Laravel does not supports PHP versions lower than 5.6.4, hence you will have to install a PHP version higher than 5.6.4 or you can also install PHP 7. PHP 5.6 or PHP 7 is not included in the default YUM repository, hence you will need to add Webtatic repository in your system. Run the following command to do so.
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum -y update
yum clean all
Now you can install either PHP 5.6 or PHP 7.0 in your system. To install PHP 5.6 and all the required PHP modules, run the following command.
Make sure that your PHP version is not older than 5.6.4. Now start the Apache web server and enable it to start at boot time using following command.
systemctl start httpd
systemctl enable httpd
To start MariaDB and enable it to start at boot time using the following command.
systemctl start mariadb
systemctl enable mariadb
Now run the following command to harden your MySQL or MariaDB installation.
It will run a small script which will ask you to set a root password for your MariaDB installation. Most of the questions are self explanatory and you should answer yes for all the questions. The output of the command will look like the one shown below.
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
Remove anonymous users? [Y/n] y
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
- Dropping test database...
- Removing privileges on test database...
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
Now we will need to install Composer as Composer will help with the installation of the dependencies required by Laravel. Run the following command to download and install Composer in your system.
curl -sS https://getcomposer.org/installer | php
You will see following output.
[root@ip-172-31-28-226 ~]# curl -sS https://getcomposer.org/installer | php
All settings correct for using Composer
Composer successfully installed to: /root/composer.phar
Use it: php composer.phar
Now run the following command to make composer available gobelally.
Run the following command to check if composer is installed and working correctly.
You should see following output.
[root@ip-172-31-28-226 ~]# composer -V
Composer version 1.2.1 2016-09-12 11:27:19
Now we have everything configured, we can install Laravel. The latest version of Laravel is available through the GIT repository. Run the following commands to install GIT and then switch to Apache web root directory and clone the Laravel repository in your system.
yum -y install git
git clone https://github.com/laravel/laravel.git
Now navigate to Laravel files directory and use composer to install the dependencies and software.
Composer will take some time to install the dependencies. 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.
The next thing we should do after installing the framework is to set the application key to a random string. It is important to set a random application key otherwise the user sessions and encrypted data will not be secured. Before generating the key it is necessary to rename .env.example file to .env file. Run the following command to do so.
mv .env.example .env
Once you have .env file ready, you can generate the new application key using the following command.
php artisan key:generate
You will see a output similar to shown below.
[root@ip-172-31-28-226 laravel]# php artisan key:generate
Application key [base64:PllGKlCqZSwTJKGyGacEN8FEJeEt0Jlyx1n8xMea3Iw=] set successfully.
The above command will generate the random application key as well as it will write the key into environment file .env. You can verify if the key has been set using the following command.
As you can see in the above output we have a value set for APP_KEY, this means that the application key for our Laravel framework is set.
Now create a new Apache virtual host file so that our application can be accessed through the web browser. Edit the /etc/httpd/conf/httpd.conf file using your favorite editor. In this tutorial we will be using nano editor, if you do not have nano installed, you can run yum -y install nano to install nano editor.
Now scroll down to the bottom of the file and paste these lines.
You can create an email email filters through your cPanel control panel which is where you manage your hosting account. Email filters can be set up to target specific word, subject, from or to. Emails that are filtered out can be sent to a different email, deleted, delivered to a...
If you find your cPanel disk space filling up, or an email address has hit its disk space quota, cPanel has a helpful built in Email Disk Usage tool. This will provide you with a simple to understand breakdown of how much disk space each folder for a particular email...
Although WHM will normally automatically keep itself up to date, you may want to manually check for server updates / push through an update that is pending, or it may be that you have automatic updates switched off on your cPanel server. In this guide we will show you how...