<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Postpostmodern &#187; PHP</title>
	<atom:link href="http://postpostmodern.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://postpostmodern.com</link>
	<description>Speaking of web development.</description>
	<lastBuildDate>Wed, 11 Jan 2012 00:21:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Slicehost (and Linode) LAMP Cheatsheet</title>
		<link>http://postpostmodern.com/instructional/slicehost-and-linode-lamp-cheatsheet/</link>
		<comments>http://postpostmodern.com/instructional/slicehost-and-linode-lamp-cheatsheet/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 23:51:35 +0000</pubDate>
		<dc:creator>Jason Johnson</dc:creator>
				<category><![CDATA[Instructional]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Deployment]]></category>
		<category><![CDATA[LAMP]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Postfix]]></category>
		<category><![CDATA[Slicehost]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://postpostmodern.com/?p=120</guid>
		<description><![CDATA[A quick list of steps I use to set up a LAMP server on Slicehost or Linode.]]></description>
			<content:encoded><![CDATA[<p>I have set up several <a href="http://slicehost.com">Slicehost</a> slices as Ubuntu LAMP servers, but since I&#8217;m not a server admin, I always have to reference the tutorials to remember the steps. So, I&#8217;ve compiled the list of steps here, as concisely as possible. This process sets up everything you need for hosting multiple sites on a single server, and it works equally well for most servers running Ubuntu including <a href="http://slicehost.com">Slices</a> and <a href="http://linode.com">Linodes</a>.</p>

<dl>
  <dt>Disclaimer</dt>
  <dd>Please use these only if you already know the whys and wherefores. If you don&#8217;t generally understand one or more of these steps, <strong><em>consult the <a href="http://articles.slicehost.com/ubuntu-intrepid">Slicehost Articles</a> or the <a href="http://library.linode.com/lamp-guides/">Linode Articles</a> before asking questions here</em></strong>. Most of the information here comes from the <a href="http://articles.slicehost.com/ubuntu-intrepid">Slicehost Articles for Ubuntu</a>. I have also added a few extra steps from sources cited in the footnotes.</dd>
  <dt>Helping Me Out</dt>
  <dd>If you need to sign up for a Slicehost or Linode account, and you plan on using this article as a guide to configure your server, please use these referral links:
    <ul>
      <li><del datetime="2011-10-01T18:19:12+00:00">Sign up for a Slicehost account</del> <ins style="display: inline; border: 0; padding: 0; margin: 0;" datetime="2011-10-01T18:19:12+00:00">(I no longer use Slicehost.)</ins></li>
      <li><a href="http://www.linode.com/?r=1eadb325010c5678e5e5af3cd16505bf6bb5be00">Sign up for a Linode account</a></li>
    </ul>
  </dd>
  <dd>Corrections to this article are also appreciated. Please note, however, that corrections != personal preference. If you have a different way of doing something, you&#8217;ll need to present a convincing case as to why it is better.</dd>
  <dt>Assumptions</dt>
  <dd>This guide/cheatsheet assumes you have already created a virtual server with Ubuntu installed.</dd>
  <dd>You should also set up your DNS. If you&#8217;re using Slicehost, my <a href="http://github.com/postpostmodern/slicehost-dns">Slicehost DNS</a> script will help.</dd>
  <dt>Conventions</dt>
  <dd>For this article, I&#8217;m using:
    <ul>
      <li><code>xxx.xxx.xxx.xxx</code> to indicate the IP address of your server</li>
      <li><code>bob</code> as the server&#8217;s name (hostname)</li>
      <li><code>example.com</code> as the domain name</li>
      <li><code>demo</code> as the admin user</li>
      <li><code>nano</code> as my editor because I have no vi skills.</li>      
    </ul>
  </dd>
</dl>

<h2>Configure Server for Terminal.app (Mac users only)</h2>

<p>Terminal.app behaves as dtterm, but Ubuntu doesn&#8217;t have the dtterm entry in its terminfo database. This fixes that.<sup><a href="#footnote-1-120" id="footnote-link-1-120" title="See the footnote.">1</a></sup></p>

<h3>Save Terminal Info to a File</h3>

<p><em>On your Mac (local machine)&#8230;</em></p>

<ol>
<li><kbd class="block">infocmp > /tmp/dtterm</kbd></li>
<li><kbd class="block">scp /tmp/dtterm root@xxx.xxx.xxx.xxx:/tmp</kbd></li>
</ol>

<h3>Import Terminal Info</h3>

<ol>
<li>Log into your server as root</li>
<li><kbd class="block">tic /tmp/dtterm</kbd></li>
</ol>

<h2>Some Basic Package Setup</h2>

<h3>Aptitude Upgrade</h3>

<p><em>Still logged in as root&#8230;</em></p>

<ol>
<li>Make sure you have access to the universe repositories
<kbd class="block">nano /etc/apt/sources.list</kbd>
and uncomment the universe repositories</li>
<li>Update<br />
<kbd class="block">aptitude update</kbd></li>
<li>Upgrade<br />
<kbd class="block">aptitude safe-upgrade 
aptitude full-upgrade</kbd></li>
</ol>

<h3>Install Build Essentials</h3>

<ol>
<li>Install<br />
<kbd class="block">aptitude install build-essential</kbd></li>
</ol>

<h3>Install CURL</h3>

<ol>
<li>Install<br />
<kbd class="block">aptitude install curl</kbd></li>
<li>Install ca-certificates for ssl connections
<kbd class="block">aptitude install ca-certificates</kbd></li>
</ol>

<h2>SSH and Users</h2>

<h3>Create New User and Allow sudo</h3>

<p><em>Still logged in as root&#8230;</em></p>

<ol>
<li>Change root password, if desired
<kbd class="block">passwd</kbd></li>
<li>Add user<br />
<kbd class="block">adduser demo</kbd></li>
<li>Set up sudo config<br />
<kbd class="block">visudo</kbd> and add <code>demo ALL=(ALL) ALL</code> to the end</li>
<li>Log out or switch to your local machine</li>
</ol>

<h3>Set up SSH Keys</h3>

<ol>
<li><em>On your local machine</em>, copy local public ssh key to server (assuming you have already created your public key on your local machine)
<kbd class="block">scp ~/.ssh/id_rsa.pub demo@xxx.xxx.xxx.xxx:/home/demo/</kbd></li>
<li>Switch back to your server or log back in as root</li>
<li>Create authorized_keys file<br />
<kbd class="block">cd /home/demo
mkdir .ssh 
mv id_rsa.pub .ssh/authorized_keys</kbd></li>
<li>Set permissions
<kbd class="block">chown -R demo:demo .ssh
chmod 700 .ssh
chmod 600 .ssh/authorized_keys
</kbd></li>
</ol>

<h3>Configure sshd</h3>

<ol>
<li>Open sshd_config  
<kbd class="block">nano -w /etc/ssh/sshd_config</kbd></li>
<li>Set these:  
<pre><code lang="bash">Port 30000 (change to a port of your choosing)
Protocol 2
PermitRootLogin no
PasswordAuthentication no
X11Forwarding no
UsePAM no
UseDNS no
AllowUsers demo</code></pre>
</li>
</ol>

<h3>Setup iptables</h3>

<ol>
<li>Dump existing rules  
<kbd class="block">cd /etc 
iptables-save > iptables.up.rules</kbd></li>
<li>Copy rules file from Slicehost example  
<kbd class="block">curl -o iptables.test.rules http://articles.slicehost.com/assets/2007/9/4/iptables.txt</kbd></li>
<li>Edit it and set port number for sshd
<kbd class="block">nano -w iptables.test.rules</kbd></li>
<li>Load it  
<kbd class="block">iptables-restore < iptables.test.rules</kbd></iptables>
<li>Check the new rules  
<kbd class="block">iptables -L</kbd></li>
<li>Save the new rules  
<kbd class="block">iptables-save > iptables.up.rules</kbd></li>
<li>Make sure the new rules are read every time  
<kbd class="block">nano -w network/interfaces</kbd> and make it look like this:  
<pre><code lang="bash">...
auto lo
iface lo inet loopback
pre-up iptables-restore < /etc/iptables.up.rules

# The primary network interface
...</code></pre>
</li>
</ol>

<h3>Restart and Test sshd</h3>

<ol>
<li>Reload sshd<br />
<kbd class="block">/etc/init.d/ssh reload</kbd></li>
<li>Try to log in from another terminal</li>
<li>If successful, logout</li>
</ol>

<h2>User Config</h2>

<p><em>Logged in as demo...</em></p>

<h3>Configure Nano</h3>

<ol>
<li>Set some configuration
<kbd class="block">cp /etc/nanorc ~/.nanorc
nano -w ~/.nanorc</kbd></li>
<li>Uncomment these lines:<br />
<code># set brackets ""')&gt;]}"</code><br />
<code># set nowrap</code>  (should be set by default in recent versions)
<code># set tabsize 8</code></li>
<li>Change tabsize to 2 or 4 or something:<br />
<code>set tabsize 4</code></li>
</ol>

<h3>Add Bash Aliases</h3>

<ol>
<li>Create aliases file <kbd class="block">nano -w .bash_aliases</kbd> and add:
<pre><code lang="bash">alias lo='logout'
alias mksite='sudo /usr/local/a2mksite/a2mksite.sh'
alias free='free -m'
alias ag='sudo apache2ctl graceful'
if [ "$TERM" != "dumb" ] &#038;&#038; [ -x /usr/bin/dircolors ]; then
    eval "`dircolors -b`"
    alias ls='ls -la --color=auto'
fi

# Git
alias gst='git status'
# alias gl='git pull'
alias ga='git add'
alias gp='git push'
alias gd='git diff | mate'
alias gc='git commit -v'
alias gca='git commit -v -a'
alias gb='git branch'
alias gba='git branch -a'
alias gco='git checkout'
alias glog='git log --pretty=format:"# %aD : %an%n%n* %s%n%n%b%n"'
alias glt='glog --since=yesterday'
alias gly='glog --since="2 days ago" --until="1 day ago"'</code></pre>
</li>
<li>If necessary, activate aliases in .bashrc <kbd class="block">nano -w .bashrc</kbd> and uncomment the part that loads .bash_aliases</li>
<li>Get the aliases working <kbd class="block">source ~/.bashrc</kbd></li>
</ol>

<h2>Basic Server Config</h2>

<h3>Set Hostname<sup><a href="#footnote-2-120" id="footnote-link-2-120" title="See the footnote.">2</a></sup></h3>

<ol>
<li>Name your server by setting a short hostname in /etc/hostname 
<kbd class="block">sudo nano /etc/hostname</kbd>
and type <code>bob.example.com</code></li>
<li>Set the fully-qualified domain name in hosts<br />
<kbd class="block">sudo nano /etc/hosts</kbd> 
and add <code>xxx.xxx.xxx.xxx    bob.example.com    bob</code><br />
below the <code>127.0.0.1 localhost</code> entry</li>
<li>Reboot
<kbd class="block">sudo reboot</kbd></li>
<li>Check hostname<br />
<kbd class="block">hostname</kbd></li>
<li>Check FQDN<br />
<kbd class="block">hostname -f</kbd></li>
</ol>

<h3>Set Locale</h3>

<ol>
<li>Generate locale info<br />
<kbd class="block">sudo locale-gen en_US.UTF-8</kbd></li>
<li>Update locale<br />
<kbd class="block">sudo /usr/sbin/update-locale LANG=en_US.UTF-8</kbd></li>
</ol>

<h3>Set Timezone</h3>

<ol>
<li>Start up timezone configurator and follow instructions<br />
<kbd class="block">sudo dpkg-reconfigure tzdata</kbd></li>
</ol>

<h2>Git</h2>

<h3>Install Git</h3>

<ol>
<li>Install<br />
<kbd class="block">sudo aptitude install git-core</kbd></li>
</ol>

<h2>Subversion</h2>

<h3>Install svn</h3>

<ol>
<li>Install<br />
<kbd class="block">sudo aptitude install subversion</kbd></li>
</ol>

<h2>Web Server</h2>

<h3>Install a2mksite</h3>

<p>a2mksite is a script that I wrote that allows you to create an Apache virtual host with one command (including the document root, config files, log rotation, etc). One thing you should know is that it creates a directory structure for multiple web sites (virtual hosts), placing each site's public and log directories in its own directory like so: <code>/var/www/sites/example.com</code></p>

<p>Read the <a href="http://github.com/postpostmodern/a2mksite">description here</a> to learn more about what it does.</p>

<ol>
<li>Clone a2mksite from Github
<kbd class="block">git clone git://github.com/postpostmodern/a2mksite.git</kbd></li>
<li>Move it to /usr/local
<kbd class="block">sudo mv a2mksite /usr/local</kbd></li>
<li>CHOWN it to root
<kbd class="block">sudo chown 0:0 /usr/local/a2mksite</kbd></li>
<li>Make sure you have the script aliased as <code>mksite</code> in your <code>.bash_aliases</code> file (see Bash Aliases snippet earlier in this post).</li>
</ol>

<h3>Install Logrotate</h3>

<ol>
<li>Install<br />
<kbd class="block">sudo aptitude install logrotate</kbd></li>
</ol>

<h3>Install Apache</h3>

<ol>
<li>Install
<kbd class="block">sudo aptitude install apache2 apache2.2-common apache2-mpm-prefork apache2-utils libexpat1 ssl-cert</kbd></li>
<li>Set up basic config using <a href="http://gist.github.com/236374">my httpd.conf</a> as an example
<kbd class="block">wget https://raw.github.com/gist/236374/httpd.conf
sudo mv httpd.conf /etc/apache2/httpd.conf
sudo nano /etc/apache2/httpd.conf</kbd></li>
<li>Enable Modules<br />
<kbd class="block">sudo a2enmod auth_digest dav dav_lock rewrite</kbd></li>
<li>Create errors dir<br />
<kbd class="block">sudo mkdir /var/www/errors</kbd></li>
<li>Create maintenance dir<br />
<kbd class="block">sudo mkdir /var/www/maintenance</kbd></li>
<li>CHOWN them<br />
<kbd class="block">sudo chown -R demo:demo /var/www/errors /var/www/maintenance</kbd></li>
<li>Create global 404<br />
<kbd class="block">nano -w /var/www/errors/404.html</kbd></li>
<li>Create maintenance page<br />
<kbd class="block">nano -w /var/www/maintenance/index.html</kbd></li>
<li>Make default site<br />
<kbd class="block">mksite default</kbd>
and overwrite the original default</li>
</ol>

<h2>MySQL</h2>

<h3>Install MySQL</h3>

<ol>
<li>Install<br />
<kbd class="block">sudo aptitude install mysql-server mysql-client libmysqlclient15-dev</kbd></li>
<li>Set root password (follow instructions during installation)</li>
</ol>

<h2>PHP</h2>

<h3>Install PHP</h3>

<ol>
<li>Install PHP
<kbd class="block">sudo aptitude install libapache2-mod-php5 php5 php5-common php5-curl php5-dev php5-gd php5-imagick php5-mcrypt php5-memcache php5-mhash php5-mysql php5-pspell php5-snmp php5-sqlite php5-xmlrpc php5-xsl php5-xcache</kbd></li>
<li>Edit xcache.ini
<kbd class="block">sudo nano /etc/php5/apache2/conf.d/xcache.ini</kbd>
and set <code>xcache.var_size</code> to something other than zero</li>
<li>Edit php.ini
<kbd class="block">sudo nano /etc/php5/apache2/php.ini</kbd>
and set error output, max upload size, etc.</li>
<li>Restart Apache
<kbd class="block">sudo /etc/init.d/apache2 restart</kbd></li>
</ol>

<h2>Mail (for sending via PHP)</h2>

<h3>Reverse DNS</h3>

<ol>
<li>Set Reverse DNS in SliceManager or Linode Manager to your server's FQDN, i.e. what you see when you type <kbd>hostname -f</kbd></li>
<li>Check it<br />
<kbd class="block">sudo aptitude install dnsutils</kbd>
<kbd class="block">dig -x xxx.xxx.xxx.xxx</kbd></li>
</ol>

<h3>Postfix</h3>

<ol>
<li>Install Postfix<br />
<kbd class="block">sudo aptitude install postfix mailx</kbd></li>
<li>Test Postfix<br />
<kbd class="block">mail someone@somewhereelse.com</kbd> and send a message. Don't forget: <kbd>ctrl-d</kbd> ends the message.</li>
<li>Optionally continue configuration as described <a href="http://articles.slicehost.com/2008/7/31/postfix-basic-settings-in-main-cf">here</a></li>
</ol>

<h2>A Backup Solution</h2>

<p>The following is my own backup solution for my web sites. It backs up the MySQL databases and web site files. Then, it sends a copy to Amazon S3.</p>

<h3>Install Ruby for S3Sync</h3>

<ol>
<li>Install Ruby
<kbd class="block">sudo aptitude install ruby1.8-dev ruby1.8 ri1.8 rdoc1.8 irb1.8 libreadline-ruby1.8 libruby1.8 libopenssl-ruby sqlite3 libsqlite3-ruby1.8</kbd></li>
<li>Symlink locations
<kbd class="block">sudo ln -s /usr/bin/ruby1.8 /usr/bin/ruby
sudo ln -s /usr/bin/ri1.8 /usr/bin/ri
sudo ln -s /usr/bin/rdoc1.8 /usr/bin/rdoc
sudo ln -s /usr/bin/irb1.8 /usr/bin/irb</kbd></li>
<li>Install Ruby Gems (optional)
<kbd class="block">wget http://production.cf.rubygems.org/rubygems/rubygems-1.3.7.tgz
tar xzvf rubygems-1.3.7.tgz
cd rubygems-1.3.7
sudo ruby setup.rb
cd ..
rm -R rubygems-1.3.7*
sudo ln -s /usr/bin/gem1.8 /usr/bin/gem</kbd></li>
<li>Update gems
<kbd class="block">sudo gem update
sudo gem update --system</kbd></li>
</ol>

<h3>Install S3Sync</h3>

<ol>
<li>Download and move S3Sync
<kbd class="block">wget http://s3.amazonaws.com/ServEdge_pub/s3sync/s3sync.tar.gz
tar xvzf s3sync.tar.gz
sudo mv s3sync /usr/local/
sudo chown 0:0 /usr/local/s3sync/
rm s3sync.tar.gz</kbd></li>
<li>Make sure you installed the ca-certificates package earlier (see "Install CURL" above)</li>
</ol>

<h3>Install Web Server Backup Script</h3>

<ol>
<li>Clone it from Github
<kbd class="block">sudo git clone git://github.com/postpostmodern/web-server-backup.git /usr/local/web-server-backup
</kbd></li>
<li>Configure it according to the README
<kbd class="block">sudo nano /usr/local/web-server-backup/backup.sh</kbd></li>
<li>Test Run
<kbd class="block">sudo /usr/local/web-server-backup/backup.sh</kbd></li>
</ol>

<h3>Schedule the Backup with Cron</h3>

<ol>
  <li>Create a cron job
    <kbd class="block">sudo nano /etc/cron.d/web_server_backup</kbd>
  </li>
  <li>Make it look something like this:
    <pre><code lang="cron">SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
MAILTO=demo@example.com
HOME=/root

30 4 * * * root /usr/local/web-server-backup/backup.sh > /dev/null</code></pre>
  </li>
</ol>

<h2>There is no step 54.</h2>

<p>Okay. That was a lot of steps, but everything should be running properly now. Though this article is mostly for my own reference, your comments are welcome.<br /></p>

<ol class="footnotes"><li id="footnote-1-120"><a href="http://hans.fugal.net/blog/2008/02/12/os-x-terminal-emulation-woes/">OS X Terminal Emulation Woes</a>  <a href="#footnote-link-1-120">&#8593; back up there</a></li><li id="footnote-2-120"><a href="http://jblevins.org/computing/linux/hostname">Linux Hostname Configuration</a>  <a href="#footnote-link-2-120">&#8593; back up there</a></li></ol>
]]></content:encoded>
			<wfw:commentRss>http://postpostmodern.com/instructional/slicehost-and-linode-lamp-cheatsheet/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>A Body with Class</title>
		<link>http://postpostmodern.com/instructional/a-body-with-class/</link>
		<comments>http://postpostmodern.com/instructional/a-body-with-class/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 23:07:12 +0000</pubDate>
		<dc:creator>Jason Johnson</dc:creator>
				<category><![CDATA[Instructional]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://postpostmodern.com/?p=228</guid>
		<description><![CDATA[Ease section-specific styling by adding classes to your body tag.]]></description>
			<content:encoded><![CDATA[<h2>This Short Version</h2>

<p>Add a class attribute to your <body> tag for each part of the page&#8217;s path in the URL. E.g.: The page <em>http://example.com/about/history</em> should have a body tag that looks like <code>&lt;body class="about history"&gt;</code>. It makes styling those sections of your site nice and simple.</p>

<h2>The Explanation</h2>

<p>Often times, specific styling/formatting is shared between similar pages. The traditional way to deal with this is to include additional CSS files when special formatting is needed. I&#8217;ve found body classing to be more useful and more efficient.<sup><a href="#footnote-1-228" id="footnote-link-1-228" title="See the footnote.">1</a></sup></p>

<p>Since the pages that share styling often also share a path in the url, it&#8217;s really simple to add the path parts as classes to the body tag. For example, say the <strong><em>about</em></strong> section of a web site needs special formatting because it has an extra sidebar or maybe some sort of widget. I would add the class &#8216;about&#8217; to the body tag of all of the about pages. This method continues down the hierarchy. The page at <strong><em>/about/history</em></strong> would have a body class of &#8216;about history&#8217;, and so on. It&#8217;s very simple and very handy.</p>

<p>It&#8217;s also very simple to add this functionality to your layouts whether you&#8217;re using Rails or any other framework. My PHP framework, <a href="http://github.com/postpostmodern/phooey/tree">Phooey</a>, does it for you automatically.</p>

<p>For Rails, you can include this in your layout:</p>

<p><code>&lt;body class="&lt;%= controller_name -%&gt; &lt;%= action_name -%&gt;"&gt;</code></p>

<p>&#8230;or, if you&#8217;re using Haml (which I highly recommend):</p>

<p><code>%body{:class =&gt; "#{controller_name} #{action_name}"}</code></p>

<p>Agree? Disagree? Confused? Let me know down there in the comments.<br /></p>

<ol class="footnotes"><li id="footnote-1-228">I am of the opinion that you should only include <em>one CSS file per media type</em> in any page of your site (except for the IE stylesheets). I usually include only the following stylesheets in every page of every site: all.css, screen.css, print.css. And each one of those is minified. More on this in my forthcoming article on Sass.  <a href="#footnote-link-1-228">&#8593; back up there</a></li></ol>
]]></content:encoded>
			<wfw:commentRss>http://postpostmodern.com/instructional/a-body-with-class/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

