Deploy Laravel 5.2 Webapp to 1and1

As of Laravel 5.3 the 1and1 hosting does NOT meet all Laravel requirements

Laravel 5.3 requires php command line version to be PHP >= 5.6.4.

DO NOT USE 1AND1 HOSTING SERVICE IF YOU WANT TO DEPLOY A LARAVEL APP >= 5.3

About

This guide will work nicely if you have a Laravel webapp version 5.2 or 5.1 working already like a charm.

Assumptions

Your webapp uses Laravel version 5.2 or 5.1.

Your webapp is under version control so you can clone your repo in a remote server. 1and1 supports Git by default.

You have ssh access to the deployment server.

You have a Laravel webapp version 5.2 or 5.1 setup and working.

PHP version

Configure PHP version to 7 on 1and1 control panel, just Google for how to change 1and1 PHP version.

MAKE SURE THE DEPLOYMENT DOMAIN IS RUNNING PHP VERSION >= 5.5.9.

PHP command line version

1and1 php command line version is 4.x, this means our commands won’t work when we deploy, nevertheless, a php 5.5 command line version is installed on 1and1, to try it run php5.5 -v in your ssh session.

The name of the php version 5.5 may differ like: php5.5-cli

To have same command available in our development machine we can run:

ln -s /usr/local/bin/php /usr/local/bin/php5.5

This way on 1and1 we can run.

php5.5 artisan down

To put our site into maintenance mode and so on.

Getting the sources

Clone your repo in the remote server using ssh and place yourself on the root directory of your webapp.

Artisan

Open artisan file with your text editor and replace the first line, change it to

1
#!/usr/local/bin/php5.5

The path corresponds to the 1and1 php5.5 path. You can see it by running which php5.5.

Check the path is working fine since it may differ.

Composer

Edit the file composer.json replace the php scripts references to php5.5. Example:

From:

1
2
3
"post-root-package-install": [
    "php -r \"copy('.env.example', '.env');\""
],

To:

1
2
3
"post-root-package-install": [
    "php5.5 -r \"copy('.env.example', '.env');\""
],

Run curl -sS https://getcomposer.org/installer | php5.5 You’ll notice the new file composer.phar

Run php5.5 composer.phar install

Configure

Run php5.5 artisan clear-compiled.

Also run php5.5 artisan optimize.

And cp .env.example .env.

Now run php5.5 artisan key:generate

Fill your .env file with the corresponding values. Check the Laravel site documentation for more information.

I think you should know that for shared hostings plans on 1and1 you won’t be able to use SMTP (in some cases this will work, but in most cases you won’t be able to send mail through SMTP) instead use the PHP’s mail function.

.htaccess

MAKE SURE YOUR DOMAIN HAS ITS ROOT IN THE PUBLIC FOLDER

Replace default setup on your .htaccess file under your public folder with the following.

1
2
3
4
5
6
7
8
RewriteBase /

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

ALL DONE

Navigate to your url and check results.

Posted by Carlo Eduardo Rodríguez Espino