Grow Your Business Online

Linkysoft Services, Products, Hosting, and Servers

Prerequisites

1. cPanel access: Ensure you have cPanel access to your hosting account.

2. SSH access: Check if your hosting provider allows SSH access. This makes installation easier.

3. Composer: Ensure Composer is installed on your server.

Step-by-Step Guide

Step 1: Access cPanel

1. Log in to cPanel: Use your hosting provider's login URL to access cPanel.

Step 2: Set Up the Environment

1. Create a subdomain (optional): If you want to install Laravel in a subdomain, go to the 'Domains' section and create a subdomain.

2. Create a database: Go to 'MySQL Databases' and create a new database and user. Assign the user to the database with all privileges.

Step 3: Access via SSH

1. Open Terminal: Use the Terminal feature in cPanel or access your server via an SSH client (like PuTTY).

2. Navigate to the desired directory: Use the cd command to navigate to the directory where you want to install Laravel. For example:

cd public_html/subdomain

Step 4: Install Composer (if not already installed)

1. Download Composer: Run the following commands to download and install Composer:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php
php -r "unlink('composer-setup.php');"

2. Move Composer: Move Composer to a globally accessible directory:

mv composer.phar /usr/local/bin/composer

Step 5: Install Laravel

1. Install Laravel via Composer: Run the following command to create a new Laravel project:

composer create-project --prefer-dist laravel/laravel myproject

Replace myproject with your desired project name.

Step 6: Configure Laravel

1. Navigate to your project directory:

cd myproject

2. Set up environment variables:

- Rename .env.example to .env:

cp .env.example .env

- Edit the .env file to match your database credentials:

DB_DATABASE=your_database_name
DB_USERNAME=your_database_user
DB_PASSWORD=your_database_password

3. Generate an application key:

php artisan key:generate

Step 7: Set Up Web Server

1. Modify the public folder: Ensure your Laravel installation points to the public directory. In cPanel, you might need to adjust the document root of your domain or subdomain to point to myproject/public.

2. .htaccess configuration: Ensure your .htaccess file in the public directory has the correct settings for mod_rewrite. It should look something like this:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

Step 8: Set Permissions

1. Set correct permissions: Ensure the storage and bootstrap/cache directories are writable:

chmod -R 775 storage
chmod -R 775 bootstrap/cache

Step 9: Test the Installation

1. Access your Laravel application: Open your web browser and navigate to your domain or subdomain. You should see the Laravel welcome page.

Troubleshooting

- 500 Internal Server Error: Check your server logs and ensure all permissions are correctly set.

- Database connection issues: Double-check your .env file for correct database credentials.

By following these steps, you should have Laravel successfully installed on your cPanel hosting. If you encounter any issues, consult your hosting provider’s documentation or support team for additional assistance.

Was this answer helpful? 0 Users Found This Useful (0 Votes)

Search the Knowledge Base

Share