Deploying a Laravel 8 application on OzSpeed’s hosting platform is straightforward when using hPanel. Laravel is a popular PHP framework known for its elegant syntax and robust features, making it an excellent choice for building web applications. Here’s a step-by-step guide to help you successfully deploy your Laravel 8 application on OzSpeed.
Prerequisites #
Before starting the deployment, ensure you have the following:
- An OzSpeed hosting plan with PHP 7.4 or higher.
- Access to hPanel (OzSpeed’s control panel).
- SSH access enabled (optional but recommended for command-line tasks).
- A Laravel 8 project ready for deployment on your local machine.
Step 1: Prepare Your Laravel Application for Deployment #
- On your local machine, open the Laravel project folder.
- Run the following command to optimize the project:
bashCopy codephp artisan optimize
- Generate the application key if you haven’t already:
bashCopy codephp artisan key:generate
- Set the APP_ENV to
production
in the.env
file:
bashCopy codeAPP_ENV=production
APP_DEBUG=false
Tip: #
- Ensure you have configured the database connection in the
.env
file before deployment.
Step 2: Log in to hPanel and Access File Manager #
- Go to ozspeed.com.au and log in to your hPanel Dashboard.
- Navigate to Files > File Manager.
Step 3: Upload Your Laravel Project #
- Compress your Laravel project folder (excluding the
node_modules
and.git
folders) into a ZIP file. - In the File Manager, navigate to the public_html directory or the folder where you want to deploy your Laravel app.
- Click “Upload” and select the ZIP file.
- Once the upload is complete, right-click the ZIP file and select “Extract”.
Tip: #
- Ensure all files are extracted correctly, and the Laravel project structure is preserved.
Step 4: Set Up the Environment File #
- In the File Manager, locate the
.env
file and open it for editing. - Update the following environment variables:
bashCopy codeAPP_NAME=YourAppName
APP_ENV=production
APP_KEY=base64:your_generated_key
APP_DEBUG=false
APP_URL=https://yourdomain.com
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=your_database_name
DB_USERNAME=your_database_user
DB_PASSWORD=your_database_password
Tip: #
- Ensure the database credentials match the database you will create in the next step.
Step 5: Create a Database in hPanel #
- Go to Databases > MySQL Databases in hPanel.
- Click “Create New Database”.
- Enter the database name, username, and password.
- Note down the database credentials, as you will need them for the
.env
configuration.
Step 6: Configure PHP Settings #
- In hPanel, go to Advanced > PHP Configuration.
- Set the PHP version to 7.4 or higher (Laravel 8 requires PHP 7.4 or later).
- Enable the following PHP extensions:
- mysqli
- pdo_mysql
- mbstring
- openssl
- tokenizer
- xml
- Click “Save” to apply the changes.
Step 7: Install Composer Dependencies #
- Enable SSH access in hPanel if you haven’t already.
- Connect to your server via SSH using a terminal or SSH client (e.g., PuTTY):
bashCopy codessh your_username@yourdomain.com
- Navigate to the Laravel project directory:
bashCopy codecd public_html/your_laravel_project
- Install the project dependencies using Composer:
bashCopy codecomposer install --optimize-autoloader --no-dev
Step 8: Set Up File Permissions #
Ensure the correct file permissions for Laravel to function properly:
bashCopy codechmod -R 755 storage
chmod -R 755 bootstrap/cache
Tip: #
- These permissions allow the web server to read and write to the necessary directories.
Step 9: Run Laravel Migrations #
- Run the database migrations to create the necessary tables:
bashCopy codephp artisan migrate --force
- Seed the database (optional but recommended if you have seed data):
bashCopy codephp artisan db:seed --force
Step 10: Set the Document Root for the Laravel Application #
- In hPanel, go to Domains > Redirects or Manage Website Settings.
- Set the document root to point to the
public
folder of your Laravel project (e.g., /public_html/your_laravel_project/public).
Step 11: Enable SSL for Your Laravel Site #
- Go to Domains > SSL in hPanel.
- Click “Install Let’s Encrypt SSL” for your domain.
- Enable HTTPS redirection to ensure secure connections.
Step 12: Optimize the Laravel Application #
Run the following commands to optimize your Laravel app for production:
bashCopy codephp artisan config:cache
php artisan route:cache
php artisan view:cache
Tip: #
- These commands cache the configuration, routes, and views, improving performance.
Step 13: Test Your Laravel Application #
- Open a browser and go to https://yourdomain.com.
- Verify that your Laravel application is loading correctly.
- Check the logs in the storage/logs folder if you encounter any errors.
Additional Tips: #
- Enable Debug Mode Temporarily: If you face issues, temporarily set
APP_DEBUG=true
in the.env
file for error reporting. - Regular Backups: Use the Backup tool in hPanel to create regular backups of your Laravel application.
- Keep Dependencies Updated: Regularly update your Composer packages to ensure security and compatibility.