Have you built a website using Laravel but are still confused about how to upload it to hosting? Relax, in this article we will discuss how to upload Laravel to hosting easily.
Of course, the Laravel referred to here is not a blank Laravel installation, but a finished Laravel-based website, such as the blog that will be used in this article
How to Upload Laravel to Hosting
But before discussing how to upload Laravel to hosting, there are a few things you need to know about the Laravel version used in this article, because the Laravel you are using might be different.
Here is the information used in this article:
- Website uses Laravel 9.52.16
- Database access uses XAMPP (localhost/phpmyadmin)
- Hosting uses the cPanel control panel
- Laravel website is created with a subdomain
- Website on localhost is already in production (composer update, has articles, has users, etc.)
Now that you know a little bit of information used in this article, we can proceed to how to upload Laravel to hosting.
1. Compress Laravel Files
The first step you need to take to upload Laravel to hosting is to compress the Laravel files on the device you used to build Laravel. It is recommended to compress the files with the .zip extension so that there will be no issues when extracting files on the hosting.
Just select all the files inside the Laravel folder, then compress those files into a .zip file
2. Export Database
So that the website data you created on localhost can also be moved to hosting, you need to export the database. For example, if you are using XAMPP, you can open the page http://127.0.0.1/phpmyadmin then select the database you are using in that Laravel project
After opening the database, click the export menu to extract the database that you can upload to the hosting
Actually, you can use the Advanced option, but if you do not yet understand its functions, you can just click Export without using the advanced option
At this point, you should have both of the following files so you can proceed to the upload process to hosting (the names do not have to be the same, the most important thing is that you have the .zip and .sql files)
3. Upload Laravel Files to Hosting
Tip: After finishing this step, it is recommended not to close the File Manager tab.
At this point, you can turn off the XAMPP application, artisan, or other deployments on localhost, then move to the hosting to start uploading files.
But before that, it is recommended that Laravel be created on a subdomain or main domain, because if you use a subfolder, for example wpgan.com/laravel, you will need to create additional, more complex .htaccess configurations. In this article, the website will be installed on the domain ehe.my.id
First, to determine the upload folder location, you can open the Domains page from the cPanel hosting you are using
After being on the Domains page, click the folder name in the column Document Root to open your domain or subdomain folder
After being redirected to the File Manager page, you can now upload files to that folder by clicking the Upload button
Upload the .zip file you created (no need to upload the .sql file) and wait until the process is complete
After the upload process is complete, you can return to the File Manager page and extract the .zip file you uploaded by right-clicking on the file, then selecting the Extract option.
After extracting, the Document Root folder on your domain or subdomain will look more or less like this
4. Create Database
Now that you have uploaded the files, you can create a database using the MySQL Database Wizard, then fill in the necessary data.
The method for creating a database will not be discussed specifically, but if you have never created a database, you can follow this tutorial: How to Create a Database in cPanel Without the Hassle
In this example, the database created will look like this:
- DB Name: namadoma_0laravel-wpgan
- DB User: namadoma_laravel_wpgan
- DB Password: 7XLE.FuGZAQM
5. Upload Database
You can open the phpMyAdmin page from cPanel to start importing the database you saved on localhost previously, so that the website data will appear when accessed.
After being on the phpMyAdmin page, open the database you created earlier, for example in this article we use namadoma_0laravel-wpgan, then click the menu Import
Select the database you saved on localhost, then upload it by clicking the button Import. For other options, just leave them as the default
After success, the database you created now has content and you can continue to configure the database through the File Manager
6. Configure Database
For Laravel database configuration, it is usually done inside the file .env or the config.php file, depending on the script creator. If you created the script yourself, you should already know where the database configuration is located.
However, if you bought the script, you can ask the creator, or you can also check the script documentation (usually for scripts sold on marketplaces like Themeforest, the script creator has provided specific documentation for that script).
In this example, the database configuration file is created in the file .env, and because the file .env is a hidden file, we need to display that hidden file through the File Manager settings, then check Show Hidden Files (How to Show Hidden Files in cPanel)
After the hidden file is displayed, you can right-click on the .env file and select the option Edit
Now change the following lines with the database name, user, and password that you created
- DB_CONNECTION=mysql
- DB_HOST=127.0.0.1
- DB_PORT=3306
- DB_DATABASE=0laravel
- DB_USERNAME=root
- DB_PASSWORD=
With the configuration example created in step number 4, the configuration result becomes like this
- DB_CONNECTION=mysql
- DB_HOST=localhost
- DB_PORT=3306
- DB_DATABASE=namadoma_0laravel-wpgan
- DB_USERNAME=namadoma_laravel_wpgan
- DB_PASSWORD=7XLE.FuGZAQM
7. Add .htaccess
If the Laravel application you created on localhost does not have an .htaccess file, you can create it first through the File Manager > + File page
Make sure the file name starts with a dot, so it becomes .htaccess not htaccess. If it does not start with a dot, it will not be read by the system as a rule, but only as a regular file
After the file is created, you can edit the file and add the .htaccess code that you can copy from this page: Default Laravel .htaccess so the result will be like this
8. Try Accessing Your Website
Now that you have performed all the Laravel upload configurations to hosting, you can try accessing your website and ensure that all data, for example website articles, has also been moved
Additionally, if your website uses a login feature, you can also try logging in using the user you created on localhost
That is how to upload Laravel to hosting easily. If there is an error after uploading Laravel to hosting, make sure you enable Debug mode in the .env file to check the cause of the error on the Laravel website you uploaded.
COMMENTS
Loading...