Here are the steps I took to get a Laravel project up and running on MediaTemple’s Grid Service. At the time of this writing, I was using Laravel 5.2.29.
Throughout this tutorial, I’ll use some example values so I don’t have to provide my own info. The GRID server will use 123456 as it’s id, which gets used in a number of places. I’ll use example.com as the domain you’ll be installing Laravel to.
SSH to your GRID server
Open your GRID Control Panel and select View Your Guide from the Server Guide panel. You’ll see the Access Domain listed there under the Domains heading. Scrolling down, you’ll find the SSH heading where you can see the Server Administrator Username and change it’s password if you need to. Make note of this info or keep that page open to use for reference later.
SSH to your server using the SSH Server Administrator Username and the gridserver Access Domain.
marty$ ssh example.com@s123456.gridserver.com
The authenticity of host 's123456.gridserver.com (205.186.179.218)' can't be established.
RSA key fingerprint is f3:12:b3:42:cb:02:b9:99:07:d2:5b:c4:4d:42:6e:eb.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 's123456.gridserver.com' (RSA) to the list of known hosts.
Password:
You must use the administrator SSH account to connect via SSH. If you use the link in the Server Guide panel to Add/Edit FTP & SSH Users, those users will not have access to the domains folder. Don’t ask my why you would add an SSH user that couldn’t access anything outside it’s home directory but it’s irrelevant. You’ll probably need to accept the connection if it’s new. The password here is the password you would have set for the Server Administrator Username you saw in the View Your Guide page, not your MediaTemple login.
You need to be sure you’re using the latest PHP version and you can check that with php -v
. If your php version doesn’t meet the minimum requirements, you can set it in the control panel. If the php version used in your current SSH session is not the latest, you can set the version used in your SSH session by creating a .bash_profile
file in the home directory. At the time of this writing, the latest available on MediaTemple was 5.5.31.
Git your project files
If you have your Laravel site already created you can get your files up on the server the traditional ftp way but Git is available on the servers so if your project is stored in Git (recommended) then you can have a nice way to keep it up to date by checking out the master branch. NOTE: The version of Git installed on the shared server I am using is 1.7.10.4, which was released back in 2012. This is incredibly disappointing to me and their support says they have no plans to update it.
Since you already have a folder in the domains folder named after your domain, you can back it up using the mv command. Change to your domains folder, backup your existing domain folder and clone your project using
example.com@n11:~$ cd domains
example.com@n11:~/domains$ mv example.com example.com.backup
example.com@n11:~/domains$ git clone https://github.com/Username/projectName.git example.com
You’ll be prompted for your GitHub username and password. Enter those and it will download your project files into the domain folder.
Install Composer
To get composer, you will probably need to add these lines to your php.ini file.
# allows php to open urls
allow_url_fopen = On
open_basedir = ""
Now, you’ll be able to download composer. You can use this post for great instructions on how to accomplish this: https://forum.mediatemple.net/topic/6927-here-is-how-to-install-and-use-composer/
In a nutshell, you’ll use these command after changing into the example.com folder.
example.com@n11:~/domains$ cd example.com
example.com@n11:~/domains/example.com$ php -r "readfile('https://getcomposer.org/installer');" > composer-setup.php
php -r "if (hash('SHA384', file_get_contents('composer-setup.php')) === '7228c001f88bee97506740ef0888240bd8a760b046ee16db8f4095c0d8d525f2367663f22a46b48d072c816e7fe19959') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
Composer should download and successfully install.
If you try something like php composer.phar self-update
and if it doesn’t work, check that it has executable permissions by using chmod +x composer.phar
.
Now you should be able to use php composer.phar install, right? In my case, no. I received this error when using composer install:
[ErrorException]
is_dir(): open_basedir restriction in effect. File(/etc/pki/tls/certs) is not within the allowed path(s): (/nfs:/tmp:/usr/local:/etc/apache2/gs-bin)
To solve that error, I had to change the open_basedir setting in the /etc/php.ini to open_basedir = ""
. I mentioned adding this at the beginning of this section.
Now you have to get the ca-certificate. This post gave me the info: https://github.com/composer/composer/issues/2798
example.com@n11:~/domains$ wget http://curl.haxx.se/ca/cacert.pem
example.com@n11:~/domains$ wget https://github.com/bagder/ca-bundle/blob/master/ca-bundle.crt
Then add these lines to the bottom of the php.ini
file. You can use the File Manager to accomplish this. See https://mediatemple.net/community/products/grid/204403894/how-can-i-edit-the-php.ini-file for more details on how to edit the php.ini file.
# Cert locations
curl.cainfo=/home/123456/domains/ca-bundle.crt
openssl.cafile=/home/123456/domains/cacert.pem
We also need to set some environment variables since composer doesn’t seem to pick up the cert location from the php.ini
. I’m a little fuzzy on this stuff so perhaps the previous step isn’t actually needed..? Open ~/.bash_profile
on the server and add the following lines
export SSL_CERT_FILE=/home/123456/domains/example.com/cacert.pem
export SSL_CERT_DIR=/home/123456/domains/example.com/
# also, be sure you have an alias to composer
These commands set the environment variables so composer knows where to find them. The following command makes them active in your current session.
example.com@n11:~/domains$ source ~/.bash_profile
At this point, I was able to use composer install and it worked, almost.
example.com@n11:~/domains/example.com$ php composer.phar install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Nothing to install or update
Generating autoload files
> Illuminate\Foundation\ComposerScripts::postInstall
> php artisan optimize
Parse error: syntax error, unexpected T_CLASS, expecting T_STRING or T_VARIABLE or '$' in /nfs/c08/h03/mnt/118186/domains/example.com/artisan on line 31
Script php artisan optimize handling the post-install-cmd event returned with an error
[RuntimeException]
Error Output:
install [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--no-plugins] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--ignore-platform-reqs] [--] [<packages>]...
Everything seemed to go okay until that last bit there where php artisan optimize fails. After that ran, I just ran php artisan optimize
and it worked fine. I don’t know much more about that error since it didn’t cause any issues after that.
You need to create a symbolic link to the public
directory named html
since that is the default directory MediaTemple uses.
example.com@n11:~/domains/example.com$ ln -s public html
Now if you cd html
, it should take you to the public
folder.
Create your database
Make your database from the MediaTemple admin. From the Grid control panel it’s in the lower left under Databases. Use the Manage Databases link to view your databases and add a new one. Let’s say you call it “exampledb”. You’ll probably end up with something like db123456_exampledb. You’ll need the database internal hostname which probably looks something like internal-db.s123456.gridserver.com. You can find that on the Users & Settings link at the top. Put the internal hostname, username and password into the .env
file. You will probably have to copy the .env.example
file as .env
. I also had to set CACHE_DRIVER=array in the .env file.
example.com@n11:~/domains/example.com$ cp .env.example .env
example.com@n11:~/domains/example.com$ nano .env
After you’ve made the changes, use ^O to save the file, then ^X to exit. To populate the APP_KEY in the .env file, use the standard laravel artisan command.
example.com@n11:~/domains/example.com$ php artisan key:generate
Then migrate.
example.com@n11:~/domains/example.com$ php artisan migrate
Test your site
At this point, your Laravel application should show and run correctly.
Figuring all this out took hours online with MediaTemple support and searching the web for clues to each problem I ran into. Hopefully, this can save you some time. Please comment if there is a mistake in the steps. I bounced around so much, I wouldn’t be surprised if I missed a step when writing the blog post.