Deploying a Laravel application to production can be challenging, especially when moving from local development to a live server environment. This comprehensive guide walks you through setting up a Digital Ocean droplet with cPanel/WHM for Laravel deployment, covering everything from SSH key generation to initial server configuration.
Prerequisites
Before diving into the deployment process, ensure you have:
- A Digital Ocean account with a droplet (16GB RAM, 50GB disk recommended)
- Basic knowledge of SSH and command line operations
- Your Laravel application ready for deployment
- Domain name configured (we'll use
yourdomain.com
throughout this guide)
Step 1: Setting Up SSH Access
Generating SSH Keys
First, generate an SSH key pair on your local machine:
When prompted, save the key with a descriptive name like laravel_app_ssh_key
. This creates both private and public key files.
Connecting to Your Server
Once your Digital Ocean droplet is ready (IP: 171.50.123.100 - use your_ip_address), set proper permissions and connect:
You'll be greeted with the Ubuntu welcome screen and cPanel & WHM interface information.
Step 2: WHM Initial Setup
Accessing WHM
After SSH connection, you'll receive a WHM login URL similar to:
Creating Your First cPanel Account
Navigate to Account Functions → Create a New Account and configure:
Account Details:
- Domain: yourdomain.com
- Username: your_app_name (avoid special characters)
- Password: Use a strong, unique password
- Email: Your administrative email
Resource Allocation:
- Disk Space: 50GB+ (important for file uploads and logs)
- Bandwidth: Unlimited
- Email Accounts: 50+
- Databases: 10+
Step 3: PHP and Server Configuration
PHP Version Setup
Laravel requires PHP 8.1 or higher. Configure this through WHM:
- Navigate to Software → MultiPHP Manager
- Select PHP 8.2 for optimal performance
- Go to Software → EasyApache4
- Update all packages in "Currently Installed Packages"
If you encounter errors during updates, perform a graceful reboot:
- Search for "reboot" in WHM sidebar
- Execute graceful reboot
- Return to EasyApache4 and continue
Enabling Required PHP Extensions
In Software → EasyApache4 → Customize Currently Installed Packages → Enable Extensions, ensure these are active:
- OpenSSL
- PDO
- Mbstring
- Tokenizer
- XML
- Ctype
- JSON
- BCMath
- Fileinfo
Step 4: Database Configuration
Creating MySQL Database
Through cPanel, navigate to Databases → MySQL Databases:
- Database Name:
your_app_digital_db
- Username:
your_app_digital_db_user
- Password: Generate a strong password
- Privileges: Grant all privileges to the user
Step 5: File Upload and Initial Setup
Uploading Your Laravel Application
- Access cPanel File Manager
- Navigate to
public_html
- Upload your Laravel application as a ZIP file
- Extract the contents
Creating Essential Files
Create .env
file:
Create .htaccess
file in root directory:
Step 6: Setting Proper Permissions
SSH into your server and set Laravel-specific permissions:
Step 7: Installing Dependencies
Composer Installation
Node.js and NPM Setup
If Node.js isn't installed:
Install and build assets:
Laravel Artisan Commands
Troubleshooting Common Issues
NPM Installation Failures
If npm install fails, ensure Node.js is properly installed and try:
Permission Denied Errors
Ensure your SSH user has proper permissions:
Cache Issues
Clear everything and rebuild:
Testing Your Deployment
Access your application using the server IP:
http://171.50.123.100
(your_ip_address)http://171-50-123-100.cprapid.com
Update your .env
file accordingly:
What's Next?
This initial setup provides a solid foundation for your Laravel application. In our next guide, we'll cover domain configuration, SSL certificates, and performance optimization to take your deployment to production-ready status.
Building and deploying web applications is a core skill every developer needs. At ScriptVil, we're creating a marketplace where developers can share deployment scripts, configuration templates, and automation tools. Whether you're looking for ready-made deployment solutions or want to monetize your DevOps expertise, ScriptVil will be your go-to platform when we launch.
Key Takeaways
- Always use SSH keys for secure server access
- Proper file permissions are crucial for Laravel applications
- cPanel/WHM provides an intuitive interface for server management
- Testing with IP addresses before domain configuration saves time
- Environment-specific configurations prevent common deployment issues
Ready to take your Laravel deployment further? Stay tuned for our next guide on domain configuration and SSL implementation.