Installing CentOS 7, Configuring Virtual Hosts and install Laravel 5 on each host

Download CentOS 7 ISO file mount it and create a VM in Virtualbox and boot

Select the following:

  • Simple webserver
  • PHP

yum install php-common

Open Firewall for Apache and register as service

firewall-cmd –permanent –add-service=http

firewall-cmd –reload

sudo systemctl enable httpd

Install MariaDB and register as service

Check if installed

rpm -qa | grep mariadb

yum install mariadb-server

sudo systemctl enable mariadb.service

mysql

> grant all on *.* to ‘sgalea’@’%’ identified by ‘bitnami’ with grant option;

quit

 

sudo vi /etc/my.cnf

[mysqld]

skip-grant-tables

 

Enable External connections to the database

firewall-cmd –permanent –add-service=mysql

firewall-cmd –reload

 

yum -y install php-mysql

 

Install SFTP and enable as service

yum -y update

yum -y install vsftpd

Conf location: /etc/vsftpd/vsftpd.conf

sudo systemctl enable vsftpd

firewall-cmd –permanent –add-port=21/tcp

firewall-cmd –reload

 

Creating Virtual Hosts Settings

mkdir /etc/httpd/sites-available

mkdir /etc/httpd/sites-enabled

sudo vi /etc/httpd/conf/httpd.conf

Put the following at the end of file

IncludeOptional sites-enabled/*.conf

Esc :wq

Create a file per virtual host in /etc/httpd/sites-available

sudo vi /etc/httpd/sites-available/dev1.local.conf

<VirtualHost *:80>
ServerName  dev1.local
ServerAlias dev1.local
DocumentRoot /var/www/dev1.local/laravel/public
ErrorLog /var/www/dev1.local/logs/error.log
CustomLog /var/www/dev1.local/logs/requests.log combined
</VirtualHost>

sudo vi /etc/httpd/sites-available/dev2.local.conf

<VirtualHost *:80>
ServerName  dev2.local
ServerAlias dev2.local
DocumentRoot /var/www/dev2.local/laravel/public
ErrorLog /var/www/dev2.local/logs/error.log
CustomLog /var/www/dev2.local/logs/requests.log combined
</VirtualHost>

sudo vi /etc/httpd/sites-available/dev3.local.conf

<VirtualHost *:80>
ServerName  dev3.local
ServerAlias dev3.local
DocumentRoot /var/www/dev3.local/laravel/public
ErrorLog /var/www/dev3.local/logs/error.log
CustomLog /var/www/dev3.local/logs/requests.log combined
</VirtualHost>

https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-centos-7

Enabling the hosts

sudo ln -s /etc/httpd/sites-available/dev1.local.conf /etc/httpd/sites-enabled/dev1.local.conf
sudo ln -s /etc/httpd/sites-available/dev2.local.conf /etc/httpd/sites-enabled/dev2.local.conf
sudo ln -s /etc/httpd/sites-available/dev3.local.conf /etc/httpd/sites-enabled/dev3.local.conf

Create folders

mkdir /var/www/dev1.local

mkdir /var/www/dev2.local

mkdir /var/www/dev3.local

sudo chmod -R 775 /var/www

Install Composer Globally

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

Install Laravel Dependencies

ext-mbstring
sudo yum install php-mbstring

ext-mcrypt

wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm

rpm -ivh epel-release-7-5.noarch.rpm

yum install php-mcrypt*

Install Laravel

navigate to the folder where one wishes to install it in my case

cd /var/www/dev1.local
composer create-project laravel/laravel –prefer-dist

cd /var/www/dev2.local
composer create-project laravel/laravel –prefer-dist

cd /var/www/dev3.local
composer create-project laravel/laravel –prefer-dist

 

Storage Folder needs write permissions in SELinux

su -c "chcon -R -h -t httpd_sys_script_rw_t /var/www/dev1.local/laravel/storage/"

su -c "chcon -R -h -t httpd_sys_script_rw_t /var/www/dev2.local/laravel/storage/"

su -c "chcon -R -h -t httpd_sys_script_rw_t /var/www/dev3.local/laravel/storage/"

chmod -R 777 /var/www/dev1.local/laravel/storage/

chmod -R 777 /var/www/dev2.local/laravel/storage/

chmod -R 777 /var/www/dev3.local/laravel/storage/

  • Not sure if 777 is a good idea here

We need a location for logs

mkdir /var/www/dev1.local/logs

su -c "chcon -R -h -t httpd_sys_script_rw_t /var/www/dev1.local/logs/"

mkdir /var/www/dev2.local/logs

su -c "chcon -R -h -t httpd_sys_script_rw_t /var/www/dev2.local/logs/"

mkdir /var/www/dev3.local/logs

su -c "chcon -R -h -t httpd_sys_script_rw_t /var/www/dev3.local/logs/"

 

sudo systemctl restart httpd.service

Check virtualhosts

httpd -S

Add virtual hosts in host file on your host OS

On windows: C:\Windows\System32\drivers\etc

edit host file as Administrator

192.168.101.12 dev1.local
192.168.101.12 dev2.local
192.168.101.12 dev3.local

Where 192.168.101.12 is the IP of your Virtual Machine running CentOS 7

Remove index.php from the url

sudo vi /etc/httpd/conf/httpd.conf

AllowOverride Access
AllowOverride Access

Change to:

AllowOverride All

 

Things required while debugging issues:

While debugging try without SELinux

Disable:

setenforce 0

Enable:

setenforce 1

These are not permanent they will be reset to default status after reboot.

Search string in file

grep -R ‘string’ dir/

Find IP

ip addr

Changing IP of the VM

sudo dhclient -r

sudo dhclient

__________________________________________________________________

http://stackoverflow.com/questions/17954625/services-json-failed-to-open-stream-permission-denied-in-laravel-4

Errorlogs location causes htttpd not reload

http://unix.stackexchange.com/questions/175558/apache-wont-restart-after-adding-virtualhost-conf-file-why-not

Blankscreen issue

http://stackoverflow.com/questions/20678360/laravel-blank-white-screen

ServerSetup

http://www.hexblot.com/blog/centos-7-server-installation

 

Next Post is about creating a REST API on Laravel 5 which can be found here

Please like & share:

Leave a Reply