Custom Local Development Domains with Apache on Debian-based Systems

Custom Local Development Domains with Apache on Debian-based Systems

Realm Hacking

I recently took a leap into the vast expanse of Linux, specifically choosing Parrot OS for my coding endeavors in security and web app development. The journey, to be honest, hasn’t exactly been a breeze. But, oddly enough, I've found the challenges invigorating. Every hiccup and every roadblock has been an opportunity to dive deeper, understand the intricacies of the OS, and ultimately grow as a coder. This constant learning and tinkering is, after all, the essence of what makes a simple coder like me a better hacker!

In this continuous voyage of discovery, one area that stood out as crucial, especially for those involved in web app development, is the setting up of custom local development domains. These domains not only streamline the development process but also mirror real-world scenarios, helping coders to better emulate and understand the deployment environment. In this guide, I'll walk you through how to set up these custom domains using Apache on Debian-based systems, drawing from my recent adventures with Parrot OS.

What is a Local Domain?

Picture the vast Star Wars galaxy. Each planet, like Tatooine or Hoth, has a unique name so that pilots and navigators know where to go. Now, imagine your computer as a mini-galaxy. In this mini-galaxy, instead of planets, you have websites.

A local domain is like naming one of those websites with a Star Wars planet name. Instead of visiting "127.0.0.1/tatooine," you'd visit "tatooine.local" or "tatooine.test" on your browser, and it would take you to a website you're working on, right on your computer.

It's just a way to make navigation easier and more fun in your mini-galaxy of projects!

Why did I use it for?

Well, in Laravel development you are advised to run php artisan serve when you want to start developing your project, then you navigate to 127.0.0.1:8000 and there it is your precious little project. First of all, I hate running an extra command just to run a website... That's it really... I despise this extra step. Local domains solve that problem of mine so... here we are.

ε½³1. Hosts File

The hosts file in Linux systems is a text file that maps hostnames to IP addresses, allowing computers to manually override DNS resolution for specific addresses. It's often used for local testing, development, or blocking certain websites. Located at /etc/hosts, users can add custom associations between hostnames and IP addresses, but caution is advised to prevent connectivity issues. Open the hosts file with sudo nano /etc/hosts and at the end of the hosts file add the desired name of your project:

127.0.0.1    sudorealm.test

this configuration maps the domain sudorealm.test to your local machine (127.0.0.1).

ε½³2. Set up Apache configuration

cd /etc/apache2/sites-available/

Create a new configuration file for the project

sudo nano sudorealm.conf
<VirtualHost *:80>
    ServerName sudorealm.test
    DocumentRoot /path/to/your/whatever/project/public

    <Directory /path/to/your/whatever/project/public>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

My project files are under the Code directory and I navigate to it with ~/Code/sudorealm/ but please keep in mind that the ~ is a shorthand for a user's home directory. In configuration files, especially server configurations like Apache's, it's best to use the absolute path. This is because the server might not understand or resolve the ~ shorthand in the same way a shell would. Apache doesn't interpret ~ as the home directory, so using it might lead to configuration errors.

And just to be clear, I tried it and it didn't work. πŸ˜„

πŸ’Ύ Save and close the file Press CTRL + X to save then press Y to exit (in nano).

Enable the new configuration

sudo a2ensite sudorealm.conf

Ensure the mod_rewrite module is enabled

sudo a2enmod rewrite

Restart Apache

sudo systemctl restart apache2

Now if you've updated your /etc/hosts/ file appropriately and as mentioned, you should be able to access http://sudorealm.test in your browser.

Possible step: βΌ» No Permissions, Forbidden!

There are some times where you come across this pesky message while working on your local setup:

Forbidden
You don't have permission to access this resource.

Apache/2.4.56 (Debian) Server at sudorealm.test Port 80

No need for panic! πŸš€ This usually indicates a permission issue. Here's a quick solution:

  • Assign Proper Ownership: Make sure your project and its sub-files are in the good hands of the web server user, which is commonly www-data on Debian-flavored systems.
sudo chown -R www-data:www-data /path/to/your/project/public
  • Set Read and Execute Permissions: It's equally important for the Apache user to have the right to read your Laravel project files and stroll through its directories.
sudo chown -R yourusername:www-data /home/yourusername/Code/projectFolder
sudo chmod -R 775 /home/yourusername/Code/projectFolder
  • Give Apache a Gentle Nudge: Lastly, remember to refresh Apache's memory to ensure it's up-to-date with these changes.

