How to Setup Project Based PHP with HTTPS in Linux

Blue bird standing in the branch

Background

If you're used to using Laragon on Windows, you've probably been spoiled by its auto virtual host feature. It allows you to access your projects using a custom domain instead of typing localhost/project_name. For example, if you have a project named "akubagi", and you place its directory inside Laragon’s web root, Laragon will automatically create a virtual host with the address "akubagi.test".

Everything feels so easy. Accessing your app through the browser is literally just that simple. Laragon really spoils us. It makes things so convenient that you can’t help but fall in love with it. But sometimes, Windows itself becomes the problem—slow, bloated, and frustrating to deal with. There’s always some kind of drama.

That’s actually what pushed me to switch to Linux. Luckily, I came from macOS, so I wasn’t completely clueless—both systems are Unix-based after all.

When I switched jobs, my new workplace required us to run apps the way Laragon does—by setting up virtual hosts, even with SSL, so it feels like we’re accessing a real website

For example, akubagi.test had to be accessible as https://akubagi.test.

It was all a bit confusing for me, especially since I’d been spoiled by Laragon. How do you even set that up manually, like Laragon does automatically? After some trial and error, I finally found the right setup that works.

Prerequisites 

Everything you need is actually super simple. You only need:

  • PHP
  • Apache
  • Mkcert

I won’t go into the installation process here, but as long as you can get phpinfo(); to show up in your browser, that means everything is set up correctly. Apache2 acts as the web server, and mkcert is used to generate local SSL certificates—so you don’t have to deal with the hassle of using OpenSSL manually.

Step by Step

First of all, I’m gonna assume you’ve already set up your own web root. In my case, I use /var/www—makes things easier, especially since that’s how it’s done on our office server. Next, you can clone your favorite project and move it into /var/www. You’ll probably need permission for that, so make sure to use sudo when moving the files. I’m just gonna assume you already know the drill when it comes to stuff like this.

Then you can set the ownership and moderation like this

Next, you can create your virtual host configuration like this:

And here’s the content of the virtual host file—you can adjust the paths as needed, just make sure to be careful and double-check everything.

Once that’s done, you can generate the SSL certificate. Make sure the path matches whatever you declared in your virtual host file. As for me, I usually keep all my certs in ~/Projects/certs, so I can collect all certificates from my various projects in one place. I just don’t feel like initializing them in each project’s root directory—it’s kinda annoying, hahaha.

Generate certificate is simple, just use  command mkcert your-project.test

And then you must add one line below your /etc/hosts file like 127.0.0.1 your-site.test

After that, you need to enable the module and activate the site from the virtual host you just created using the commands below:

Now, here comes the permission part—again. 

Why permissions again?

Because without fixing this, you won’t be able to open or edit your code properly in VSCode.
So, what we’re gonna do here is use ACL to give your Linux user the right permissions, so you can edit your code freely without running into those annoying permission issues.
Here’s how to do it:

Me and "Evaluasi".

Bashkara "Hindia"

When I was in college, there was one of my best friends named Fauzan. He introduced me to a band called ".feast". Honestly, the music wasn't really my cup of tea. But I tried to accept it, just to add to my musical knowledge. I think the music is weird. Bashkara's voice is also not good. But lyrically, it's a bit of a touch. 

Moreover, .feast has made a statement that I think is very controversial. He said, "Our song, "Peradaban", is much louder than any metal song we've ever heard, it's furious to the point of numbness.". 

Feast Peradaban
.feast and images for the promotion of their single, "Peradaban".  At first glance, it looks like a painting of Jesus at the Last Supper

As someone who listened to metal songs from elementary school to college, I think this statement is ridiculous. Many are also furious with this .feast statement

In fact, this topic has exploded. Until it was discussed by the mainstream music media like Hai! Magazine and until the .feast apologized to music lovers. Indeed,  Bashkara is rather annoying when expressing his opinion. I think .feast deserves it all.

Long story short, .feast disbanded and Bashkara embarked on a solo career. I had also graduated from college and was already working in Jakarta. 

I have a best friend from kindergarten. His name is Fajar. He also really enjoys listening to Bashkara, maybe like Fauzan who I mentioned at the beginning of this post. I said, "Damn, why do people love bashkara?"

