wiki.allensmith.net

Personal "Rough Notes & Useful Links

User Tools

Site Tools


kb:linux:lts14lxcnginxphp

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

kb:linux:lts14lxcnginxphp [2015/08/17 13:04]
Allen Smith update to what was used
kb:linux:lts14lxcnginxphp [2016/01/13 20:35]
Line 1: Line 1:
-====== Lxc 1.0: Creating an Nginx & PHP Container ====== 
-{{INLINETOC}} 
  
-<​note>​The below **Development Web Server** is intended for use with a [[kb:​linux:​mint17webdevworkstation|Web Development Workstation]] using any 64bit Ubuntu 14.04LTS based Linux (I use Mint 17 Xfce) -- with [[kb:​linux:​lxcdnsinstall|Lxc 1.0 installed & configured to use local DNS]].\\ \\ It should also be noted this container was created to provide (only) what is needed to install then work with DokuWiki.</​note>​ 
- 
-{{page>​data:​kb:​bashprompts&​noheader&​nofooter&​noeditbtn}} 
- 
-**References:​**\\ ​ 
-[[http://​www.2daygeek.com/​install-lemp-server-linux-nginx-mysql-php-in-linux-mint-17-ubuntu-14-04-debian-7-6/​|Install LEMP Server (Linux, Nginx, MySQL & PHP) in Linux Mint 17 / Ubuntu 14.04 / Debian 7.6]]\\ ​ 
-[[https://​nealpoole.com/​blog/​2011/​04/​setting-up-php-fastcgi-and-nginx-dont-trust-the-tutorials-check-your-configuration/​|Setting up PHP-FastCGI and nginx? Don’t trust the tutorials: check your configuration!]] ... I use "''​try_files $uri =404;''"​\\ ​ 
-[[http://​the.binbashtheory.com/​using-overlayfs-with-lxc/​|The /bin/bash Theory -- Using Overlayfs With LXC]] 
- 
-===== Create A 14.04LTS Ubuntu Cloud Container ===== 
-  * The Ubuntu 14.04 LTS Container that I started from was created using the following command:<​code>​ 
-$ sudo su 
-# lxc-create -n 14lts64-nginx -t ubuntu-cloud -- -a amd64 -r trusty 
-</​code>​This produced the following output:<​file>​ 
-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. 
-</​file><​code>​ 
-# exit 
-</​code>​ 
-  * The default user & password for this just created container will be **ubuntu** & **ubuntu** 
- 
-  * Start this just created container & Log-in to it:<​code>​ 
-$ sudo lxc-start -n 14lts64-nginx -d 
-$ sudo lxc-console -n 14lts64-nginx 
-</​code>​ 
-  * Change the default password for the **ubuntu** user:<​code>​ 
-$ passwd 
-</​code>​ 
-    * set the password to something else (and remember it). 
-    * logout & log back in to ensure the password was set correctly. 
- 
-  * Install squid-deb-proxy & update the packages:<​code>​ 
-$ sudo apt-get update 
-$ sudo apt-get install squid-deb-proxy-client 
-$ sudo apt-get upgrade 
-</​code>​ 
-<note important>​If this container was to be used on the Internet, then the one thing I absolutely **would not do** is install the Squid-Deb-Proxy-Client -- which also installs ​ the [[wp>​Avahi_(software)|avahi]] libraries that are required for that to work.</​note>​ 
- 
-===== Initial Install of Nginx ===== 
-<note warning>​Nginx 1.8.0 is **broken**! So the below installs the previous **stable** version of Ubuntu Nginx (1.6.3) by using a different PPA.</​note>​ 
-  * install a current **known working** version of Nginx via a ppa:<​code>​ 
-$ sudo add-apt-repository ppa:​teward/​nginx-1.6.3 
-$ sudo apt-get update 
-$ sudo apt-get install nginx 
-</​code>​which provided the following install information:<​file>​ 
-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]  
-</​file>​ 
-  * Check the version **is** the current version from the PPA:<​code>​ 
-$ nginx -v 
-</​code>​which produces the following output<​file>​ 
-nginx version: nginx/1.6.3 
-</​file>​ 
-  * In Chrome, entering the url  ''​http://​14lts64-nginx.lxc/''​ produces a webpage like this: 
-{{  kb:​linux:​nginx14lts_welcome.png ​ }} 
- 
-  * Change the Nginx configuration file to more reasonable values for a Workstation Container:<​code>​ 
-$ sudo nano /​etc/​nginx/​nginx.conf 
-</​code>​Edit the following lines<​file>​ 
-user www-data; 
-worker_processes 4; 
-pid /​run/​nginx.pid;​ 
-</​file>​ to contain this:<​file>​ 
-user www-data www-data; 
-worker_processes 1; 
-pid /​run/​nginx.pid;​ 
-</​file>​ 
- 
-  * Now restart the nginx  service:<​code>​ 
-$ sudo service nginx restart 
-</​code>​ 
- 
-  * Finally, create a "not the default"​ test file -- to ensure Nginx is really working as expected:<​code>​ 
-$ sudo nano /​var/​www/​html/​test.html ​    # copy the below into this empty file 
-</​code><​file>​ 
-<​html>​ 
-<​head>​ 
- 
-</​head>​ 
-<​body>​ 
-<​h1>​Test File</​h1>​ 
-<p>If this is on the screen, then test.html is working.</​p>​ 
-</​body>​ 
-</​html>​ 
-</​file>​ 
- 
-  * In Chrome, entering the url  ''​http://​14lts64-nginx.lxc/​test.html''​ produces a webpage like this: 
-{{  kb:​linux:​nginx14lts_test.png ​ }} 
- 
-===== Install & Configure PHP ===== 
-  * install php5-fpm:<​code>​ 
-$ sudo apt-get install php5-fpm php5-cli php5-gd php5-mcrypt php5-sqlite 
-</​code>​which provided the following install information:<​file>​ 
-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] 
-</​file>​ 
-  * now configure php5-fpm:<​code>​ 
-$ sudo nano /​etc/​php5/​fpm/​php.ini 
-</​code>​change this line in the file:<​file>​ 
-;​cgi.fix_pathinfo=1 
-</​file>​to the following:<​file>​ 
-cgi.fix_pathinfo=0 
-</​file>​ 
-  * finally, restart the php5-fpm service:<​code>​ 
-$ sudo service php5-fpm restart 
-</​code>​ 
- 
-===== Configure Nginx to use PHP-FPM ===== 
-  * create the configuration file for a Nginx virtual server (14lts64-nginx) using php-fpm:<​code>​ 
-$ sudo nano /​etc/​nginx/​sites-available/​virtual ​    # copy the below into this empty file 
-</​code><​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;​ 
-        } 
-} 
-</​file>​ 
-  * Remove the ''​default''​ configuration,​ and instead use the configuration for the ''​virtual''​ server<​code>​ 
-$ sudo rm /​etc/​nginx/​sites-enabled/​default 
-$ sudo ln -s /​etc/​nginx/​sites-available/​virtual /​etc/​nginx/​sites-enabled 
-</​code>​ 
-  * Now restart the nginx & php-fpm services:<​code>​ 
-$ sudo service nginx restart 
-$ sudo service php5-fpm restart 
-</​code>​ 
- 
-  * To test that .php pages are working, create a single line page to display the PHP info:<​code>​ 
-$ sudo nano /​var/​www/​html/​index.php ​    # copy the below into this empty file 
-</​code><​file>​ 
-<?php phpinfo(); ?> 
-</​file>​ 
- 
-  * http://​14lts64-nginx.lxc/ ​ ← now shows a detailed PHP Information page (using the above index.php) 
-{{  kb:​linux:​nginx14lts_phpinfo.png ​ }} 
- 
-  * http://​14lts64-nginx.lxc/​test.html/​index.php ← returns a 404 error as it should. 
- 
-===== Optional Additional Configurations ===== 
-  * Add the default user **''​ubuntu''​** to the group www-data<​code>​$ sudo usermod -a -G www-data ubuntu</​code>​ 
- 
-  * Add the ssh Public/​Private keys to use **''​rsync''​** or **''​sftp''​** to upload and download files directly to/from the Lxc Container. 
- 
- 
-===== Snapshot (snap0) of the "​14lts64-nginx"​ Container ===== 
-  * Stop 14lts64-nginx and take a snapshot of it:<​code>​ 
-$ 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 
-</​code><​file>​ 
-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. 
-</​file>​ 
-  * List the snapshots w/ any comments:<​code>​ 
-# lxc-snapshot -n 14lts64-nginx -LC     # example output below 
-</​code><​file>​ 
-snap0 (/​var/​lib/​lxcsnaps/​14lts64-nginx) 2015:05:20 16:18:19 
-Nginx w/ php-fpm just installed & configured 
-</​file>​ 
-  * now delete the text file created to hold the above comment:<​code>​ 
-# rm snapshot-comment.txt 
-# exit 
-</​code>​ 
- 
-===== Development Containers from  this Preconfigured Container ===== 
- 
-<​note>​The message output while making a snapshot of the 14lts64-nginx container is the "​Executive Summary"​ for how this container should be used.</​note>​ 
-  * This container is now **frozen** and **should never be used** or logged into again! In fact, the only reason to have a snapshot of this container, is to enable putting it back to **exactly** the way it is now -- should anything happen that changes this Lxc Container that has been Preconfigured with Nginx using php-fpm. 
-  * The **''​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. ​ 
-<note tip>​**Overlayfs** creates a single unified view of two separate directory trees. ​ One directory tree is of the "​lower"​ filesystem -- such as the filesystem of a frozen Preconfigured Container -- which is utilized in a read-only manner. ​ The second directory tree is of the "​upper"​ filesystem -- such as the filesystem of a Development Container -- which provides the read-write media.\\ \\ As such, all changes are **stored only** in this "​upper"​ filesystem. Then any original (unchanged) version of the same file in the “lower” files is **hidden** just by having a changed "​upper"​ version of that file … which works something like putting an “upper” playing card on top of a “lower” playing card. (Use a blank card on top to delete a file.) 
-</​note>​ 
-  * As Example: the Summary Notes for [[kb:​linux:​lts14lxcnginxphpdokuwiki|DokuWiki in an Nginx & PHP Container]] use the following command to create the **''​dokuwiki''​** container -- so the DokuWiki package can then be installed & configured in this clone of the **''​14lts64-nginx''​** container<​code>​ 
-#  lxc-clone -o 14lts64-nginx -n dokuwiki -B overlayfs -s 
-</​code>​ 
-  * This use of the Overlayfs for Development Containers also enables truly useful Snapshots -- where each snapshot also records **only the changes** that have been made. 
- 
-==== Naming of Preconfigured Containers and Development Containers ==== 
- 
-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** 
-  * In the above **''​14lts64''​** is how I designate any Ubuntu 14.04 LTS 64bit container. (I would use **''​12lts64''​** for Ubuntu 12.04 64bit) 
-  * Any Preconfigured Container -- that I create Development Containers from -- will **always** start with an OS designation. 
-  * These are the "​frozen"​ ext4 filesystem based containers that **should never be used**. 
-  * The only reason to have **one snapshot** of a Preconfigured Container is to enable restoring it to **exactly** how it was "​frozen"​. 
-for overlayfs **Development Containers** 
-  * These are named using some combination of an Application (possibly with a version designation) and/or a Project or Site. 
-  * Development Containers **never** contain one of the (above) "​frozen"​ OS designations anywhere in the container name. 
-  * These are the Overlayfs based containers that are "​created & destroyed"​ to be "used & abused"​ for Development Work. 
kb/linux/lts14lxcnginxphp.txt · Last modified: 2016/01/13 20:35 (external edit)