deployment guide subdomain guide

adding a new project subdomain

complete step-by-step guide for adding a new project subdomain to your existing setup.

prerequisites

step 1: choose your subdomain name

decide on your subdomain name. examples:

use lowercase letters, numbers, and hyphens only. no underscores or special characters.

step 2: add dns a record in hostinger

  1. log in to hostinger
    • go to your hostinger account
    • navigate to dns management for codelabhaven.com
  2. add a record:
    • type: A
    • name: my-new-project (your subdomain name without .codelabhaven.com)
    • points to: 145.223.99.106
    • ttl: automatic (or 14400)
  3. save the dns record
  4. wait for dns propagation (5-30 minutes, sometimes up to 48 hours)

verify dns propagation:

on your local machine:

nslookup my-new-project.codelabhaven.com

on your vps:

nslookup my-new-project.codelabhaven.com

online check:

do not proceed until dns has propagated!

step 3: ssh into your vps

ssh root@145.223.99.106

enter your ssh password when prompted.

step 4: locate your project directory

your project should already be deployed to:

/var/www/html/codelabhaven/projects/your_project_name/

verify the directory exists:

ls -la /var/www/html/codelabhaven/projects/
if your project isn't there yet, deploy it first using your normal deployment process.

step 5: create apache virtual host

replace my-new-project with your actual subdomain name, and your_project_name with your actual project directory name.

cat > /etc/apache2/sites-available/my-new-project.codelabhaven.com.conf < ServerName my-new-project.codelabhaven.com DocumentRoot /var/www/html/codelabhaven/projects/your_project_name Options Indexes FollowSymLinks AllowOverride All Require all granted ErrorLog ${APACHE_LOG_DIR}/my-new-project-error.log CustomLog ${APACHE_LOG_DIR}/my-new-project-access.log combined EOF
replace: my-new-project.codelabhaven.com → your actual subdomain, your_project_name → your actual project directory name (e.g., my_new_project)

step 6: enable the virtual host

a2ensite my-new-project.codelabhaven.com.conf

replace my-new-project.codelabhaven.com.conf with your actual filename.

step 7: test apache configuration

apache2ctl configtest
expected output: Syntax OK

if you see errors, fix them before proceeding.

step 8: restart apache

systemctl restart apache2

step 9: verify virtual host is active

apache2ctl -S

you should see your new virtual host listed in the output.

step 10: test http access

visit in your browser:

http://my-new-project.codelabhaven.com
expected: your project should load (without ssl, so browser will show "not secure")

if you get a 404 error:

step 11: install certbot (if not already installed)

check if certbot is installed:

certbot --version

if not installed:

apt-get update apt-get install -y certbot python3-certbot-apache

step 12: obtain ssl certificate

get ssl certificate for your new subdomain:

certbot --apache -d my-new-project.codelabhaven.com --non-interactive --agree-tos --email matej.resman@gmail.com --redirect

replace:

what this does:

step 13: verify ssl certificate

check certificate status:

certbot certificates

you should see your new subdomain listed.

test https in browser:

visit:

https://my-new-project.codelabhaven.com

expected:

test http redirect:

visit:

http://my-new-project.codelabhaven.com
expected: automatically redirects to https://my-new-project.codelabhaven.com

step 14: update php session cookie domain (if php project)

only needed if your project uses php and sessions.

find php files with session configuration:

common locations:

update session cookie domain:

edit the file(s):

nano /var/www/html/codelabhaven/projects/your_project_name/api/auth.php

find this code:

session_set_cookie_params([ 'lifetime' => 1209600, 'path' => '/', 'domain' => '', // ← This line 'secure' => isset($_SERVER['HTTPS']), 'httponly' => true, 'samesite' => 'Lax' ]);

change to:

session_set_cookie_params([ 'lifetime' => 1209600, 'path' => '/', 'domain' => '.codelabhaven.com', // ← Add leading dot 'secure' => isset($_SERVER['HTTPS']), 'httponly' => true, 'samesite' => 'Lax' ]);

save and exit: ctrl+o, enter, ctrl+x

repeat for all php files that set session cookies.

why the leading dot?

the leading dot (.codelabhaven.com) makes the cookie work across:

without the dot, cookies only work for the exact domain.

step 15: test everything

final checklist:

check apache logs (if issues):

tail -f /var/log/apache2/my-new-project-error.log tail -f /var/log/apache2/my-new-project-access.log

quick reference commands

for future reference, here's the complete command sequence:

# 1. SSH into VPS ssh root@145.223.99.106 # 2. Create virtual host (replace placeholders) cat > /etc/apache2/sites-available/my-new-project.codelabhaven.com.conf < ServerName my-new-project.codelabhaven.com DocumentRoot /var/www/html/codelabhaven/projects/your_project_name Options Indexes FollowSymLinks AllowOverride All Require all granted ErrorLog ${APACHE_LOG_DIR}/my-new-project-error.log CustomLog ${APACHE_LOG_DIR}/my-new-project-access.log combined EOF # 3. Enable site a2ensite my-new-project.codelabhaven.com.conf # 4. Test and restart apache2ctl configtest systemctl restart apache2 # 5. Get SSL certificate certbot --apache -d my-new-project.codelabhaven.com --non-interactive --agree-tos --email matej.resman@gmail.com --redirect # 6. Verify certbot certificates apache2ctl -S

troubleshooting

dns not resolving

problem: nslookup shows no results or wrong ip

solutions:

apache won't start

problem: systemctl restart apache2 fails

solutions:

# Check configuration apache2ctl configtest # Check error log tail -f /var/log/apache2/error.log # Common issues: # - Syntax error in virtual host file # - Port 80 already in use # - Missing directory

404 error on subdomain

problem: subdomain loads but shows 404

solutions:

# Verify DocumentRoot exists ls -la /var/www/html/codelabhaven/projects/your_project_name # Check file permissions chown -R www-data:www-data /var/www/html/codelabhaven/projects/your_project_name chmod -R 755 /var/www/html/codelabhaven/projects/your_project_name # Verify index file exists ls -la /var/www/html/codelabhaven/projects/your_project_name/index.html # or ls -la /var/www/html/codelabhaven/projects/your_project_name/index.php

ssl certificate failed

problem: certbot fails to obtain certificate

solutions:

sessions not working (php)

problem: login doesn't persist or sessions reset

solutions:

certificate expired

problem: browser shows certificate error

solutions:

# Check certificate expiration certbot certificates # Manually renew certbot renew # Reload Apache systemctl reload apache2

certbot should auto-renew, but you can check the timer:

systemctl status certbot.timer

summary

after completing these steps, your new project will be:

time required: ~15-30 minutes (mostly waiting for dns propagation)
you're done! 🎉