Introduction and overview
So today I'm going to show you how you can host or deploy your Laravel application to hosting. The one that I'm going to use in this video is Hostinger hosting. This is not my hosting; actually, this is the hosting of one of my clients and he wants me to deploy his Laravel application. If you have any other hosting then the process will be the same—just the difference is the whole cPanel or HPanel.
Accessing Hostinger and selecting the domain
When you log into Hostinger you will see the home page. To host your application you need to go to Hosting and then find the domain on which you want to host your Laravel application. As you can see I have different domains here; I need to choose the domain on which I want to host my Laravel application. I want to host my Laravel application on this domain, so let's click Manage and it will go to the dashboard of this domain. When you go to this domain you need to click File Manager and this will open up in a new tab. This will actually open a File Manager where your application will be hosted.
Preparing and compressing the Laravel project
Let me show you the application that I want to host—this is the Laravel application. There are different ways to host your Laravel application, like with FTP or SSH keys, but the one that I am going to use and show you is the manual way. What I need to do is go to the destination folder where my project is located. This is my project, Emerging Publishers. I need to convert this application folder into a compressed ZIP folder. Right click on the application folder, choose the Send to option, and then choose Compressed (zipped) folder. This will convert it into a ZIP folder. Whenever you host your application manually you need to first convert your application folder into a ZIP folder. Let's wait while it compresses. Now the folder has been compressed successfully. Now I need to upload this folder into the public_html folder.
Uploading ZIP to public_html and extracting
Go to the public_html folder. Currently I just have this .htx s file here. If I go to the domain where I want to upload this application, it is giving a 500 Internal Server Error because I don't have anything uploaded in public_html. Click the Upload button in File Manager, then choose File and navigate to the compressed application. Select the ZIP file and upload it. Upload time depends on internet speed and application size. The folder has been uploaded. Now this folder is a ZIP folder; we need to unarchive it. Right click the ZIP and select Unarchive. It will ask the folder in which you want to unarchive; I want to unarchive into the current folder, public_html, so click Unarchive. The folder is unarchived. Now select all of the application files and move them to public_html. To move into the parent folder (public_html), click the folder icon and then click Move.
Verify site is live and initial database error
Now we are in the public_html folder and these are the complete folders of our application. If I go to the domain and refresh, our application is live and we do not see any error. This is how we host our application. Now how can we connect this application to the database? If I go to the Contact Us page and fill out some data—some dummy data—and submit, we get an error saying access denied for user. This means the application is not connected to the database. To connect the application to the database we first need to create a database.
Creating the live MySQL database in Hostinger
Go back to Hosting and click the Database option. You can create multiple databases here. I have some databases already. Let's create a new one and name it EP because the site name is Emerging Publisher, then EP_admin. You can generate a password or add your own; I'll add my own, then adjust to meet requirements with numbers and uppercase. Create the database. Whenever you create a database you should save the credentials in a separate file so you can fetch the information later if you forget. I have created the database and if I scroll down you can see the database we created. Click Enter phpMyAdmin to go to phpMyAdmin for that database.
Exporting local DB and importing to live phpMyAdmin
This is our database. I need to upload my database to this live database. First open XAMPP because I have my database on my local machine. I need to export the database from local and import it into the live database. Go to localhost phpMyAdmin and the local database EPDB. Click Export, choose Custom to display all options, then click Export to save the SQL file to Downloads. To upload this SQL database, click Import on the live database server and upload the exported SQL file. Click Go. This will upload the whole database into the live database. Now we have deployed our application, created our database, and deployed our database from localhost to the live server.
Update .env credentials and test connectivity
To connect the live database to the application, go to public_html where you uploaded the application and open the .env file of your Laravel application. Find the database credentials and add all credentials of the database you created. Copy the database name, username, and password from the hosting database panel and paste them into the .env file. Save the file. Now send the request again. The request is received successfully, which means our application is running and connected to the database.
Recap and closing notes
This is how you can easily deploy or host your Laravel application manually. In this video I used Hostinger, but the process is the same on any cPanel or HPanel: convert your application folder into a ZIP, upload it into your file manager, unarchive it, and ensure your application files are in public_html to be live on your domain.