Hello worlds,
We have built a shortener URL with Laravel 9 from the previous posts. The functionalities already implemented, we will deploy it to make this service accessible through internet. Actually, there are several ways to host a Laravel Project and in this tutorial, we will do it on Shared Hosting.

The Advantage of using Shared Hosting is that the setup is quite simple because we don’t need to set up a web server, database, php, etc. It’s already managed by the hosting providers, so we just need to manage our project. But the weakness, obviously we depend on the environment provided by this hosting provider, such as the version of the tools used.

Another drawback is that the resources on this hosting are shared with other users, as the name implies shared hosting. When the hosting provider has many users and their websites are accessed by so many visitors, the performance most likely will be degraded. Okay, here I use Domainesia for this shared hosting. There are also certain free domain features on the domainesia hosting packages.

Btw, for those who want to register on Domainesia, you can use my referral code: “AGRIK”. I get a small commission from the referral, and you can get discount of up to 30%, valid forever. Not bad at all, isn’t it?

[SAMPLE] Discount 30%, forever . Hosting on Domainesia

However, if you use hosting that doesn’t have SSH features, either on Domainesia or other shared hosting, you can follow the following tutorial: https://www.domainesia.com/panduan/cara-upload-file-laravel-di-hosting/.

In my personal opinion, it’s quite comfortable to use Domainesia, moreover, I’m using a package that has SSH features. So that was easier to deploy and use tools such as git, composer , Laravel Artisan Command, Tinker, etc. Even though it’s shared hosting, the performance is quite good.

  1. PHP environment

Before installing Laravel, we first prepare the environment needed by Laravel, namely the PHP version and the configuration that needs to be activated via the Tools Menu >> Select PHP Version. Also we need to enable the following extensions as a prerequisites for Laravel 9.

Select PHP Version on Domainesia CPANEL

— BCMath PHP Extension
— Ctype PHP Extension
— DOMPHP Extensions
— Fileinfo PHP Extension
— JSON PHP Extension
— Mbstring PHP Extension
— OpenSSL PHP Extension
— PCRE PHP Extension
— PDO PHP Extension
— PHP Extension
— Tokenizers XML PHP Extension

Select PHP version and enable PHP Extensions

2. Domain Setup
To set up the domain, we access the Domain menu on CPANEL and we specify the folder where our Laravel project is set up. In that folder, we place the Laravel project in the ‘pendekin’ folder.

*In the next stage, I will use ‘1ln’ folder, to be able to provide screenshots and simulate the configuration process.

domain set up on CPANEL

3. MySQL Database Setup
Next, let’s create the MySQL database. You can follow the following tutorial: https://www.domainesia.com/panduan/panduan-buat-database-mysql-di-cpanel/, to determine the database name, user, and password. After getting it, we can include these variables in .env file .

4. Set Up Laravel Project via SSH
We will use SSH to upload to shared hosting. The SSH setup can be seen in the Domainesia tutorial, at the following link: https://www.domainesia.com/panduan/cara-access-ssh-di-cpanel-hosting/. After entering SSH, we can install our project.

— Clone from the repository
The code that we created, with the following repository address: https://github.com/agriirga/pendekin.git. We can clone it with the following syntax in the SSH terminal: git clone https://github.com/agriirga/pendekin.git 1ln . The 1ln is the name of the folder that we will use when we clone from the repository.

clone project with ssh on 1ln folder

— Download Project Dependencies
As we have learned before, we can download the dependencies of this project using the composer update.

download project dependencies through composer update

— Create a .env file
Execute the following command :

cp .env.example .env

To create a .env file from an example .env.example file. Don’t forget there are important things that we set up yesterday in the project, namely: DB configuration and ReCaptcha configuration. Let’s customize the .env file on this server.

Add information on .env file

We also need to change these .env variables

APP_DEBUG = FALSE 
APP_URL=https://1ln.xyz

We set APP_DEBUG as false so that the display of errors/bugs in our application does not appear to our users, considering that this application can be accessed by the public. For trace errors, we can look at storage>>logs>>laravel.log . Meanwhile, we modify the APP_URL to the domain name or subdomain that we use, in this example: https://1ln.xyz.

For reCaptcha configuration, you can create a new configuration or change an existing one. Similar to the previous tutorial, what must be considered is the domain of our application. Here I add my domain, namely ‘1ln.xyz’ .

reconfig ReCaptcha keys for our hosting

When done, please attach it to the .env variable. Next, we need to generate the encryption key used in our application by running this artisan command:

php artisan key:generate

— Database Migration
Run the artisan command to generate a database via the Laravel migration with this command :

php artisan migrate

— Configuration .htaccess File

In the project folder that we created earlier, we need to create the .htaccess file as follows:

touch .htaccess

In that file, include the following script so that our Laravel project can be accessed via the domain or subdomain that we specify.

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteRule ^(.*)$ public/$1 [L]

</IfModule>

Voila, now our web can be accessed via the internet. As an example of a project, you can access this website on this page https://1ln.xyz .

https://1ln.xyz

Ok, I think thats enough for this tutorial series. We already learn Laravel 9 and build shortener URL project and deploy it to internet. If you feel this tutorial series is helpful, please share , clap, and follow me on Medium.

Have any questions or suggestions about this tutorial series ? You can hit me in the comments below. That’s all I thought, hopefully, we can learn more in next times. Cheers .

--

--

Agri Kridanto

I'm a software developer with skills in web & mobile development. Proficient in PHP, Javascript and Java. Also experienced in IoT & Machine Learning research