Guide to deploy Laravel 5 app to shared hosting (1and1/ionos)

Last updated

Antonio Ufano avatar

Antonio Ufano

⚠️ Important This is a very old article and I've published another one which is better explained and, even though is meant for Namecheap servers, it should be very similar if you are using 1and1 or Ionos. You can find it here: How to deploy Laravel to shared hosting

In this article I'm going to explain how to deploy a Laravel 5 application to a shared hosting using 1and1 as a reference. If you are using a different hosting provider some steps can be different, like the ones involving the control panel, but other should be pretty similar. Hope it helps you.

Pre-requisites

A Laravel application running in your local PC.

Access via FTP and SSH to your 1and1 hosting.

Step by step guide

1.- Connect via FTP and create a folder for your application, for example "myWebApp".

2.- Copy in it all the archives and directories from your local PC. You'll have directories like app, config, routes public etc ...

3.- In the file /public/.htaccess modify the line

    RewriteRule ^ index.php

to:

    RewriteRule ^ /index.php

4.- Now you have to configure your domain to point to the /public folder of your app; in our case myWebApp/public. Go to the 1and1 Control Panel > Domains and configure where your domain is pointing.

5.- Configure the PHP version that is running for your domain. In the 1and1 Control Panel, search for an option called PHP configuration, select your domain and choose PHP version 7.0.0.

6.- At this point you can try to access your application by it's domain. You might have a paermission error in some folders like /storage. If so you need to connect to your server via SSH to grant the application permission to write in the folder. Go back to the 1and1 Control Panel, to the Secure FTP section. Once there, search for SSH access and configure a user and password. Also make sure to copy the host address. Now open a Terminal in your PC and run the command:

$ssh youruser@yourhostaddress

(it will ask you the password)

Once connected we can grant permissions to the folder with the command

$chmod 777 myWebApp/storage

Apply to any neccesary folder.

Once completed, your application should be running in the 1and1 servers without issues.

Configure a MySQL database

If your application requires a MySQL database to run, the first thing you need to do is obtain an export sql file with the queries to create all the tables.

7.- Go to MySQL databases section in the 1and1 Control Panel and create a new database. Configure a username and password to access and make sure to also copy the host details.

8.- Import your SQL file to create all tables in the database.

9.- Go back to your local PC and modify the file .env (in the root of your project) with the connection details to your database and upload the file to the server via FTP. 1and1 usually assign a prefix to the database name when you create it, make sure you configure it correctly.

10.- Give it a try :)

If you enjoyed this article consider sharing it on social media or buying me a coffee ✌️

Oh! and don't forget to follow me on Twitter where I share tons of dev tips 🤙

Other articles that might help you

my projects

Apart from writing articles in this blog, I spent most of my time working on my personal projects.

lifeboard.app logo

theLIFEBOARD.app

theLIFEBOARD is a weekly planner that helps people achieve their goals, create new habits and avoid burnout. It encourages you to plan and review each week so you can easily identify ways to improve your productivity while keeping track of your progress.

Sign up
soliditytips.com logo

SolidityTips.com

I'm very interested in blockchain, smart contracts and all the possiblilities chains like Ethereum can bring to the web. SolidityTips is a blog in which I share everything I learn about Solidity and Web3 development.

Check it out if you want to learn Solidity
quicktalks.io logo

Quicktalks.io

Quicktalks is a place where indie hackers, makers, creators and entrepreneurs share their knowledge, ideas, lessons learned, failures and tactics they use to build successfull online products and businesses. It'll contain recorded short interviews with indie makers.

Message me to be part of it