Skip to content

Mohcin Bounouara

Thoughts about software engineering and life

Use site.local Instead of localhost/mysite on apache without using docker or DDEV

Let’s suppose you’re using Apache on your local machine and you want to visit your PHP project using something like http://site.local instead of http://localhost/mysite.

You’re not using Docker, DDEV, or any container tools, just plain XAMPP or Apache on Linux.

Here’s how to set it up:

Map your custom domain locall

Edit your /etc/hosts file:

sudo nano /etc/hosts
#And add
127.0.0.1    site.local

Set up a virtualHost

Edit Apache’s virtual hosts config:

sudo nano /opt/lampp/etc/extra/httpd-vhosts.conf
#And add
<VirtualHost *:80>
    ServerName site.local
    DocumentRoot "/opt/lampp/htdocs/mysite"

    <Directory "/opt/lampp/htdocs/mysite">
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Make sure this file is included in Apache. In /opt/lampp/etc/httpd.conf, ensure this line is uncommented:

#This one
Include etc/extra/httpd-vhosts.conf

Don’t forget to restart your apache,

#using this command: 
sudo /opt/lampp/lampp restart

That’s it! Now you can access your local project via http://site.local like a real domain without Docker, without DDEV, and without container complexity.

Keep improving!