I assume the coding friend already has a real Laravel project that has been completed in development or an empty project, it doesn't matter.
There are several steps that I will share, including:
1. Install the Empty Laravel Project via the official laravel documentation at https://laravel.com/.
2. Make the laravel project a .zip extension.
3. If you don't have a hostinger account, please create an account or register with the https://www.hostinger.co.id/ site as a place to store our project folder along with assets, databases and domains.
4. Then login to hostinger and go to hosting menu and click file manager.
5. Upload the laravel project that has been created. zip into the public_html folder and extract it in the public_html folder.
6. If you have entered the project folder that has been extracted then into the public folder and move all files in the public folder into the public_html folder.
7. Then open the index.php file in the public_html folder and make changes to the following line of code:
require __DIR__.'/../vendor/autoload.php';
be like below :
require __DIR__.'/{folder_project}/vendor/autoload.php';
and
$app = require_once __DIR__.'/../bootstrap/app.php';
be like below :
$app = require_once __DIR__.'/{folder_project}/bootstrap/app.php';
👉 folder_project is the name of the extracted folder from the zip extension project.
8. Next is the settings for the database from the laravel project in this case I use postgresql. to make changes to the database connection, you can enter the project folder then open the .env file and make changes as below :
DB_CONNECTION=pgsql
DB_HOST=88.88.88.88 {ip_database}
DB_PORT=5432
DB_DATABASE=database_name
DB_USERNAME=username
DB_PASSWORD=password
or like this:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=database_name
DB_USERNAME=username
DB_PASSWORD=password
9. Make changes to the AppServiceProvider.php file in the_project/app/Providers folder in the function register to be like this:
/**
* Register any application services.
*
* @return void
*/
public function register() {
$this->app->bind('path.public', function() {
return base_path('../../public_html');
});
}
This is when we insert the file not into the public folder in the project but into the assets folder in the public_html folder.
10. If steps 1 to 9 have been done then you can check whether your website has been successfully uploaded by typing the url of your website, for example https://www.embuncode.com.
11. Maybe this is a tutorial that I can share for hosting a laravel project into cpanel hostinger, oh yes, this time I'm using laravel 9.
Thanks for reading, I hope it's useful.