<?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>johker&#039;s blog &#187; php5</title>
	<atom:link href="http://johker.ibutho.de/tag/php5/feed/" rel="self" type="application/rss+xml" />
	<link>http://johker.ibutho.de</link>
	<description>stories about me, my life and my trips</description>
	<lastBuildDate>Sun, 18 Dec 2011 11:53:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Der neue Server: Teil 4 apache</title>
		<link>http://johker.ibutho.de/2009/03/22/der-neue-server-teil-4-apache/</link>
		<comments>http://johker.ibutho.de/2009/03/22/der-neue-server-teil-4-apache/#comments</comments>
		<pubDate>Sun, 22 Mar 2009 19:42:40 +0000</pubDate>
		<dc:creator>johker</dc:creator>
				<category><![CDATA[Howto]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[a2enmod]]></category>
		<category><![CDATA[a2ensite]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[apache2]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[fastcgi]]></category>
		<category><![CDATA[fcgi]]></category>
		<category><![CDATA[fcgid]]></category>
		<category><![CDATA[gd]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[imagick]]></category>
		<category><![CDATA[imap]]></category>
		<category><![CDATA[installation]]></category>
		<category><![CDATA[konfiguration]]></category>
		<category><![CDATA[mcrypt]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[PATH]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[postgres]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[profile]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rewrite]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ssl]]></category>
		<category><![CDATA[suexec]]></category>
		<category><![CDATA[suhosin]]></category>
		<category><![CDATA[vHost]]></category>
		<category><![CDATA[webserver]]></category>

		<guid isPermaLink="false">http://johker.ibutho.de/?p=149</guid>
		<description><![CDATA[Nachfolgend stelle ich vor, wie man apache2 inkl. php, sowie ruby über fastcgi installiert. php, bzw. ruby über fastcgi einzubinden bietet den Vorteil, dass die Skripts immer mit Benutzerrechten und nicht mit den rechten des Webserver ausgeführt werden. Zudem kann &#8230; <a href="http://johker.ibutho.de/2009/03/22/der-neue-server-teil-4-apache/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Nachfolgend stelle ich vor, wie man <em>apache2</em> inkl. <em>php</em>, sowie <em>ruby</em> über fastcgi installiert. <em>php</em>, bzw. <em>ruby</em> über fastcgi einzubinden bietet den Vorteil, dass die Skripts immer mit Benutzerrechten und nicht mit den rechten des Webserver ausgeführt werden. Zudem kann man so für jeden vHost eine eigene <em>php.ini</em> anlegen.</p>
<h1>Installation und Konfiguration</h1>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> apache2 apache2-suexec libapache2-mod-fcgid php5-cgi</pre></div></div>

<p>Dieser Befehl installiert das <em>apache2</em>- und <em>php5</em>-Grundsystem. <em>Ruby</em> werden wir später installieren, sobald <em>apache</em> und <em>php</em> funktionieren.<br />
Nun aktivieren wir einige apache2-mods:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">a2enmod ssl
a2enmod rewrite
a2enmod suexec
a2enmod fcgid
<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>apache2 force-reload</pre></div></div>

<p>Nun legen wir noch einen Benutzer an, unter dem Skripts ausgeführt werden, die nicht direkt einem bestimmten Benutzer zugeordnet werden können (wichtig ist, dass dieser Benutzer eine GID>100 hat):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">adduser <span style="color: #660033;">--system</span> <span style="color: #660033;">--group</span> <span style="color: #660033;">--no-create-home</span> www-user</pre></div></div>

<p>Jetzt ist es an der Zeit die vHost-Strukturen unter &#8220;<em>/var/www/</em>&#8221; anzulegen. Für jeden vHost wird ein eigener Ordner erstellt und enthält mehrere Unterordner:</p>
<ul>
<li>conf &#8211; enthält die php.ini, sowie die fcgi-Konfiguration</li>
<li>docs &#8211; das Webroot</li>
<li>log &#8211; enthält die Log-Dateien</li>
<li>tmp &#8211; für temporäre Dateien</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>example.com
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>example.com<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> conf
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> docs
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> logs
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> tmp
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">755</span> <span style="color: #660033;">-R</span> example.com</pre></div></div>

<p>Als Nächstes legen wir unter &#8220;<em>/var/www/example.com/conf</em>&#8221; einen Symlink auf &#8220;<em>/etc/php5/cgi/php.ini</em>&#8221; an:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>php5<span style="color: #000000; font-weight: bold;">/</span>cgi<span style="color: #000000; font-weight: bold;">/</span>php.ini <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>example.com<span style="color: #000000; font-weight: bold;">/</span>conf<span style="color: #000000; font-weight: bold;">/</span>php.ini</pre></div></div>

<p>Das hat den Vorteil, dass alle vHosts standardmäßig die gleiche <em>php.ini</em> benutzen, man diese aber sehr leicht austauschen kann, falls man bestimmte vHost-spezifische Anpassungen vornehmen muss.<br />
Dann legen wir noch einen fcgi-Starter an:</p>
<p><em>/var/www/example.com/conf/php-fcgi.conf</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #007800;">PHPRC</span>=<span style="color: #ff0000;">&quot;/var/www/example.com/conf&quot;</span>
<span style="color: #7a0874; font-weight: bold;">export</span> PHPRC
<span style="color: #666666; font-style: italic;">#PHP_FCGI_CHILDREN=3</span>
<span style="color: #666666; font-style: italic;">#export PHP_FCGI_CHILDREN</span>
<span style="color: #7a0874; font-weight: bold;">exec</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>php5-cgi</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">755</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>example.com<span style="color: #000000; font-weight: bold;">/</span>conf<span style="color: #000000; font-weight: bold;">/</span>php-fcgi.conf</pre></div></div>

<p>Wenn man nun einen neuen vHost erstellt, muss nur dieser komplette Ordner kopiert werden, die Zeile &#8220;PHPRC=&#8221;/var/www/example.com/conf&#8221; angepasst werden, sowie das immutable-bit für die Datei <em>php-fcgi.conf</em>, bzw. <em>php.ini</em> gesetzt werden.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chattr</span> +i <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/&lt;</span>ORDNERNAME<span style="color: #000000; font-weight: bold;">&gt;/</span>conf<span style="color: #000000; font-weight: bold;">/</span>php-fcgi.conf
<span style="color: #c20cb9; font-weight: bold;">chattr</span> +i <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/&lt;</span>ORDNERNAME<span style="color: #000000; font-weight: bold;">&gt;/</span>conf<span style="color: #000000; font-weight: bold;">/</span>php.ini</pre></div></div>

<p>Jetzt muss nur noch eine vHost-Konfiguration für <em>apache</em> angelegt werden. Hierfür legen wir unter &#8220;<em>/etc/apache2/sites-available/example.com</em>&#8221; ein Template an, welches dann kopiert und angepasst werden kann:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;</span>VirtualHost <span style="color: #000000; font-weight: bold;">*</span>:<span style="color: #000000;">80</span><span style="color: #000000; font-weight: bold;">&gt;</span>
        SuExecUserGroup <span style="color: #7a0874; font-weight: bold;">&#123;</span>USER<span style="color: #7a0874; font-weight: bold;">&#125;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>GROUP<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
        ServerName <span style="color: #7a0874; font-weight: bold;">&#123;</span>SRV_NAME<span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #666666; font-style: italic;">#       ServerAlias {SRV_ALIAS}</span>
        ServerAdmin <span style="color: #7a0874; font-weight: bold;">&#123;</span>SRV_ADMIN<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
        DocumentRoot <span style="color: #7a0874; font-weight: bold;">&#123;</span>DOC_ROOT<span style="color: #7a0874; font-weight: bold;">&#125;</span>
        AddHandler fcgid-script .php
        <span style="color: #000000; font-weight: bold;">&lt;</span>Directory <span style="color: #7a0874; font-weight: bold;">&#123;</span>DOC_ROOT<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
                FCGIWrapper <span style="color: #7a0874; font-weight: bold;">&#123;</span>CONF_ROOT<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">/</span>php-fcgi.conf .php
                Options +SymLinksIfOwnerMatch +MultiViews +ExecCGI <span style="color: #660033;">-Indexes</span>
                AllowOverride FileInfo
                Order allow,deny
                allow from all
        <span style="color: #000000; font-weight: bold;">&lt;/</span>Directory<span style="color: #000000; font-weight: bold;">&gt;</span>
&nbsp;
        ErrorLog <span style="color: #7a0874; font-weight: bold;">&#123;</span>LOG_ROOT<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">/</span>error.log
        CustomLog <span style="color: #7a0874; font-weight: bold;">&#123;</span>LOG_ROOT<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">/</span>access.log combined
        LogLevel warn
        ServerSignature Off
<span style="color: #000000; font-weight: bold;">&lt;/</span>VirtualHost<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>Um den vHost zu aktivieren, muss man noch folgenden Befehl absetzen:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">a2ensite <span style="color: #000000; font-weight: bold;">&lt;</span>VHOST_NAME<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>Danach noch die <em>apache</em>-Konfiguration neu einlesen und der vHost ist einsatzbereit.</p>
<p>Quellen:<br />
<a href="http://wiki.hetzner.de/index.php/Apache_PHP5_fcgi_und_SuExec" target="_blank">http://wiki.hetzner.de/index.php/Apache_PHP5_fcgi_und_SuExec</a></p>
<h1>php-Addons</h1>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> php5-gd php5-imagick php5-mcrypt php5-mysql php5-pgsql php5-imap php5-suhosin</pre></div></div>

<p><em>gd</em> und <em>imagick</em> sind hierbei Bibliotheken zur Bildmanipulation, <em>mcrypt</em> bietet Verschlüsselungsfunktionen, <em>mysql</em> und <em>pgsql</em> sind für den Datenbankzugriff, imap bietet Funktionen zur Interaktion mit einem IMAP-Server und suhosin ist eine Sicherheitserweiterung für php.</p>
<h1>ruby</h1>
<p>Nun folgt noch die Installation von <em>ruby</em> und <em>ruby on rails</em> &#8211; ebenfalls als fastcgi:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"> <span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> ruby rdoc irb rubygems libfcgi-ruby1.8 libmysql-ruby libpgsql-ruby rails libopenssl-ruby1.8</pre></div></div>

<p>Da fastcgi schon konfiguriert ist, funktioniert <em>ruby</em>, bzw. <em>RoR</em> ohne weitere Konfiguration.</p>
<h2>rails über gem installieren</h2>
<p>Alternativ kann man <em>rails</em> auch über <em>gem</em>, anstatt über <em>aptitude</em> installieren. Dazu führt man diesen Befehl aus:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gem <span style="color: #c20cb9; font-weight: bold;">install</span> rails</pre></div></div>

<p>Und ändert anschließend &#8220;<em>/etc/profile</em>&#8221; und nimmt &#8220;<em>/var/lib/gems/1.8/bin</em>&#8221; in <strong><code>$PATH</code></strong> mit auf (vor &#8220;<code>export PATH</code>&#8221; hinzufügen):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># add rails to path</span>
<span style="color: #007800;">PATH</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$PATH</span>:/var/lib/gems/1.8/bin&quot;</span></pre></div></div>

<p>Quellen:<br />
<a href="http://howtoforge.net/ruby_on_rails_debian_etch" target="_blank">http://howtoforge.net/ruby_on_rails_debian_etch</a></p>
]]></content:encoded>
			<wfw:commentRss>http://johker.ibutho.de/2009/03/22/der-neue-server-teil-4-apache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