The problem is that when he first made that statement, I already had an "Ilang Feeling". So, when fajar tried to introduce Bashkara to me, I was not too interested in him. 

Until I finally stepped into the world of work and there were so many problems, especially from family, I tried listening to Bashkara's song title "Secukupnya". The most famous song of Bashkara. 

Oh yes, Bashkara finally used the stage name "Hindia". He said that it came from looking at Raden Saleh's painting and the words "Hindia Belanda".

When I listened to the song, I started thinking "How come the song really related with my adult life". And then, as usual, I tried to explore his songs, and I found a song called "Evaluasi".

And when I tried to listen to it and I absorbed the lyrics. Damn! It was so deep. Here I began to understand why Fajar and Fauzan liked Hindia so much.

I really enjoy listening to music from a musician but the live performance version, because I think it's more raw than the studio version that has been polished here and there. So, I want you to hear the live version of the Evaluasi by Hindia


Now, let's try to analyze the lyrics one by one. I want to interpret these lyrics based on my point of view. Let's take a look at the first paragraph

Yang tak bisa terobati, biarlah mengering sendiri. Menghias tubuh

 From this piece of lyrics, Bashkara tries to say that the wounds we have experienced, both physical wounds and mental wounds that are not yet finished, in the end we have to make peace with all these wounds and let them become part of our lives that decorate out body and minds.

Then we try to move on to the next lyric 

Dan yang mengevaluasi, ragamu. Hanya kau sendiri, mereka tak mampu melewati yang telah kau lewati tiap berganti hari. Rintangan yang kau hadapi.

 From here it is very clear that this point emphasizes that everything that happens has indeed been arranged by God. So, whatever things happen to us, basically it is because God knows we are able to get through it all. No one in the world plays a role in your life scenario as well as you do.

Masalah yang mengeruh. Perasaan yang rapuh. Ini belum separuhnya. Biasa saja, kamu tak apa.

At this point, Bashkara wants to convey the message that no matter how hard the problem is, no matter how frantic you feel, this is nothing. Because throughout life, there will always be problems waiting ahead. So, take it easy. You'll be fine. 

And I probably won't explain all the meanings of the lyrics. But there's one stanza that I think feels very personal to me 

Bilas muka, gosok gigi, evaluasi. Tidur sejenak menemui esok pagi. Walau pedih ku bersamamu kali ini. Ku masih ingin melihatmu esok hari.

I remember the moment I cried on the motorcycle when I heard these lyrics in the afternoon when I got home from work. "Bilas muka (wash your face), Gosok gigi (brush your teeth), Evaluasi (evaluation)". It is the routine of most people working in metropolitan areas when they come home from work.

I also do this routine, but for the "evaluation" part, I honestly rarely do it. Evaluation requires us to look at the events that happened today. Be grateful for what we have done well and try to improve tomorrow whatever is lacking from today.

These lyrics teach me to always be grateful for whatever happens to me today. 

"Tidur sejenak menemui esok pagi (Take a short nap to meet tomorrow morning)" - Again, the lyrics are very relate to me. I commute every day from home to office, office to home with a distance of more than 100km and that's all on a motorcycle. It feels very tired. But what can I do? This is the way and there is no other alternative.

I spend a lot of time on the road. Getting enough rest and sleep is a luxury for me. Imagine going to bed and waking up to suddenly be faced with going to work again. I've been doing this routine for the past year.

Especially when you have a problem that you have to face the next day. It feels very upset, but Bashkara tries  to say "let's sleep first, the things that exist tomorrow, just leave it to yourself tomorrow"

 Walau pedih ku bersamamu kali ini. Ku masih ingin melihatmu esok hari. (Although it hurts me to be with you this time. I still want to see, tomorrow) - Again, the lyrics really hit home with me. I often feel that everything is hopeless and it's better for me to just "end" my life in this world. 

But after everything that's happened, it feels like life is like this. There are always wounds, there are always problems. There's joy and there's sadness. Something that can't be avoided.

When we see life from a beautiful frame, the world will look like a beautiful place too. At first, we may not want to live here anymore, but as our perspective changes, we even wait to see tomorrow.

Thank you, Bashkara for the song. It makes me evaluate myself every day.