Possible step: βΌ» Wrong php version on Composer!

Since I am using Laravel I got the following message:

Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.1.0"

If you face this, even after confirming the correct PHP version using the php -v command, it means that Apache is still referencing the outdated PHP version. But not to worry, this can be easily rectified! Here's a step-by-step to align Apache with the desired PHP version:

sudo a2dismod php7.4
sudo a2enmod php8.1
sudo service apache2 restart

With these commands, Apache is set to use PHP 8.1, ensuring smoother development experiences with php8.1.

😎 Hacking story.

The Stage: Marla, our InstaGlam diva, was living her best online life. Filters, fans, and fabulousness – she had it all.

The Sneaky Deed: Enter Tyler, Marla's geek-chic BF wasn't just about the geek life for fun; he had skills. Flexing his Apache muscles, he meticulously crafted a twin InstaGlam site on his own server – every button, every shade, and every pixel echoed the real deal. When Marla was distracted, probably picking out her next killer filter, our man Tyler sneakily altered her hosts file. A few lines of code later, any time Marla tried to hit up InstaGlam, she'd land on Tyler's lookalike. The stage was set, the bait was in place, and Marla, none the wiser, waltzed right into Tyler's digital mirage.

The Twist: But Tyler's game had a bigger play. Instead of playing dirty, he went legit. With Marla's thumbs-up, he showcased the 'InstaGlam Swap' in webinars, selling cybersecurity tips and tricks. The cash? Oh, it flowed in, making Tyler the new cyber-rockstar. Marla? Oh, she will be way more careful. Especially now that she has felt how simple is to be hacked if you don't care about the little details.

πŸš€ Spread the Love & Support the Realm

Hey there, fellow Realmer! If this guide illuminated a new path in your Linux/hacker journey, your support would mean a lot. Every bit of magic helps

πŸ‘‘ Crown & Share: If you found value in this post, please give it a crown and share it with your fellow code enthusiasts. Spreading knowledge is what Sudorealm is all about! Fun fact the Author with the most crowns inside a realm will be crowned as the Realm King! 🀴

πŸ› Affiliate Treasures Below: Dive into the depths below the post to uncover some affiliate products I've curated just for you. It's a great way to support the realm and discover some nerdy treasures.

🐦 Twitter/X Shoutout: Feeling extra grateful or have some cool feedback? Drop me a shoutout on Twitter – I'd love to hear from you!

β˜•οΈ Coffee Driven Development: Enjoyed the content? Help keep my coding sessions energized with a cuppa! BuyMeACoffee

Thanks for being a part of our realm. Every bit of support propels our community to new horizons. Until next time, keep exploring!

I am @d3ad R1nger, Creator of Sudorealm, thank you for reading.

Affiliate Links

Check out what d3ad R1nger suggests for Custom Local Development Domains with Apache on Debian-based Systems!

  • Tuqiso Programming Stickers for Developers, Coders, Programmers, Hackers, Geeks, and Engineers,Developper Stickers for Laptop affiliate image
    Coding

    Tuqiso Programming Stickers for Developers, Coders, Programmers, Hackers, Geeks, and Engineers,Developper Stickers for Laptop

  • Alfa AWUSO36NH High Gain USB Wireless G / N Long-Rang WiFi Network Adapter affiliate image
    Hacking Gear

    Alfa AWUSO36NH High Gain USB Wireless G / N Long-Rang WiFi Network Adapter

    https://geni.us/eHIjaOy Alfa AWUS036NH 2000mW 2W 802.11g/n High Gain USB Wireless G/N Long-Range WiFi Network Adapter with 5dBi Screw-On Swivel Rubber Antenna and 7dBi Panel Antenna and Suction Cup/Clip Window Mount: Alfa

Subscribe to our newsletter.

πŸ‘‹ Hey there, Realmer! Fancy getting a byte of nerdy knowledge straight to your inbox? Subscribe to our Sudorealm newsletter and don't miss a single trick from our growing community of curious minds! Ready to level up your knowledge game? Join us in the Realm today!

Be one of the privileged few
Think of it as your VIP pass into the Realm where you'll get first dibs on new features, insider updates, and more.
No spam
And, worry not, we promise not to spam – just top-tier, brain-tickling content.