<?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>Sycha Web Design &#38; Development &#187; Debian Linux Tips, Tricks and Tutorials</title>
	<atom:link href="http://www.sycha.com/resources/web-development/debian-linux/feed" rel="self" type="application/rss+xml" />
	<link>http://www.sycha.com</link>
	<description>Website Design &#38; Development</description>
	<lastBuildDate>Mon, 09 May 2011 09:59:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Linux tip: Mirror a website with one easy command (wget)</title>
		<link>http://www.sycha.com/linux-tip-mirror-website-one-easy-command-wget</link>
		<comments>http://www.sycha.com/linux-tip-mirror-website-one-easy-command-wget#comments</comments>
		<pubDate>Sat, 09 Oct 2010 01:19:26 +0000</pubDate>
		<dc:creator>Charlie Evans</dc:creator>
				<category><![CDATA[Linux Resources]]></category>

		<guid isPermaLink="false">http://www.sycha.com/?p=1328</guid>
		<description><![CDATA[I often find myself having to setup a static copy of a website. If I have command line access to the host then it's simple enough to tar up the filesystem and database, but if I only have web access then this little gem saves me a lot of time.]]></description>
			<content:encoded><![CDATA[<p>I often find myself having to setup a static copy of a website. If I have command line access to the host then it&#8217;s simple enough to tar up the filesystem and database, but if I only have web access then this little gem saves me a lot of time.</p>
<p>I&#8217;ve used &#8220;wget&#8221; for years, but hadn&#8217;t bothered to read the man pages for it. It turns out there&#8217;s a primo little option you can use to mirror a website, and strangely enough the option is &#8211;mirror.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #660033;">--mirror</span> URL</pre></div></div>

<p>This will essentially get all the html source files, and any files that are linked from within such as images, CSS etc. It even creates the appropriate directory structures so the links all work and the images aren&#8217;t broken.</p>
<p>The only thing I&#8217;ve found needs doing after this is manually grabbing any background images specified in the CSS files.</p>
<p>Hope this saves you some time too. Props to <a href="http://stupidunixlinuxtricks.blogspot.com" target="_blank" rel="nofollow">Helmuth W. Kump</a> for sharing his knowledge.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sycha.com/linux-tip-mirror-website-one-easy-command-wget/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LAMP setup guide: Configure Debian Linux for Apache, MySQL and PHP</title>
		<link>http://www.sycha.com/lamp-setup-debian-linux-apache-mysql-php</link>
		<comments>http://www.sycha.com/lamp-setup-debian-linux-apache-mysql-php#comments</comments>
		<pubDate>Fri, 20 Nov 2009 02:25:13 +0000</pubDate>
		<dc:creator>Charlie Evans</dc:creator>
				<category><![CDATA[Linux Resources]]></category>

		<guid isPermaLink="false">http://www.sycha.com/?p=56</guid>
		<description><![CDATA[Here at Sycha, we're full advocates of the LAMP web development suite. This article is a step by step guide to setting up a Linux server running Debian with stable versions of Apache, MySQL and PHP. Also included are some performance tweaks to default settings, sys admin tips, and info on sending email with Exim.]]></description>
			<content:encoded><![CDATA[<p>Here at Sycha, we&#8217;re full advocates of the LAMP web development suite. This article is a step by step guide to setting up a Linux server running Debian with stable versions of Apache, MySQL and PHP. Also included are some performance tweaks to default settings, sys admin tips, and info on sending email with Exim.</p>
<p><strong>Table of contents</strong></p>
<ul>
<li><a href="#anchor1">Install / Access your base Debian system</a></li>
<li><a href="#anchor2">Install and configure the Vim text editor</a></li>
<li><a href="#anchor3">Configure your system locale and timezone</a></li>
<li><a href="#anchor4">Configure your shell</a></li>
<li><a href="#anchor5">Enable public key authentication over SSH</a></li>
<li><a href="#anchor6">Create a non-root user for web activities</a></li>
<li><a href="#anchor7">Install packages with APT</a></li>
<li><a href="#anchor8">Configure Apache Web Server</a></li>
<li><a href="#anchor9">MySQL User Management</a></li>
<li><a href="#anchor10">Configure PHP</a></li>
<li><a href="#anchor11">Character Sets / Encoding and UTF-8</a></li>
<li><a href="#anchor12">Hostname, Fully Qualified Domain Name and Reverse DNS</a></li>
<li><a href="#anchor13">Configure Exim for sending email</a></li>
</ul>
<p><a name="anchor1"></a></p>
<h2>Install / Access your base Debian system</h2>
<p>For this guide, we&#8217;ll assume your hosting provider has installed a base Debian system and you are accessing your server remotely via SSH as the root user. If you actually have physical access to the machine then you should <a rel="nofollow" href="http://www.debian.org/distrib/" target="_blank">download a small image file from Debian.org</a>, record it to a CD/DVD/USB disk/floppy, and install using the Internet.</p>
<p>Now is a good time to change the root password..</p>

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

<p><a name="anchor2"></a></p>
<h2>Install and configure the Vim text editor</h2>
<p>We love Vim (Vi IMproved) for editing all our text based files &#8211; let&#8217;s install it.</p>

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

<p>If required, uninstall standard vi (package name is nvi) so the &#8220;vi&#8221; command cranks up vim</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">dpkg</span> <span style="color: #660033;">-P</span> nvi</pre></div></div>

<p>Let&#8217;s make a few tweaks to the Vim config file:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">vi</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>vim<span style="color: #000000; font-weight: bold;">/</span>vimrc</pre></div></div>

<p>Uncomment the following line to enable syntax highlighting:</p>

<div class="wp_syntax"><div class="code"><pre class="vim" style="font-family:monospace;"><span style="color: #adadad; font-style: italic;">&quot; Vim5 and later versions support syntax highlighting. Uncommenting the next</span>
<span style="color: #adadad; font-style: italic;">&quot; line enables syntax highlighting by default.</span>
syntax on</pre></div></div>

<p>Uncomment the following to have Vim jump to the last position when reopening a file:</p>

<div class="wp_syntax"><div class="code"><pre class="vim" style="font-family:monospace;"><span style="color: #adadad; font-style: italic;">&quot; Uncomment the following to have Vim jump to the last position when</span>
<span style="color: #adadad; font-style: italic;">&quot; reopening a file</span>
<span style="color: #804040;">if</span> <span style="color: #25BB4D;">has</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">&quot;autocmd&quot;</span><span style="color: #000000;">&#41;</span>
  au BufReadPost <span style="color: #000000;">*</span> <span style="color: #804040;">if</span> <span style="color: #25BB4D;">line</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">&quot;'<span style="">\&quot;</span>&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&gt;</span> <span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000000;">&amp;&amp;</span> <span style="color: #25BB4D;">line</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">&quot;'<span style="">\&quot;</span>&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&lt;</span>= <span style="color: #25BB4D;">line</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">&quot;$&quot;</span><span style="color: #000000;">&#41;</span> 
    \<span style="color: #000000;">|</span> <span style="color: #804040;">exe</span> <span style="color: #C5A22D;">&quot;normal! g'<span style="">\&quot;</span>&quot;</span> <span style="color: #000000;">|</span> <span style="color: #804040;">endif</span>
<span style="color: #804040;">endif</span></pre></div></div>

<p>Change the default editor for some programs (e.g. crontab, svn) from nano to vim</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>alternatives<span style="color: #000000; font-weight: bold;">/</span>editor
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</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><span style="color: #c20cb9; font-weight: bold;">vi</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>alternatives<span style="color: #000000; font-weight: bold;">/</span>editor</pre></div></div>

<p><a name="anchor3"></a></p>
<h2>Configure your system locale and timezone</h2>
<p>If you receive any locale warnings when running apt commands<br />
e.g. warning: Falling back to the standard locale (&#8220;C&#8221;).<br />
It probably just means you have to reconfigure your locales with the following command:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">dpkg-reconfigure locales</pre></div></div>

<p>select the appropriate UTF-8 version for your country and set as default<br />
e.g. for us Kiwis en_NZ.UTF-8 is a good choice.</p>
<p>Set correct timezone:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">dpkg-reconfigure tzdata</pre></div></div>

<p>Set the system clock:</p>

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

<p><a name="anchor4"></a></p>
<h2>Configure your shell</h2>
<p>In the .bashrc file you can specify shell behaviour and appearance, e.g. the way the prompt looks on the command line, being prompted before deleting / overwriting etc.<br />
The following settings are simply personal preference.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">vi</span> ~<span style="color: #000000; font-weight: bold;">/</span>.bashrc</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PS1</span>=<span style="color: #ff0000;">'\u@\h:\w\$ '</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">rm</span></span>=<span style="color: #ff0000;">'rm -i'</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">cp</span></span>=<span style="color: #ff0000;">'cp -i'</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">mv</span></span>=<span style="color: #ff0000;">'mv -i'</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">ls</span></span>=<span style="color: #ff0000;">'ls --color'</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PROMPT_COMMAND</span>=<span style="color: #ff0000;">'echo -ne &quot;\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007&quot;'</span></pre></div></div>

<p><a name="anchor5"></a></p>
<h2>Enable public key authentication over SSH</h2>
<p>Instead of entering a password everytime to SSH into your server, you can enable public key authentication. This can come in quite handy when transferring data between servers or when running scripts where an interactive password prompt would be a pain.<br />
To enable this you need to ensure the following settings are configured in your sshd_config file:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">vi</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ssh<span style="color: #000000; font-weight: bold;">/</span>sshd_config</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">RSAAuthentication <span style="color: #c20cb9; font-weight: bold;">yes</span>
PubkeyAuthentication <span style="color: #c20cb9; font-weight: bold;">yes</span>
AuthorizedKeysFile <span style="color: #000000; font-weight: bold;">%</span>h<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>authorized_keys</pre></div></div>

<p>Restart ssh for changes to take effect</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><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><span style="color: #c20cb9; font-weight: bold;">ssh</span> restart</pre></div></div>

<p>Now simply add the public keys of any machines you wish to connect from to the authorized_keys file.</p>
<p>Note: the authorized_keys file must <strong>only</strong> be writable by user</p>
<p><a name="anchor6"></a></p>
<h2>Create a non-root user for web activities</h2>
<p>For good security, we don&#8217;t want to run everything as root.<br />
And since most of our activities on this server are to be web based, we&#8217;ll create a user called &#8220;web&#8221;.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">adduser web</pre></div></div>

<p>In general we&#8217;ll log into the server as &#8220;web&#8221; and then switch user to root only when necessary,<br />
e.g. to restart apache etc</p>
<p>Note: bash settings and authorized_keys are per user so you may wish to update these as above for &#8220;web&#8221;:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">su</span> web
<span style="color: #c20cb9; font-weight: bold;">vi</span> ~<span style="color: #000000; font-weight: bold;">/</span>.bashrc
<span style="color: #c20cb9; font-weight: bold;">vi</span> ~<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>authorized_keys
<span style="color: #7a0874; font-weight: bold;">exit</span></pre></div></div>

<p><a name="anchor7"></a></p>
<h2>Install packages with APT</h2>
<p>OK now we&#8217;ve prepared our environment, let&#8217;s install a bunch of packages using apt:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #c20cb9; font-weight: bold;">less</span>
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> mysql-server
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> apache2-mpm-prefork
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> php5
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> php5-mysql
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> php5-gd
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> php5-curl
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> php5-mcrypt
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> php5-cli
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> subversion
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> debian-archive-keyring
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> imagemagick
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> rsync
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #c20cb9; font-weight: bold;">unzip</span></pre></div></div>

<p><a name="anchor8"></a></p>
<h2>Configure Apache Web Server</h2>
<p>Let&#8217;s enable rewrites and SSL in Apache, but turn off the autoindex module (which displays a directory listing to the user when there&#8217;s no index file. Run the following commands:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">a2dismod autoindex
a2enmod ssl
a2enmod rewrite</pre></div></div>

<p>If you are enabling SSL, modify the ports config file as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">vi</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>ports.conf</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">NameVirtualHost</span> * 
<span style="color: #00007f;">Listen</span> <span style="color: #ff0000;">80</span> 
&nbsp;
&lt;<span style="color: #000000; font-weight:bold;">IfModule</span> mod_ssl.c&gt;
    <span style="color: #00007f;">Listen</span> <span style="color: #ff0000;">443</span> 
&lt;/<span style="color: #000000; font-weight:bold;">IfModule</span>&gt;</pre></div></div>

<p>and remove the NameVirtualHost * from the default virtual host</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">vi</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>sites-enabled<span style="color: #000000; font-weight: bold;">/</span>000-default</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #adadad; font-style: italic;">#NameVirtualHost *</span></pre></div></div>

<p>To stop warnings on Apache startup, add a ServerName directive as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">vi</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>apache2.conf</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">ServerName</span> localhost</pre></div></div>

<p>Edit the environment variables so Apache runs as our new user &#8220;web&#8221;:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">vi</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>envvars</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">APACHE_RUN_USER</span>=web
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">APACHE_RUN_GROUP</span>=web</pre></div></div>

<p><a name="anchor9"></a></p>
<h2>MySQL User Management</h2>
<p>MySQL comes ready to use, only thing to do is a bit of user management.<br />
By default, MySQL is installed without a password for the root user, so let&#8217;s login:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mysql</pre></div></div>

<p>Note: before running any of the following SQL commands<br />
- be sure to change <strong>DB_NAME</strong>, <strong>DB_USER</strong> and <strong>DB_PASS</strong> first <img src='http://www.sycha.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Firstly, give the root user a password:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SET</span> <span style="color: #000099;">PASSWORD</span> <span style="color: #CC0099;">=</span> <span style="color: #000099;">PASSWORD</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'DB<span style="color: #008080; font-weight: bold;">_</span>PASS'</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span></pre></div></div>

<p>Now set up a non-root power user with full privileges to everything:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #000099;">USER</span> <span style="color: #008000;">'DB<span style="color: #008080; font-weight: bold;">_</span>USER'</span>@<span style="color: #008000;">'localhost'</span> IDENTIFIED BY <span style="color: #008000;">'DB<span style="color: #008080; font-weight: bold;">_</span>PASS'</span><span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">GRANT</span> <span style="color: #990099; font-weight: bold;">ALL</span> <span style="color: #990099; font-weight: bold;">PRIVILEGES</span> <span style="color: #990099; font-weight: bold;">ON</span> <span style="color: #CC0099;">*</span>.<span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">TO</span> <span style="color: #008000;">'DB<span style="color: #008080; font-weight: bold;">_</span>USER'</span>@<span style="color: #008000;">'localhost'</span> <span style="color: #990099; font-weight: bold;">WITH</span> <span style="color: #990099; font-weight: bold;">GRANT</span> <span style="color: #990099; font-weight: bold;">OPTION</span><span style="color: #000033;">;</span></pre></div></div>

<p>To setup a user who has full access to only 1 specific database:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #000099;">USER</span> <span style="color: #008000;">'DB<span style="color: #008080; font-weight: bold;">_</span>USER'</span>@<span style="color: #008000;">'localhost'</span> IDENTIFIED BY <span style="color: #008000;">'DB<span style="color: #008080; font-weight: bold;">_</span>PASS'</span><span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">GRANT</span> <span style="color: #990099; font-weight: bold;">ALL</span> <span style="color: #990099; font-weight: bold;">PRIVILEGES</span> <span style="color: #990099; font-weight: bold;">ON</span> DB_NAME.<span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">TO</span> <span style="color: #008000;">'DB<span style="color: #008080; font-weight: bold;">_</span>USER'</span>@<span style="color: #008000;">'localhost'</span><span style="color: #000033;">;</span></pre></div></div>

<p><a name="anchor10"></a></p>
<h2>Configure PHP</h2>
<p>We have installed PHP for Apache and the command line (cli) so we have 2 configuration files to update:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">vi</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>apache2<span style="color: #000000; font-weight: bold;">/</span>php.ini
<span style="color: #c20cb9; font-weight: bold;">vi</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>cli<span style="color: #000000; font-weight: bold;">/</span>php.ini</pre></div></div>

<p>We only make a few tweaks here as the default config is pretty good for our needs.<br />
Basically upping the upload filesize and the memory limit, and allowing only cookies for our sessions.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">upload_max_filesize = 8M
memory_limit = 128M
session.use_only_cookies = <span style="color: #000000;">1</span></pre></div></div>

<p><a name="anchor11"></a></p>
<h2>Character Sets / Encoding and UTF-8</h2>
<p>Ever seen those nasty question marks showing up on a webpage in place of non-latin characters? Chances are this is due to mismatched or inapporopriate character sets. Something in the pipeline is not set to UTF-8, and it could be mysql, apache, content-type, or even a file encoding.</p>
<p>The best way to avoid these issues is to set things up correctly at the beginning.<br />
Let&#8217;s start with MySQL:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">vi</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>mysql<span style="color: #000000; font-weight: bold;">/</span>my.cnf</pre></div></div>

<p>Set MySQL server&#8217;s default character set to UTF-8 so all databases, tables and strings will be UTF-8 unless specified otherwise. Add the following line to the [mysqld] section:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>mysqld<span style="">&#93;</span></span>
<span style="color: #000099;">character_set_server</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">utf8</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><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>mysql restart</pre></div></div>

<p>Tip: if for some reason, a database&#8217;s default charset is latin1 &#8211; then you can issue the following query to display any subsequent utf-8 data correctly:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SET</span> NAMES <span style="color: #008000;">'utf8'</span></pre></div></div>

<p>Now for Apache.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">vi</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>apache2.conf</pre></div></div>

<p>In your your config file, make sure the following directive is present:</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">AddDefaultCharset</span> utf-<span style="color: #ff0000;">8</span></pre></div></div>

<p>Include the following HTML meta tag in the head section of your web pages:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">meta</span> <span style="color: #000066;">http-equiv</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Content-Type&quot;</span> <span style="color: #000066;">content</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/html; charset=UTF-8&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span></pre></div></div>

<p><a name="anchor12"></a></p>
<h2>Hostname, Fully Qualified Domain Name and Reverse DNS</h2>
<p>As an example, let&#8217;s say we&#8217;re setting up the following server:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">          server <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #c20cb9; font-weight: bold;">hostname</span> = server1
fully qualified domain name = server1.example.com
         primary IP address = 123.456.78.90</pre></div></div>

<p>Through your DNS admin, point the fully qualified domain name (FQDN) to the primary IP:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">$ORIGIN example.com.
server1        A     123.456.78.90     <span style="color: #666666; font-style: italic;">; ip address for &quot;server1.example.com&quot;</span></pre></div></div>

<p>Then through your hosting provider, setup reverse DNS from your IP to your FQDN:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">123.456.78.90 - server1.example.com</pre></div></div>

<p>Finally, in your server&#8217;s hosts file point both the FQDN and hostname at the primary IP:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">vi</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>hosts</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">127.0.0.1       localhost
123.456.78.90   server1.example.com server1</pre></div></div>

<p>Now on your server you can check things with the hostname command:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">hostname</span> <span style="color: #660033;">-a</span>        <span style="color: #666666; font-style: italic;"># will print your hostname &quot;server1&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">hostname</span> <span style="color: #660033;">-f</span>        <span style="color: #666666; font-style: italic;"># will print your FQDN &quot;server1.example.com&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">hostname</span> <span style="color: #660033;">-d</span>        <span style="color: #666666; font-style: italic;"># will print your domain part &quot;example.com&quot;</span></pre></div></div>

<p>Your system&#8217;s hostname is set during Debian installation.<br />
You can change the hostname by editing /etc/hostname then running hostname.sh:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">vi</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">hostname</span>
<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>hostname.sh start</pre></div></div>

<p>Note: after changing the hostname, be sure to update your DNS and /etc/hosts as above</p>
<p><a name="anchor13"></a></p>
<h2>Configure Exim for sending email</h2>
<p>Exim is a full featured MTA (Mail Transfer Agent) and can be a little overwhelming with all it&#8217;s possible configurations. Fortunately we only need it to send email via SMTP for our hosted websites (e.g. sending an order confirmation email from an ecom store), so the config becomes very simple.</p>
<p>By default, mail will be sent from our FQDN (e.g. &#8220;server1.example.com&#8221; from our example above). You can change that in Exim, but you generally want it to match.</p>
<p>So let&#8217;s run the configuration script:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">dpkg-reconfigure exim4-config</pre></div></div>

<p>Answer the questions as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">General <span style="color: #7a0874; font-weight: bold;">type</span> of mail configuration:
internet site; mail is sent and received directly using SMTP
&nbsp;
System mail name:
server1.example.com
&nbsp;
IP-addresses to listen on <span style="color: #000000; font-weight: bold;">for</span> incoming SMTP connections:
127.0.0.1
&nbsp;
Other destinations <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #c20cb9; font-weight: bold;">which</span> mail is accepted:
&nbsp;
Domains to relay mail <span style="color: #000000; font-weight: bold;">for</span>:
&nbsp;
Machines to relay mail <span style="color: #000000; font-weight: bold;">for</span>:
&nbsp;
Keep number of DNS-queries minimal <span style="color: #7a0874; font-weight: bold;">&#40;</span>Dial-on-Demand<span style="color: #7a0874; font-weight: bold;">&#41;</span>?
No
&nbsp;
Delivery method <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #7a0874; font-weight: bold;">local</span> mail:
mbox format <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>mail<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;
Split configuration into small files?
No</pre></div></div>

<p>If you have multiple IPs setup on your server, then Exim may choose to send from one of the additional ones as opposed to the primary IP. You can specify which IP to use for sending via SMTP as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">vi</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>exim4<span style="color: #000000; font-weight: bold;">/</span>exim4.conf.template</pre></div></div>

<p>In the &#8220;transports&#8221; section, add the following line inside the <strong>remote_smtp:</strong> block:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">remote_smtp:
  <span style="color: #000099;">interface</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> 123.456.78.90 </span><span style="color: #666666; font-style: italic;">; this should be YOUR primary IP</span></pre></div></div>

<p>Then restart Exim:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><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>exim4 restart</pre></div></div>

<p>If you&#8217;re interested, the config file that gets generated from the template is:<br />
/var/lib/exim4/config.autogenerated</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sycha.com/lamp-setup-debian-linux-apache-mysql-php/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced
Database Caching 1/20 queries in 0.006 seconds using disk: basic
Object Caching 240/273 objects using disk: basic

Served from: www.sycha.com @ 2012-02-04 18:49:09 -->
