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
ping sm.webscraping.pro
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: sm.webscraping.pro. 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 https://github.com/xxx/yyy sm.webscraping.pro
Note the last parameter in the git clone line: sm.webscraping.pro
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/sm.webscraping.pro
, it having a Laravel project. Let’s edit the /etc/httpd/conf/httpd.conf
file adding the following:
NameVirtualHost *:80 <VirtualHost *:80> ServerName sm.webscraping.pro DocumentRoot /home/admin/web/sm.webscraping.pro/public_html/public <Directory "/home/admin/web/sm.webscraping.pro/public_html/public"> Options Indexes FollowSymLinks AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost>
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:
/home/admin/web/sm.webscraping.pro/public_html
<IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{REQUEST_URI} !^public RewriteRule ^(.*)$ public/$1 [L] </IfModule>
Grant folder permissions (optional)
You might need Grant folder permission and Set ownership
chown -R apache:apache /home/admin/web/sm.webscraping.pro
Restore Security
restorecon -R /home/admin/web
Disable SELinux
setenforce 0