Partners        Payment Options        My Account       Cart

Blog, News & Events

Deploying Laravel (or Django) Apps on Sternhost: From Zero to Live

Getting your modern web application from code to production doesn’t have to be complicated. In this tutorial, we’ll cover two popular frameworks—Laravel (PHP) and Django (Python)—and show you how to deploy them on Sternhost from an empty server to a live, secure site.

Why Choose Sternhost for Framework Apps?

  • Optimized Environments for PHP and Python
  • SSH & Composer/Pip preconfigured on VPS plans
  • Easy Virtual Host Setup via cPanel
  • Free SSL, automated backups, and 24/7 expert support

Common Prerequisites

  1. Sternhost VPS or Dedicated Plan (required SSH access).
  2. Domain Pointed to your Sternhost nameservers.
  3. SSH Key installed in your Sternhost control panel for secure login.
  4. Basic CLI Knowledge (SSH, composer, pip).

Part 1: Deploying a Laravel App

1. Connect via SSH & Prepare Server

ssh youruser@your.server.ip
cd ~
  1. Update packages
    sudo apt update && sudo apt upgrade -y
    
  2. Install PHP dependencies (if not already)—Laravel requires PHP 8.x, extensions, Composer:
    sudo apt install php php-mbstring php-xml php-zip php-mysql php-pdo unzip -y
    curl -sS https://getcomposer.org/installer | php
    sudo mv composer.phar /usr/local/bin/composer
    

2. Upload or Clone Your Laravel Project

  • Git clone:
    git clone https://github.com/yourname/your-laravel-app.git public_html
    
  • Or upload your project ZIP via cPanel File Manager into ~/public_html, then extract.

3. Install Dependencies & Environment

cd public_html
composer install --optimize-autoloader --no-dev
cp .env.example .env
php artisan key:generate

Edit .env to configure:

APP_URL=https://yourdomain.com
DB_HOST=localhost
DB_DATABASE=your_db
DB_USERNAME=your_user
DB_PASSWORD=your_pass

4. Set Up Database

  1. In cPanel → MySQL® Databases, create a database and user.
  2. Grant all privileges, then run:
    php artisan migrate --force
    

5. Configure Virtual Host & SSL

  1. In cPanel → DomainsAddon Domains (or Subdomains), point yourdomain.com to public_html/public.
  2. Enable SSL via SSL/TLSLet’s Encrypt.
  3. In .htaccess (inside public_html/public), ensure Laravel’s rewrite rules:
    <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteRule ^(.*)$ public/$1 [L]
    </IfModule>
    

6. Optimize & Go Live

php artisan config:cache
php artisan route:cache
php artisan view:cache

Visit **https://yourdomain.com**—your Laravel app is live!

Part 2: Deploying a Django App

1. Connect via SSH & Prepare Server

ssh youruser@your.server.ip

Install Python 3, pip, virtualenv:

sudo apt update && sudo apt install python3 python3-venv python3-pip -y

2. Upload or Clone Your Django Project

cd ~
git clone https://github.com/yourname/your-django-app.git
mv your-django-app public_html

3. Create Virtual Environment & Install Requirements

cd public_html
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

4. Configure Django Settings

In settings.py:

ALLOWED_HOSTS = ['yourdomain.com']
DEBUG = False
STATIC_ROOT = BASE_DIR / 'staticfiles'

Collect static files:

python manage.py collectstatic --noinput

5. Set Up Database

If using MySQL/PostgreSQL:

  1. Create DB & user in cPanel → MySQL® Databases or PostgreSQL® Databases.
  2. Update DATABASES in settings.py.
  3. Run migrations:
    python manage.py migrate
    

6. Configure uWSGI and Apache (via cPanel)

  1. In cPanel → Setup Python App:
    • Choose Python 3.x
    • Set “Application root” to public_html
    • “Application startup file” to passenger_wsgi.py (create this file next)
  2. Create passenger_wsgi.py in public_html:
    import os
    from django.core.wsgi import get_wsgi_application
    
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'yourproject.settings')
    application = get_wsgi_application()
    
  3. Restart the Python app in cPanel.

7. Enable SSL & Test

Troubleshooting & Tips

  • Permissions: Ensure storage (Laravel) or staticfiles (Django) directories are writable (chmod -R 755).
  • Logs: Check storage/logs/laravel.log or Django’s error_log via cPanel’s Metrics → Errors.
  • Support: Sternhost’s 24/7 team can assist with server-level issues—open a ticket via the Support Portal.

Conclusion

Deploying Laravel or Django on Sternhost is fast and reliable when you follow these steps. From SSH setup to SSL configuration, our platform gives you the tools to launch robust, production-ready applications. Ready to deploy? Log in to your Sternhost cPanel and go live today!

Leave a Reply

Your email address will not be published.