How to set up Apache Virtual Hosts on CentOS 7



1. Requirements
දැන් ඔයාගේ ලිනක්ස් සර්වර් එකට ලොග් වෙන්න
# ssh root@server_ip
2. Disable selinux , install nano , wget and unzip
# yum install nano
# yum install wget
# yum install unzip
# setenforce 0
# nano /etc/sysconfig/selinux
ඔන්න ඔකේ බලන්න selinux= කියල එකක් ඇති
අන්න එක selinux=disabled ඔන්න ඔහොම කරන්න.
දැන් මේ පහල තියන කමාන්ඩ් එක ගහන්න 
# yum install httpd
දැන් Apache start up එකේදී රන් වෙන්න මේ කමාන්ඩ් ගහන්න.
# systemctl start httpd.service

# systemctl enable httpd.service
4. Configure a virtual host directive for your domain.
ඔන්න ඉතින් අපි සයිට් එකක් හදන්න හදන්නේ. එකට ඉස්සෙල්ලම මේ සයිට් එකේ විස්තර දාගන්න ඕනි ඒකට පොඩි file එකක් හදාගන්න යන්නේ /etc/httpd/conf.d/ කියන පාත් එක ඇතුලේ.
# nano /etc/httpd/conf.d/ඔයාගේ_domain.conf
පහල තියන එක කොපි paste කරන්න එකේ
<VirtualHost *:80>
ServerAdmin webmaster@ඔයාගේ_domain.com
DocumentRoot "/var/www/html/ඔයාගේ_domain/"
ServerName ඔයාගේ_domain.com
ServerAlias www.ඔයාගේ_domain.com
ErrorLog "/var/log/httpd/ඔයාගේ_domain.com-error_log"
CustomLog "/var/log/httpd/ඔයාගේ_domain.com-access_log" combined

<Directory "/var/www/html/ඔයාගේ_domain/">
DirectoryIndex index.html index.php
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

5. Settings explanation

උඩින් තිබ්බ වචන සෙට් එක.
  •  <VirtualHost *:80> – මේකෙන් තමා ඔයාගේ සයිට් එක browse කරන්නේ මේක https නෙමේ http.
  •  ServerAdmin – මේකේ තියන mail එකට තමා email යන්නේ සර්වර් එකේ අවුලක් ආවම.
  •  DocumentRoot – අපේ සයිට් එක හොස්ට් කරලා තියන තැන
  •  ServerAlias – අපේ සයිට් එකේ web url එක
  •  <Directory> and </Directory> and are used to enclose a group of directives that will apply only to the named directory, sub-directories of that directory, and the files within the respective directories. Any directive that is allowed in a directory context may be used. Directory-path is either the full path to a directory or a wild-card string using Unix shell-style matching. In our case we are enabling the FollowSymLinks option which will follow symbolic links in the /var/www/html/your_domain/ directory. We also set the AllowOverridedirective to All which means that any directive which has the .htaccesscontext is allowed in .htaccess files. The Require directive selects which authenticated users can access a resource.
හරි දැන් අපි කන්ෆිග් එක හදාගත්තනේ දැන් බලමු කොහොමද සයිට් එක පබ්ලිෂ් කරගන්නේ කියල.
දැන් සයිට් එක දාන්න folder එකක් හදාගන්න
# mkdir /var/www/html/your_domain/
දැන් ඔයාගේ සයිට් එකට අදාළ file ටික කොපි කරන්න එක ඇතුලට.
දැන් පහල තියනවා වගේ පමිෂන් දෙන්න ඕනි 
# chown apache:apache -R /var/www/html/your_domain/
# chmod -R 755 /var/www/html/your_domain
හරි දැන් /etc/hosts කියන ෆයිල් එක එඩිට් කරලා ip එක දාන්න පහල වගේ
192.168.1.100           www.your_domain.com

දැන් firewall එකෙන් access දෙමු

sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --reload

දැන් අපි ලෝකල් නෙට්වර්ක් එකෙන් බලමු ඕකම අපේ මැෂින් එකෙත් දාන්න ඊටපස්සේ බ්‍රවුස් කරන්න.

දිරියක් වෙන්න අදහස් පෙළක් දාන්න

Post a Comment (0)
Previous Post Next Post