Custom Local Development Domains with Apache on Debian-based Systems

Custom Local Development Domains with Apache on Debian-based Systems

Realm Hacking

7 min read

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 coder/hacker journey, your support would mean a lot. Every bit of magic helps.

Spread the Love

👑 Crown & Share: If you found value in this post, please give it a crown and share it with your fellow coder/hacker 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! 🤴

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

💬 Join our Discord Server: Join the Sudorealm Discord Server connect with fellow enthusiasts and chat about everything that fascinates you! From new blog post suggestions to seeking support on tricky tutorials. Come, share your ideas, and let's grow together! 🚀🌐

Support the Realm

🛍 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.

☕️ Coffee Driven Development: Love what you're reading? Fuel my passion for coding with a delicious cup of coffee! Every sip powers up another line of code and helps bring more exciting content your way. Support my caffeine-fueled coding adventures and let's brew up something amazing together! ☕👨‍💻 Join the journey and BuyMeACoffee

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

Affiliate Links

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

Ready to Forge an Alliance
🤝

Join our alliance and play a pivotal role in the evolution of our digital realm! By aligning with our pricing model, you're not just accessing premium features; you're becoming an integral part of our journey. As an ally, your support propels us forward, ensuring we continue to innovate and thrive.

Lifetime membership

As valued allies, exclusive content awaits you 👀. Unlock a suite of premium features and gain early access to ally-only enhancements in our realm. With our month-by-month commitment, you're always privy to our most coveted updates!

What's included

  • Premium Content Access
  • Ally resources + Unique Ally Badge
  • Access to Affiliate store front 🤑 (🔮)
  • More to come...

It's like buying a pint 🍺. But less!

€1.99 EUR

Forge Alliance

Invoices and receipts available for easy company reimbursement

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.