Introduction
The Laravel framework can be installed on cPanel accounts using PHP's composer.
Procedure
Note: The following commands are meant to be run as the cPanel user and not root. Information on connecting to SSH as the cPanel user can be found here:
Additionally, note that Laravel is 3rd-party software, while these steps are provided for instructional purposes, cPanel support can't perform the installation nor any configuration.
1. Ensure that PHP Composer is set up on the server. This can be verified with the composer diagnose
command. For example if allow_url_fopen is not enabled, the following will be shown:
# composer diagnose
Checking composer.json: WARNING
No license specified, it is recommended to do so. For closed-source software you may use "proprietary" as license.
Checking platform settings: FAIL
The allow_url_fopen setting is incorrect.
Add the following to the end of your `php.ini`:
allow_url_fopen = On
2. Navigate to the location where you wish to create a Laravel project. Install Laravel with the following commands. The "example-app" is the name of the directory the project will be installed into.
# composer create-project laravel/laravel example-app
# cd example-app
# php artisan serve
3. Create a new database, user, and password via cPanel. Modify the .env file within the project directory with the database details:
[~/example-app]# grep ^DB_ .env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=cptest_larvel
DB_USERNAME=cptest_larvel
DB_PASSWORD="password"
Congratulations, Laravel is now set up on your cPanel account.
Troubleshooting
If you receive an error similar to the following during creation, this is caused by the fileinfo PHP package not being installed on the server:
# composer create-project laravel/laravel example-app
Creating a "laravel/laravel" project at "./example-app"
Installing laravel/laravel (v7.30.1)
- Downloading laravel/laravel (v7.30.1)
- Installing laravel/laravel (v7.30.1): Extracting archive
Created project in /home/cptest/example-app
> @php -r "file_exists('.env') || copy('.env.example', '.env');"
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.
Problem 1
- laravel/framework[v7.29.0, ..., 7.x-dev] require league/flysystem ^1.1 -> satisfiable by league/flysystem[1.1.0, ..., 1.x-dev].
- league/flysystem[1.1.0, ..., 1.x-dev] require ext-fileinfo * -> it is missing from your system. Install or enable PHP's fileinfo extension.
- Root composer.json requires laravel/framework ^7.29 -> satisfiable by laravel/framework[v7.29.0, ..., 7.x-dev].
To enable extensions, verify that they are enabled in your .ini files:
- /opt/cpanel/ea-php72/root/etc/php.ini
- /opt/cpanel/ea-php72/root/etc/php.d/20-bcmath.ini
Install fileinfo with EasyApache 4 to correct this.
Additional Information
Official Laravel installation documentation
Comments
0 comments
Article is closed for comments.