Subdomain at Centos 7 with Laravel project

This post is devoted to the steps of how to create subdomain (Centos 7 and Vesta CP) and map a [Laravel] project folder to it.

Ping subdomain


Restart httpd service after each change in httpd.conf

It takes sudo privileges.

service httpd restart

Note: it may take up to 24 hours for the registrar to spread all over.

Using Vesta CP

Inside Vesta CP we perform two things:

1) Create new subdomain

2) Set DNS records for it

Just added a new DNS: All the settings were put in automatically.

Placing a project into the web folder of Centos machine

After creating a new domain we move to the web folder where we clone the project into (takes sudo permissions):

cd /home/admin/web
git clone

Note the last parameter in the git clone line: It means that we clone the project into the folder with this name.

Map up the folder to the subdomain

We now have a folder named /home/admin/web/, it having a Laravel project. Let’s edit the /etc/httpd/conf/httpd.conf file adding the following:

NameVirtualHost *:80

<VirtualHost *:80>
  DocumentRoot /home/admin/web/
  <Directory "/home/admin/web/"> 
    Options Indexes FollowSymLinks 
    AllowOverride All 
    Order allow,deny 
    Allow from all 

Note that we’ve mapped a virtual host to the project folder public since the Laravel starts off from index.php, it being in this folder.

Restart httpd service after the change: service httpd restart

Access rules

Add a .htacces file into the project root folder:


<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_URI} !^public
    RewriteRule ^(.*)$ public/$1 [L]

Grant folder permissions (optional)

You might need Grant folder permission and Set ownership

chown -R apache:apache /home/admin/web/

Restore Security

restorecon -R /home/admin/web

Disable SELinux

setenforce 0

Apache docs for vhosts


Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.