<?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>Bin-Blog &#187; source</title>
	<atom:link href="http://www.bin-co.com/blog/tag/source/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bin-co.com/blog</link>
	<description>Learn about the latest in Web Development - as soon as I do.</description>
	<lastBuildDate>Tue, 13 Oct 2009 18:55:47 +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>Compile and Install a LAMP(Linux/Apache/MySQL/PHP) Server from Source</title>
		<link>http://www.bin-co.com/blog/2008/09/compile-install-lamp-linux-apache-mysql-php-server-from-source/</link>
		<comments>http://www.bin-co.com/blog/2008/09/compile-install-lamp-linux-apache-mysql-php-server-from-source/#comments</comments>
		<pubDate>Mon, 22 Sep 2008 18:00:07 +0000</pubDate>
		<dc:creator>Binny V A</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[compile]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[lamp]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[source]]></category>

		<guid isPermaLink="false">http://www.bin-co.com/blog/?p=132</guid>
		<description><![CDATA[In the last post, I described the method to install a LAMP server using apt in debian. But in some occasions, we need the latest build of the software - then we have to install it from source.]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.bin-co.com/blog/wp-content/uploads/2008/09/lava_lamp.jpg" alt="LAMP - Linux, Apache, MySQL, PHP" title="LAMP - Linux, Apache, MySQL, PHP" width="232" height="294" class="size-full wp-image-128 intro" align="right" /></p>
<p class="intro">In the last post, I described the method to <a href="http://www.bin-co.com/blog/2008/09/installing-lampapache-web-serverphpmysql-in-debian/">install a LAMP server using apt in debian</a>. But in some occasions, we need the latest build of the software &#8211; then we have to install it from source.</p>
<p>Before installation, a few points to remember. These instruction are not for a production environment &#8211; this is for a development environment. Some of the commands(the <code>make install</code> commands) need root access. You can get that using this command <code>su -</code> and entering the root password at the prompt.</p>
<h2>Installing MySQL 5</h2>
<p><img src="http://www.bin-co.com/blog/wp-content/uploads/2008/09/mysql_logo.gif" alt="" title="MySQL Logo" width="150" height="98" class="alignnone size-full wp-image-127" align="right" /></p>
<p><strong class="highlight">Download MySQL source tarballs</strong> from <a href="http://dev.mysql.com/downloads/" class="external">MySQL.com</a>. Make sure that you have downloaded the latest releases. At the time of writing this, MySQL 5.0 was the latest. <strong class="highlight">Open a terminal</strong> and login as the root user. <strong class="highlight">Extract</strong> the source to some folder(say &#8216;/usr/src/mysql&#8217;).</p>
<pre><code class="cli"></code>$ mkdir /usr/src/mysql
$ cp mysql-VERSION.tar.gz /usr/src/mysql
$ cd /usr/src/mysql
$ gunzip &lt; mysql-VERSION.tar.gz | tar -xvf -
$ cd mysql-VERSION</code></pre>
<p>For added security we will create a <strong class="highlight">new user called &#8216;mysql&#8217;</strong> and use this user while running MySQL.</p>
<pre><code class="cli">$ groupadd mysql
$ useradd -g mysql mysql</code></pre>
<p>Now we will <strong class="highlight">compile and install MySQL</strong> &#8211; this will take some time.</p>
<pre><code class="cli">$ ./configure --prefix=/usr/local/mysql [add the necessary extra options here]
$ make
$ make install</code></pre>
<p>After installing, we have to <strong class="highlight">configure MySQL</strong>.</p>
<pre><code class="cli">$ cp support-files/my-medium.cnf /etc/my.cnf
$ cd /usr/local/mysql
$ bin/mysql_install_db --user=mysql
$ chown -R root  .
$ chown -R mysql lib
$ chgrp -R mysql .</code></pre>
<p>Start MySQL</p>
<pre><code class="cli">$ bin/mysqld_safe --user=mysql &amp;</code></pre>
<p>If all goes well, you will be able to <strong class="highlight">connect to the mysql server</strong> using some clients like <a href="http://www.phpmyadmin.net/home_page/" class="external">phpMyAdmin</a> or <a href="http://www.mysqlfront.de/" class="external">MySQL Frontend</a>. For testing we will use the command line client provided with MySQL. In terminal type&#8230;</p>
<pre><code class="cli">$ mysql</code></pre>
<p>Now you should see <strong class="highlight">mysql command shell</strong> &#8211; something like this&#8230;</p>
<pre><code class="cli">Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 5.0.21-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql&lt;</code></pre>
<p>Here you can <strong class="highlight">run SQL command</strong> and see the returned results. Try some out&#8230;</p>
<pre><code class="mysql">SHOW DATABASES;</code></pre>
<p>That&#8217;s it &#8211; we have installed MySQL. You can <strong class="highlight">start the server</strong> using the command</p>
<pre><code class="cli">cd /usr/local/mysql ; bin/mysqld_safe --user=mysql &amp;</code></pre>
<p>If <strong class="highlight">anything went wrong</strong>, cry for sometime and then <strong class="highlight">consult the documentation</strong>.</p>
<h2>Installing Apache 2</h2>
<p><img src="http://www.bin-co.com/blog/wp-content/uploads/2008/09/apache.png" alt="" title="Apache Logo" width="230" height="90" class="alignnone size-full wp-image-126" style="right" /></p>
<p>Same as in MySQL, download the source from <a href="http://httpd.apache.org/download.cgi" class="external">Apache.org</a>. Extract to /usr/src/httpd.</p>
<pre><code class="cli">$ mkdir /usr/src/httpd
$ cp httpd-VERSION.tar.gz /usr/src/httpd
$ cd /usr/src/httpd
$ gunzip &lt; httpd-VERSION.tar.gz | tar -xvf -
$ cd httpd-VERSION</code></pre>
<p>Compile and Install&#8230;</p>
<pre><code class="cli">$ ./configure --prefix=/usr/local/apache2 [add extra options here]
$ make
$ make install</code></pre>
<p>The configure command I used is given below &#8211; you can change it if you feel like it.</p>
<pre><code class="cli">./configure --prefix=/usr/local/apache2 --enable-mime-magic --enable-expires \
--enable-headers --enable-ssl --enable-http --enable-info --enable-dir \
--enable-rewrite --enable-so</code></pre>
<p>We will hold off configuration of Apache until after the PHP installation.</p>
<h2>Installing PHP 5</h2>
<p><img src="http://www.bin-co.com/blog/wp-content/uploads/2008/09/php-logo.png" alt="" title="PHP Logo Custom" width="179" height="98" class="alignnone size-full wp-image-123" align="right" /></p>
<p>You know the drill &#8211; <strong class="highlight"><a href="http://www.php.net/downloads.php">download PHP 5</a>, extract to /usr/src/php5</strong>.</p>
<pre><code class="cli">$ mkdir /usr/src/php5
$ cp php-VERSION.tar.gz /usr/src/php5
$ cd /usr/src/php5
$ gunzip &lt; php-VERSION.tar.gz | tar -xvf -
$ cd php-VERSION</code></pre>
<p>Building PHP is a little more complicated than the other two. PHP have a lot of options, and must be customized according to your needs. You can see all the available configurations by running the command <code>./configure --help</code>. If you require more information about this, take a look at <a href="http://www.php.net/manual/en/configure.php" class="external">PHP documentation on <code>configure</code></a>.</p>
<p>My requirements may not match yours &#8211; some you have to make your own decisions here. I am providing the most basic configuration for the build&#8230;</p>
<pre><code class="cli">./configure \
--prefix=/usr/local/php5 \
--with-apxs2=/usr/local/apache2/bin/apxs \
--with-mysql=shared,/usr/local/mysql [add your options here]</code></pre>
<p>You can add all your configuration to this line. The &#8211;with-apxs2 lines tells the installer where to find Apache2 executables and the &#8211;with-mysql configuration is the location of the mysql libraries. These two lines are a must.</p>
<p>This is the actual command I used&#8230;</p>
<pre><code class="cli">./configure --prefix=/usr/local/php5 --with-apxs2=/usr/local/apache2/bin/apxs \
--with-mysql=shared,/usr/local/mysql --with-zlib --with-gettext --with-gdbm --with-sqlite</code></pre>
<p>Now to install the language&#8230;</p>
<pre><code class="cli">$ ./configure \
$ --prefix=/usr/local/php5 \
$ --with-apxs2=/usr/local/apache2/bin/apxs \
$ --with-mysql=shared,/usr/local/mysql [add your options here]
$ make
$ make install</code></pre>
<p>Now copy the php.ini file to the necessary location&#8230;</p>
<pre><code class="cli">cp php.ini-dist /usr/local/php5/lib</code></pre>
<p>Wonderful! Now we have everything we need &#8211; we just have to configure it.</p>
<h2>Configuring Apache</h2>
<p>The <strong class="highlight">Apache can be configured by editing a single text file</strong>. This file is usually located in <code>Apache_folder/conf/httpd.conf</code>. In our case this will be <code>/usr/local/apache2/conf/httpd.conf</code> . Open this file in you favorite text editor and change the following lines. Please note that some lines may be different in you apache configuration file &#8211; so if you can&#8217;t find the line when you search with the full line, try to find the line using just the identifier. For example, if you can&#8217;t find the text &#8216;<code>DocumentRoot "/usr/local/apache2/htdocs"</code>&#8216; in your httpd.conf file, search for the text &#8216;<code>DocumentRoot</code>&#8216;.</p>
<h3>Configuration Options</h3>
<p>You may want to change the document root &#8211; replace the line</p>
<pre><code>DocumentRoot "/usr/local/apache2/htdocs"</code></pre>
<p>With</p>
<pre><code>DocumentRoot "/var/www/htdocs" # Or whatever folder you want to set as the document root.</code></pre>
<p>Also change the line</p>
<pre><code>&lt;Directory "/usr/local/apache2/htdocs"&gt;</code></pre>
<p>to</p>
<pre><code>&lt;Directory "/var/www/htdocs"&gt;</code></pre>
<p>I don&#8217;t have to tell you that you can use any directory you want &#8211; you don&#8217;t have to use &#8216;/var/www/htdocs&#8217; just because I use it. If you are using another directory, make sure that you change both the above given lines to that directory.</p>
<p>If you want to use .htaccess file to configure different folders, find the line</p>
<pre><code>AllowOverride None</code></pre>
<p>inside the <code>&lt;Directory "/usr/local/apache2/htdocs"&gt; ... &lt;/Directory&gt;</code> tag and change it to </p>
<pre><code>AllowOverride All</code></pre>
<p>Since we are using PHP, and want to use index.php as the default page in a directory, we have to set that configuration option. Find the line </p>
<pre><code>DirectoryIndex index.html index.html.var</code></pre>
<p>and replace it with, say,</p>
<pre><code>DirectoryIndex index.php index.html index.html.var</code></pre>
<p>This will make sure that the index.php will be called when you try to access a directory. For example, if you try to access, say, http://localhost/ you will get a file listing. But if you put a file named &#8216;index.php&#8217; in this folder, the server will open this file when someone accesses &#8216;http://localhost/&#8217;. The order of the names are important. If there is a file called &#8216;index.php&#8217; and a file called &#8216;index.html&#8217; in the same folder, the first one(in our case index.php) will be opened.</p>
<p>Now we must associate all files with the extension &#8216;php&#8217; with the PHP scripts handler. For this find the line</p>
<pre><code>AddHandler type-map var</code></pre>
<p>and add the following line below that line &#8211; like this</p>
<pre><code>AddHandler type-map var
AddHandler php5-script	php</code></pre>
<p>Below that there is a AddType section. Add the following line to this section.</p>
<pre><code>AddType application/x-httpd-php .php</code></pre>
<h2>Start the Server</h2>
<p>You can test your installation by starting your server. Open a terminal and run the following command.</p>
<pre><code class="cli">/usr/local/apache2/bin/apachectl start</code></pre>
<p>Go to your document root(<code>/var/www/htdocs</code>) and create a php file called &#8216;info.php&#8217; and put this code inside it&#8230;</p>
<pre><code class="php">&lt;?php
php<!-- wp bugfix -->info();

</code></pre>
<p>Now open a browser and try to access <a href="http://localhost/">http://localhost/</a> &#8211; you should see a file listing page with a &#8216;info.php&#8217; in the list. Click on that link &#8211; if you see a PHP information page, your web server is setup correctly.</p>
<p>To make sure MySQL-PHP connection is working, <a href="http://www.bin-co.com/database/clients/phpmyadmin/installing_phpmyadmin.php">install phpMyAdmin</a> &#8211; or write a database connection script &#8211; whatever is easier for you.</p>
<p><strong class="highlight">Shameless Plug</strong>: If you are a Linux user, you may want to check out my <a href="http://lindesk.com/">Linux Blog &#8211; LinDesk</a> &#8211; its about Linux on the Desktop &#8211; Articles, Application Reviews and Tutorials about many aspects of Linux included configuration and scripting.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bin-co.com/blog/2008/09/compile-install-lamp-linux-apache-mysql-php-server-from-source/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

