Skip to content

Instantly share code, notes, and snippets.

@nellshamrell
Last active April 10, 2018 21:50
Show Gist options
  • Save nellshamrell/bab52d90c9160e41e2aafbaf99fa8db7 to your computer and use it in GitHub Desktop.
Save nellshamrell/bab52d90c9160e41e2aafbaf99fa8db7 to your computer and use it in GitHub Desktop.

Testing habitat-sh/core-plans#1146

(Manual steps are based on https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-in-ubuntu-16-04)

Creating PHP app

$ mkdir php-test
$ cd php-test
$ vim index.php

index.php

<html>
 <head>
  <title>PHP Test</title>
 </head>
 <body>
 <?php echo '<p>Hello World</p>'; ?> 
 </body>
</html>
$ php -S localhost:8000
  • Push to Github repo
  • Create release on Github

Deploying the app manually

  • Create cloud VM (port 22 and 80 open)
  • SSH into Cloud VM
  • git clone github repo
$ git clone https://github.com/nellshamrell/sample-php-habitat.git

install NGINX

$ sudo apt-get update
$ sudo apt-get install nginx
  • Head to http://<vm_public_ip>
  • And you should see the "Welcome to nginx!" page

install PHP

$ sudo apt-get install php-fpm
  • NOTE - nginx does not run php natively, that is why we need php-fpm

configuring nginx to use php processor

$ sudo vim /etc/nginx/sites-available/default

/etc/nginx/sites-available/default

server {
	listen 80 default_server;
	listen [::]:80 default_server;

	root /var/www/html;

	index index.php index.html index.htm index.nginx-debian.html;

	server_name _;

	location / {
		# First attempt to serve request as file, then
		# as directory, then fall back to displaying a 404.
		try_files $uri $uri/ /index.php$is_args$args;
	}

	# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
	#
	location ~ \.php$ {
		include snippets/fastcgi-php.conf;
		fastcgi_pass unix:/run/php/php7.0-fpm.sock;
	}
}
  • Test config file
$ sudo nginx -t
  • Reload nginx
$ sudo service nginx restart

move PHP file into correct place

$ sudo cp ~/sample-php-habitat/index.php /var/www/html/

Check out the site in your browser and you should see your hello world

Habitizing the app

$ hab plan init
$ vim habitat/plan.sh

plan.sh

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