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
Also update your .htaccess file to have simple rewrite module:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
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!