complete step-by-step guide for adding a new project subdomain to your existing setup.
145.223.99.106codelabhaven.comdecide on your subdomain name. examples:
my-new-project.codelabhaven.comapp-name.codelabhaven.comtool-name.codelabhaven.comcodelabhaven.comAmy-new-project (your subdomain name without .codelabhaven.com)145.223.99.106on your local machine:
nslookup my-new-project.codelabhaven.com
on your vps:
nslookup my-new-project.codelabhaven.com
online check:
my-new-project.codelabhaven.comA record145.223.99.106 globallyssh root@145.223.99.106
enter your ssh password when prompted.
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/
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
my-new-project.codelabhaven.com → your actual subdomain, your_project_name → your actual project directory name (e.g., my_new_project)a2ensite my-new-project.codelabhaven.com.conf
replace my-new-project.codelabhaven.com.conf with your actual filename.
apache2ctl configtest
Syntax OKif you see errors, fix them before proceeding.
systemctl restart apache2
apache2ctl -S
you should see your new virtual host listed in the output.
visit in your browser:
http://my-new-project.codelabhaven.com
if you get a 404 error:
ls -la /var/www/html/codelabhaven/projects/your_project_namecheck if certbot is installed:
certbot --version
if not installed:
apt-get update
apt-get install -y certbot python3-certbot-apache
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:
my-new-project.codelabhaven.com → your actual subdomainmatej.resman@gmail.com → your email addresswhat this does:
check certificate status:
certbot certificates
you should see your new subdomain listed.
test https in browser:
visit:
https://my-new-project.codelabhaven.com
expected:
https:// (not http://)test http redirect:
visit:
http://my-new-project.codelabhaven.com
https://my-new-project.codelabhaven.comfind php files with session configuration:
common locations:
api/auth.phpapi/config.phpincludes/session.phpsession_set_cookie_params()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:
codelabhaven.commy-new-project.codelabhaven.commovie-night.codelabhaven.comwithout the dot, cookies only work for the exact domain.
final checklist:
nslookup my-new-project.codelabhaven.comhttp://my-new-project.codelabhaven.comhttps://my-new-project.codelabhaven.comcheck apache logs (if issues):
tail -f /var/log/apache2/my-new-project-error.log
tail -f /var/log/apache2/my-new-project-access.log
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
problem: nslookup shows no results or wrong ip
solutions:
145.223.99.106problem: 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
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
problem: certbot fails to obtain certificate
solutions:
systemctl status apache2apache2ctl -Sufw status
# If needed:
ufw allow 80/tcp
ufw allow 443/tcp
tail -f /var/log/apache2/error.logproblem: login doesn't persist or sessions reset
solutions:
.codelabhaven.com (with leading dot)secure flag matches https usagels -la /var/www/html/codelabhaven/projects/your_project_name/sessions
chmod 755 /var/www/html/codelabhaven/projects/your_project_name/sessions
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
after completing these steps, your new project will be:
https://my-new-project.codelabhaven.com