Skip to content

Instantly share code, notes, and snippets.

@dgoguerra
Last active July 24, 2023 07:28
Show Gist options
  • Save dgoguerra/5bddf0262cc1ac67a9e8 to your computer and use it in GitHub Desktop.
Save dgoguerra/5bddf0262cc1ac67a9e8 to your computer and use it in GitHub Desktop.
Setup steps to serve a Yii 2 webapp in an Amazon EC2 instance with Ubuntu 14.04.

Installation

This file covers all the steps needed to install a web server and Yii 2 framework to host a project in an Ubuntu 14.04 server.

Apache and php installation

First, the packages related to apache and php need to be installed:

sudo apt-get update
sudo apt-get install apache2
sudo apt-get install php5

Then you will need to install and enable GD and Mcrypt extensions:

sudo apt-get install php5-gd
sudo apt-get install php5-mcrypt
sudo php5enmod mcrypt

When installed, restart apache:

sudo service apache2 restart

Set up apache virtual hosts, if needed.

We'll be using apache's vhosts feature, to allow hosting production and development environments in the same server. For that, we are following Digital Ocean's guide to setup vhosts.

TODO: managing /var/www permissions.

Currently, we are using the following permissions:

ls -dl /var/www /var/www/*
drwxr-xr-x  4 root root     4096 Nov  3 09:42 /var/www
drwxrwxr-x 13 USER www-data 4096 Nov  3 10:43 /var/www/app.HOST.COM
drwxrwxr-x 13 USER www-data 4096 Nov  3 10:35 /var/www/dev.HOST.COM

We are going to deploy from a tool such as dploy.io, which needs to have write permissions on the virtual hosts.

Also, since Yii 2 appears to need write permissions too, we need to set www-data as every file's group.

This is a work in progress, currently it appears as if we have to run chgrp -R www-data VHOST after every deploy.

Composer and Yii 2

For this steps I'm following Yii's installation guide.

Install composer globally:

curl -s http://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

Install the composer asset plugin, to manage npm and and bower dependencies:

composer global require "fxp/composer-asset-plugin:1.0.0-beta3"

And finally, install a Yii 2 basic template project:

composer create-project --prefer-dist yiisoft/yii2-app-basic basic
@eduardoliveros
Copy link

what its the dir (route) of the index???

@azazqadir
Copy link

Setting up an EC2 server is quite a task, especially if you have little sysadmin knowledge. It's confusing why people are still doing it manually when they can do it using server management services, like this one: https://www.cloudways.com/en/yii-hosting.php where you can get right down to deploying your app on a pre-installed and pre-configured server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment