
Apache Virtual Hosts on CentOS 7
This is a short guide for creating to virtual hosts on Apache with CentOS 7. For detailed description, see source at the bottom. Use sudo in front of the commands if your not root.
Create folders
mkdir -p /var/www/<span class="highlight">example.com</span>/public_html
mkdir -p /var/www/<span class="highlight">example2.com</span>/public_htmlGive users permission to the folders
chown -R $USER:$USER /var/www/<span class="highlight">example.com</span>/public_html
chown -R $USER:$USER /var/www/<span class="highlight">example2.com</span>/public_htmlModify permissions to www-root
chmod -R 755 /var/wwwCreate a index.php file with some content on the web-folders we created.
Create virtual host files
mkdir /etc/httpd/sites-available
mkdir /etc/httpd/sites-enabledvi /etc/httpd/conf/httpd.confAdd this line at the bottom:
IncludeOptional sites-enabled/*.confAdd the virtual host config
Open config file
vi /etc/httpd/sites-available/<span class="highlight">example.com</span>.confAdd this to the config-file
<VirtualHost *:80>
ServerName <span class="highlight">www.example.com</span>
ServerAlias <span class="highlight">example.com</span>
DocumentRoot /var/www/<span class="highlight">example.com</span>/public_html
ErrorLog /var/www/<span class="highlight">example.com</span>/error.log
CustomLog /var/www/<span class="highlight">example.com</span>/requests.log combined
</VirtualHost>Remember to create conf file for example2.com domain if you want to add two virtual hosts.
Create symbolic link in sites-enabled
Enable the virtual host by creating a symbolic link for each host in sites-enabled directory.
ln -s /etc/httpd/sites-available/<span class="highlight">example.com</span>.conf /etc/httpd/sites-enabled/<span class="highlight">example.com</span>.conf
ln -s /etc/httpd/sites-available/<span class="highlight">example2.com</span>.conf /etc/httpd/sites-enabled/<span class="highlight">example2.com</span>.conf
Kommentarer
Laster kommentarer …