References:
Install LEMP Server (Linux, Nginx, MySQL & PHP) in Linux Mint 17 / Ubuntu 14.04 / Debian 7.6
Setting up PHP-FastCGI and nginx? Don’t trust the tutorials: check your configuration! … I use “try_files $uri =404;
“
The /bin/bash Theory -- Using Overlayfs With LXC
$ sudo su # lxc-create -n 14lts64-nginx -t ubuntu-cloud -- -a amd64 -r trusty
This produced the following output:
ubuntu-cloudimg-query is /usr/bin/ubuntu-cloudimg-query wget is /usr/bin/wget --2015-05-20 13:20:58-- https://cloud-images.ubuntu.com/server/releases/trusty/release-20150506/ubuntu-14.04-server-cloudimg-amd64-root.tar.gz Resolving cloud-images.ubuntu.com (cloud-images.ubuntu.com)... 91.189.88.141, 2001:67c:1360:8001:ffff:ffff:ffff:fffe Connecting to cloud-images.ubuntu.com (cloud-images.ubuntu.com)|91.189.88.141|:443... connected. HTTP request sent, awaiting response... 302 Found Location: https://cloud-images.ubuntu.com/releases/trusty/release-20150506/ubuntu-14.04-server-cloudimg-amd64-root.tar.gz [following] --2015-05-20 13:20:59-- https://cloud-images.ubuntu.com/releases/trusty/release-20150506/ubuntu-14.04-server-cloudimg-amd64-root.tar.gz Reusing existing connection to cloud-images.ubuntu.com:443. HTTP request sent, awaiting response... 200 OK Length: 186816043 (178M) [application/x-gzip] Saving to: ‘ubuntu-14.04-server-cloudimg-amd64-root.tar.gz’ 100%[==========================================================>] 186,816,043 1.02MB/s in 2m 18s 2015-05-20 13:23:17 (1.29 MB/s) - ‘ubuntu-14.04-server-cloudimg-amd64-root.tar.gz’ saved [186816043/186816043] Extracting container rootfs perl: warning: Setting locale failed. perl: warning: Please check that your locale settings: LANGUAGE = "en_CA:en", LC_ALL = (unset), LANG = "en_CA.UTF-8" are supported and installed on your system. perl: warning: Falling back to the standard locale ("C"). locale: Cannot set LC_CTYPE to default locale: No such file or directory locale: Cannot set LC_MESSAGES to default locale: No such file or directory locale: Cannot set LC_ALL to default locale: No such file or directory Current default time zone: 'America/Toronto' Local time is now: Wed May 20 13:23:25 EDT 2015. Universal Time is now: Wed May 20 17:23:25 UTC 2015. Container 14lts64-nginx created.
# exit
$ sudo lxc-start -n 14lts64-nginx -d $ sudo lxc-console -n 14lts64-nginx
$ passwd
$ sudo apt-get update $ sudo apt-get install squid-deb-proxy-client $ sudo apt-get upgrade
$ sudo add-apt-repository ppa:teward/nginx-1.6.3 $ sudo apt-get update $ sudo apt-get install nginx
which provided the following install information:
The following NEW packages will be installed: fontconfig-config fonts-dejavu-core libfontconfig1 libgd3 libjbig0 libjpeg-turbo8 libjpeg8 libtiff5 libvpx1 libxpm4 libxslt1.1 nginx nginx-common nginx-full 0 upgraded, 14 newly installed, 0 to remove and 0 not upgraded. Need to get 2,784 kB of archives. After this operation, 9,037 kB of additional disk space will be used. Do you want to continue? [Y/n]
$ nginx -v
which produces the following output
nginx version: nginx/1.6.3
http://14lts64-nginx.lxc/
produces a webpage like this:$ sudo nano /etc/nginx/nginx.conf
Edit the following lines
user www-data; worker_processes 4; pid /run/nginx.pid;
to contain this:
user www-data www-data; worker_processes 1; pid /run/nginx.pid;
$ sudo service nginx restart
$ sudo nano /var/www/html/test.html # copy the below into this empty file
<html> <head> </head> <body> <h1>Test File</h1> <p>If this is on the screen, then test.html is working.</p> </body> </html>
http://14lts64-nginx.lxc/test.html
produces a webpage like this:$ sudo apt-get install php5-fpm php5-cli php5-gd php5-mcrypt php5-sqlite
which provided the following install information:
The following NEW packages will be installed: libmcrypt4 php5-cli php5-common php5-fpm php5-gd php5-json php5-mcrypt php5-readline php5-sqlite 0 upgraded, 9 newly installed, 0 to remove and 0 not upgraded. Need to get 4,973 kB of archives. After this operation, 20.4 MB of additional disk space will be used. Do you want to continue? [Y/n]
$ sudo nano /etc/php5/fpm/php.ini
change this line in the file:
;cgi.fix_pathinfo=1
to the following:
cgi.fix_pathinfo=0
$ sudo service php5-fpm restart
$ sudo nano /etc/nginx/sites-available/virtual # copy the below into this empty file
## # You should look at the following URL's in order to grasp a solid understanding # of Nginx configuration files in order to fully unleash the power of Nginx. # http://wiki.nginx.org/Pitfalls # http://wiki.nginx.org/QuickStart # http://wiki.nginx.org/Configuration # # Generally, you will want to move this file somewhere, and start with a clean # file but keep this around for reference. Or just disable in sites-enabled. # # Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples. ## # Default server configuration # server { listen 80 default_server; listen [::]:80 default_server; # SSL configuration # # listen 443 ssl default_server; # listen [::]:443 ssl default_server; # # Self signed certs generated by the ssl-cert package # Don't use them in a production server! # # include snippets/snakeoil.conf; root /var/www/html; # Add index.php to the list if you are using PHP index index.php index.html index.htm; server_name 14lts64-nginx.lxc; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; } location ~ /\.ht { # deny access to .htaccess files, if Apache's document root # concurs with nginx's one deny all; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { try_files $uri =404; # # With php5-cgi alone: # fastcgi_pass 127.0.0.1:9000; # With php5-fpm: fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
default
configuration, and instead use the configuration for the virtual
server$ sudo rm /etc/nginx/sites-enabled/default $ sudo ln -s /etc/nginx/sites-available/virtual /etc/nginx/sites-enabled
$ sudo service nginx restart $ sudo service php5-fpm restart
$ sudo nano /var/www/html/index.php # copy the below into this empty file
<?php phpinfo(); ?>
ubuntu
to the group www-data$ sudo usermod -a -G www-data ubuntu
rsync
or sftp
to upload and download files directly to/from the Lxc Container.$ sudo su # lxc-stop -n 14lts64-nginx # echo 'Nginx w/ php-fpm just installed & configured' >snapshot-comment.txt # lxc-snapshot -n 14lts64-nginx -c snapshot-comment.txt # output below
lxc_container: Snapshot of directory-backed container requested. lxc_container: Making a copy-clone. If you do want snapshots, then lxc_container: please create an aufs or overlayfs clone first, snapshot that lxc_container: and keep the original container pristine.
# lxc-snapshot -n 14lts64-nginx -LC # example output below
snap0 (/var/lib/lxcsnaps/14lts64-nginx) 2015:05:20 16:18:19 Nginx w/ php-fpm just installed & configured
# rm snapshot-comment.txt # exit
lxc-clone
command will now be used to create Development Containers using the Overlayfs – where only the changes made to this base/master/starting container are actually stored by the file-system for these cloned containers. dokuwiki
container – so the DokuWiki package can then be installed & configured in this clone of the 14lts64-nginx
container# lxc-clone -o 14lts64-nginx -n dokuwiki -B overlayfs -s
To effectively implement the above, there needs to be some way to know which containers are the “Preconfigured Containers” and which containers are the “Development Containers”. I use the following container name hints to make this immediately obvious on my own Development Workstation:
for ext4 Filesystem Preconfigured Containers
14lts64
is how I designate any Ubuntu 14.04 LTS 64bit container. (I would use 12lts64
for Ubuntu 12.04 64bit)for overlayfs Development Containers