Introduction
The Laravel framework can be installed on cPanel accounts using PHP's composer.
Procedure
Please note that Laravel is 3rd-party software. While these steps are provided for instructional purposes, cPanel support can't perform the installation or any configuration.
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:
Installation:
- 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 - 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 -
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
php-fileinfo Extension Errors:
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.
SoftException in Application.cpp errors:
Servers set up to use the "suphp" handler for PHP may encounter permissions issues when accessing the Laravel installation:
SoftException in Application.cpp:267: File "/home/cptest/public_html/example-app/public/index.php" is writeable by group
These errors are due to permissions requirements with the suphp handler, and the default permissions installed as part of the Laravel framework. These errors can be corrected by editing the file permissions as described here:
PHP website error 500 - Apache error_log reports "SoftException in Application.cpp"