Step-by-step installation of Laravel 12 on cPanel hosting
Installing Laravel 12 on cPanel hosting can seem daunting, but with the right guidance, it becomes a straightforward process. This article will provide you with a detailed, step-by-step approach to install Laravel 12 on your cPanel hosting environment. We will cover everything from preparing your environment to setting up your database and deploying your application.
Prerequisites
- Access to a cPanel hosting account
- Basic knowledge of PHP and web servers
- Composer installed on your local machine
- FTP client or cPanel File Manager access
Step 1: Choose the Right Hosting Plan
Before you begin, ensure that your hosting plan supports Laravel’s requirements:
- PHP version 8.0 or higher
- MySQL version 5.7 or higher
- OpenSSL, PDO, Mbstring, Tokenizer, XML, and Ctype extensions enabled
Step 2: Create a New Database
1. Log in to your cPanel account.
2. Navigate to the MySQL Databases section.
3. Create a new database by entering a name and clicking Create Database.
4. Create a new MySQL user with a secure password.
5. Add this user to the database and grant all privileges.
Step 3: Upload Laravel Files
1. On your local machine, open your terminal and create a new Laravel project:
composer create-project --prefer-dist laravel/laravel your-project-name
2. Once the installation is complete, compress the folder into a .zip file.
3. In cPanel, navigate to the File Manager.
4. Upload the .zip file to the public_html directory.
5. Extract the .zip file.
Step 4: Configure Environment File
1. Locate the .env file in your Laravel project folder.
2. Update the database connection settings:
DB_HOST=localhost
DB_DATABASE=your_database_name
DB_USERNAME=your_database_user
DB_PASSWORD=your_database_password
3. Save the changes.
Step 5: Set Permissions
Ensure that the storage and bootstrap/cache directories are writable:
- In File Manager, right-click on storage and select Change Permissions.
- Set permissions to 755.
- Do the same for bootstrap/cache.
Step 6: Generate Application Key
1. Access the terminal via SSH or use the cPanel Terminal feature.
2. Navigate to your Laravel project directory:
cd public_html/your-project-name
3. Run the following command to generate the application key:
php artisan key:generate
Step 7: Run Migrations
Set up your database tables by running migrations:
php artisan migrate
Step 8: Access Your Application
Open your web browser and go to your domain:
http://yourdomain.com
Your Laravel application should now be up and running!
Checklist for Installation
- Ensure PHP and MySQL versions are compatible.
- Create a database and user in cPanel.
- Upload Laravel files to the correct directory.
- Configure the .env file.
- Set appropriate permissions for storage and cache.
- Generate application key.
- Run migrations to set up the database.
FAQs
1. What if I encounter errors during installation?
Check your PHP version and ensure all required extensions are enabled. Review error logs in cPanel for more details.
2. Can I use shared hosting for Laravel?
Yes, shared hosting can work for Laravel, but consider using a VPS for better performance.
3. How do I update Laravel in cPanel?
Upload the new version files and run composer update in the terminal.
4. Is it necessary to use Composer?
Yes, Composer is essential for managing Laravel’s dependencies.
5. How can I troubleshoot common Laravel errors?
Consult the Laravel documentation and check your server logs for specific errors.
6. What are the benefits of using Laravel?
Laravel offers robust features like routing, authentication, and a powerful ORM, making development faster and more efficient.
7. How do I secure my Laravel application?
Use HTTPS, validate user inputs, and keep your Laravel version updated to enhance security.