You have successfully made an app with Laravel on your local. Now, the next
step is deploying the app to a live production server so it can be access for
everyone.
Step 1: Upload Files
Upload all your Laravel project files to the live production server in the
root folder. As an example, I have made
After your database has been created, you will get the username, database name,
password and hostname. You will need to use all these information in
Step 3.
Step 3: Edit
Step 4: Create redirect to
/public_html/restoapp
as the
root path for my
Restaurant App. So, I uploaded everything into the folder.
Step 2: Create database
Next, create the database for the app. Creating database is different, based
on what server/hosting you used and what kind of databse you use. In my case,
I use StackCP and MySQL database so the interface is like shown in the photo
below.
Next, login into phpMyAdmin and import the .sql file that you
have exported from your local.
Step 3: Edit .env
file
Now that you have your files and database ready, you need to edit your
.env
file so that your app will use the database that you've just created. Simply
change DB_HOST
, DB_DATABASE
, DB_USERNAME
and DB_PASSWORD
in the file by
using your newly created database information from the previous step.
Step 4: Create redirect to public
folder
Your app should already be deployed by now. However, it can only be access
if you put
/public
into the URL of your app. For example, the url of my app
is restoapp.aliya-h.com
, but the app can only be accessible if I open
restoapp.aliya-h.com/public
. If I open my app without the /public
, I
will get a 500 Error as shown below.
To avoid this, we need to create a new
.htaccess
file in the root folder where all
our files were uploaded. Inside this file, insert these lines of code:
RewriteEngine on RewriteCond %{REQUEST_URI} !^public RewriteRule ^(.*)$ public/$1 [L]
What this code do is, it will redirect all access of your app to the folder
/public
, without explicitly show it in the URL. Step 5: Done
Congratulations! You have successfully deploy your app to a live server!
You can view the Laravel project that I've deployed for this tutorial in this link: http://restoapp.aliya-h.com/ (please open it on desktop as it is not mobile-friendly).
No comments:
Post a Comment