how to setup a linux web server and use it to monitor your home speaker: jessica deen – systems...
TRANSCRIPT
How to setup a Linux Web Server and use it to monitor your homeSPEAKER: JESSICA DEEN – SYSTEMS INTEGRATION ENGINEER – SPK AND ASSOCIATES, LLC.
@JLDEEN | JESSICADEEN.COM | [email protected]
About Me
3 Year Microsoft MVP
Current Systems Integration Engineer for SPK and Associates, LLC.
Former Community Engagement Specialist for Windows Client and Windows IT Pro
CompTIA A+, Network +, Security + Certified
Apple Certified Macintosh Technician, Apple Certified Support Professional, Mac Integration Basics Certified
Why Linux?
Cost – Free
Security – Some might argue it’s a stronger OS than Windows considering most viruses are written for the Windows platform
Versatility – It can work on extremely old hardware and requires very little computing power (Raspberry Pi)
Software – The vast majority of Linux software is open source and free. Not only is there a zero cost associated, but you can also usually modify the source code and add more features if you have programming experience
Speed – In many cases, Linux distributions are found to be faster and snappier than Windows and Mac
Building a Web Server - Important Considerations
Cost
Apache HTTP is free
Ubuntu is free
Physical or Virtual?
Is your web server going to be setup with physical infrastructure or using a virtual solution such as VMware ESXi or Hyper-V?
What kind of web site will you be deploying?
PHP based
Python based (Django)
HTML
Microsoft .NET (IIS)
10 Most Popular Linux Distributions
Debian Composed of only free, open sourced software
Ubuntu Debian-based
Linux Mint Built on top of Ubuntu
Fedora Fedora doesn’t make its own desktop environment or
other software. Instead, the Fedora project uses “upstream” software
Comes with GNOME 3, by default
Cent OS / RHEL (Red Hat Enterprise Linux) Commercial Linux Distribution
Intended for servers and workstations
openSUSE / SUSE Linux Enterprise Community created; sponsored by Novell
Mageia / Mandriva Fork of Mandriva Linux created in 2011
Arch Linux Lightweight, minimal
Uses a “rolling release” model
Slackware Linux Oldest distrio that’s still maintained
Puppy Linux Latest version built on Slackware
ISO file is only 161 MB
Desktop Environments
Desktop Environments
Think of them like GUIs
XFCE
Gnome
KDE
Unity
Installed by default in 14.04
Cinnamon
Linux (UNIX) Basics Commands
Man “Manual”
Ls “List”
Equivalent to “dir” in CMD
Pwd “Print Working Directory”
Sudo Think of this as UAC – elevate current user to root permissions for specific
commands
Text Editors: Nano
vim
Linux (UNIX) Basics Commands (Cont’d)
Mv
Move
Cp
Copy
Crontab
Cron Table
Think of it like scheduled tasks on Windows Server
History | grep “search string”
Pipe = Sends data from one program to another
Recommend Code Academy’s “Learn the Command Line” course to become more familiar with CLI
Software Repositories
What are software repositories?
Storage locations from which software packages may be retrieved and installed on a computer.
Each Linux distribution hosts their own software repositories
Installing software on Linux involves package managers and software repositories
Package manager – Think of it like an app store, except they were the original app store.
Example: Sudo apt-get updateExample: Sudo apt-get upgradeExample: Sudo apt-get install gitExample: Sudo apt-get install vim
Updates
Sudo apt-get update
Downloads the package lists from the repositories and "updates" them to get information on the newest versions of packages and their dependencies. It will do this for all repositories and PPAs
Sudo apt-get upgrade
Will fetch new versions of packages existing on the machine if APT knows about these new versions by way of apt-get update
Media
You can get the media for Ubuntu 14.04 LTS (long term support) for free direct from: http://www.ubuntu.com/download/desktop
You can either burn to a disk, create a bootable USB stick, or mount it on a virtual machine
LAMP Stack
LAMP = Linux / Apache / MySQL / PHP
Apache HTTP
Around since 1995
Serves an estimated ~55% of all websites (as of June of 2013)
Can run on Windows, Linux, Mac
MySQL
Open source database
Free
PHP
Server side scripting language for web development
Can also be used as a general-purpose programming language
Install packages
To install all necessary tools for your new Web Server and the Nest Thermostat web monitoring application, we can type everything we need to install in one single command:
sudo apt-get install apache2 mysql-server libapache2-mod-auth-mysql php5 php5-mysql php5-curl php5-json php5-mcrypt git
For Ubuntu 14, type:
Sudo php5enmod mcrypt
Enables mcrypt
Sudo service apache2 restart
Nest Thermostat Web Based Monitoring
git clone https://github.com/f0rkz/Bootstrap-Nest-Administration-Tool
mv Bootstrap-Nest-Administration-Tool Nest_Admin
Proceeding with install
Activate mysql with this command:
sudo mysql_install_db
After you have the pre-requisites installed, you will want to clone the repo into your web directory.
git clone https://github.com/f0rkz/Bootstrap-Nest-Administration-Tool
I also renamed my Bootstrap-Nest-Administration-Tool by typing:
Mv Bootstrap-Nest-Administration-Tool Nest_Admin
Access MySQL
MySQL -u root -p
You should be prompted for a password. This is the root password you created for your MySQL installation
Proceeding with install (Cont’d)
Create the database for information to be stored
create database nest_stats;
grant all privileges on nest_stats.* to nest_stats@localhost identified by ‘some-password’;
exit
mysql -unest_stats -p nest_stats < dbsetup.sql
Run the database query file as the user just created with the password just specified
cp ./includes/nest.conf.php_EXAMPLE nest.conf.php
Note: Make sure the copied file is copied into the includes directory, or you will experience an error later on. After the file is copied, you will edit it with the necessary information and configure your crontab by typing:
Proceeding with install (Cont’d)
Reoccurring task
crontab –e
*/5 * * * * /bin/rm -f /tmp/nest_php_* ; cd /var/www/html/Nest_Admin/includes/scripts/; /usr/bin/php /var/www/html/Nest_Admin/includes/scripts/collect-nest-data.php > /dev/null
Mounting NFS / CIFS Shares
Mount an NFS directory from another machine
mount example.jessicadeen.com:/misc/export /misc/local
Mount a CIFS share
sudo apt-get install cifs-utils
mount -t cifs -o username=USERNAME,password=PASSWD //192.168.1.88/shares /mnt/share
FSTAB
Mount the NFS or CIFS File System using FSTAB so the mount remains after reboot
You must be root to modify the fstab
NFS Example:
Server:/usr/local/pub /pub nfs rszie=8192,wsize=8192,timeo=14,intr
CIFS Example:
//192.168.1.102/misc/export /location/goes/here cifs credentials=/root.smbcredentials.iocharset.utf
//192.168.1.102/Location\040With\040Spaces /local/location/goes_here cifs credentials=/root/.smbcredentials,iocharset=utf8
Store data in /root/.smbcredentials
Username=bob
Password=P@ssw0rd!
Vhost
Virtual hosting
Allows for hosting multiple domain names on a single server
Shared resources for multiple sites
Ubuntu specifically, vhost directory is /etc/apache2/sites-available/
Example:
ServerName democode.cloudapp.net
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/Nest_Admin/web/
Blog
http://www.jessicadeen.com/tech/setup-nest-bootstrap-control-panel/
Deck and notes will be posted on the blog later today
Free trick and tip:
Shortcut to SSH on Windows
Install Cygwin64 with the openssh and client package (bin)
Locate C:\cygwin64\bin\mintty.exe
Create shortcut
Copy shortcut to c:\windows\system32
Renam shortcut to ‘ssh’
Right click properties, change target path to C:\cygwin64\mintty.exe /bin/ssh
Press OK