To deploy a Laravel project on a cPanel server, you can follow these steps:
-
Make sure your cPanel server meets the Laravel system requirements, such as PHP version, extensions, and database support.
-
Create a new subdomain or add-on domain in cPanel to point to the public directory of your Laravel project. This can usually be done through the "Domains" or "Subdomains" section in cPanel.
-
Upload your Laravel project files to the appropriate directory on the server. Typically, this would be the public_html directory for the main domain or the subdomain/add-on domain directory you created in the previous step.
-
Set the correct file permissions for your Laravel project. The storage and bootstrap/cache directories should be writable by the web server. You can do this using the following commands via SSH or cPanel's file manager:
cd /path/to/your/laravel/project
chmod -R 755 storage bootstrap/cache
-
Create a new MySQL database and user in cPanel. Make sure to grant the user all necessary privileges for the database.
-
Update the .env file in your Laravel project with the database connection details. You can find the .env file in the root directory of your Laravel project. Update the following lines with your database credentials:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_database_name
DB_USERNAME=your_database_username
DB_PASSWORD=your_database_password
- Run the necessary Laravel migration and seed commands to set up your database tables and initial data. You can do this via SSH or by using Laravel's Artisan command line tool. For example:
php artisan migrate --seed
- Finally, make sure your cPanel server has the necessary PHP extensions enabled for Laravel to work properly. Common extensions include OpenSSL, PDO, Mbstring, Tokenizer, and XML. You can usually enable these extensions through the "Select PHP Version" or "PHP Extensions" section in cPanel.
If you're still encountering errors after following these steps, it would be helpful to provide more specific details about the errors you're seeing.