Bhaveshpp

Professional Magento Developr - Healp eachother to grow

Apache2: Create virtualhost on local linux

03 Jun 2021 » server, apache2

Start with creating directory /var/www/magento241.local/public_html local machin


sudo mkdir -p /var/www/magento241.local/public_html

Change Ownsership and permission


sudo chown -R $USER:$USER /var/www/magento241.local/public_html
sudo chmod -R 777 /var/www/magento241.local/public_html

Copy default apache2 conf for generate config file


sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/magento241.local.conf

Edit Config file use ^+k to delete line in nano


sudo nano /etc/apache2/sites-available/magento241.local.conf

Use config Like


<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/magento241.local/public_html/pub
        ServerName magento241.local
        ServerAlias www.magento241.local
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Enable Site


sudo a2ensite magento241.local.conf

Restart Apache2


sudo systemctl reload apache2

Add Site url in host file


sudo nano /etc/hosts

Add site url like this


100.107.130.234 apstudio.ddns

127.0.0.1 bhaveshpp.com

192.168.0.100 homeserver

192.168.0.100 magento241.local

Thank you.