{"id":132,"date":"2008-09-22T23:30:07","date_gmt":"2008-09-22T18:00:07","guid":{"rendered":"http:\/\/www.bin-co.com\/blog\/?p=132"},"modified":"2008-09-22T23:30:07","modified_gmt":"2008-09-22T18:00:07","slug":"compile-install-lamp-linux-apache-mysql-php-server-from-source","status":"publish","type":"post","link":"https:\/\/www.bin-co.com\/blog\/2008\/09\/compile-install-lamp-linux-apache-mysql-php-server-from-source\/","title":{"rendered":"Compile and Install a LAMP(Linux\/Apache\/MySQL\/PHP) Server from Source"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" 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>\n<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>\n<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>\n<h2>Installing MySQL 5<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" 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>\n<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>\n<pre><code class=\"cli\"><\/code>$ mkdir \/usr\/src\/mysql\n$ cp mysql-VERSION.tar.gz \/usr\/src\/mysql\n$ cd \/usr\/src\/mysql\n$ gunzip &lt; mysql-VERSION.tar.gz | tar -xvf -\n$ cd mysql-VERSION<\/code><\/pre>\n<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>\n<pre><code class=\"cli\">$ groupadd mysql\n$ useradd -g mysql mysql<\/code><\/pre>\n<p>Now we will <strong class=\"highlight\">compile and install MySQL<\/strong> &#8211; this will take some time.<\/p>\n<pre><code class=\"cli\">$ .\/configure --prefix=\/usr\/local\/mysql [add the necessary extra options here]\n$ make\n$ make install<\/code><\/pre>\n<p>After installing, we have to <strong class=\"highlight\">configure MySQL<\/strong>.<\/p>\n<pre><code class=\"cli\">$ cp support-files\/my-medium.cnf \/etc\/my.cnf\n$ cd \/usr\/local\/mysql\n$ bin\/mysql_install_db --user=mysql\n$ chown -R root  .\n$ chown -R mysql lib\n$ chgrp -R mysql .<\/code><\/pre>\n<p>Start MySQL<\/p>\n<pre><code class=\"cli\">$ bin\/mysqld_safe --user=mysql &amp;<\/code><\/pre>\n<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>\n<pre><code class=\"cli\">$ mysql<\/code><\/pre>\n<p>Now you should see <strong class=\"highlight\">mysql command shell<\/strong> &#8211; something like this&#8230;<\/p>\n<pre><code class=\"cli\">Welcome to the MySQL monitor.  Commands end with ; or \\g.\nYour MySQL connection id is 1 to server version: 5.0.21-log\n\nType 'help;' or '\\h' for help. Type '\\c' to clear the buffer.\n\nmysql&lt;<\/code><\/pre>\n<p>Here you can <strong class=\"highlight\">run SQL command<\/strong> and see the returned results. Try some out&#8230;<\/p>\n<pre><code class=\"mysql\">SHOW DATABASES;<\/code><\/pre>\n<p>That&#8217;s it &#8211; we have installed MySQL. You can <strong class=\"highlight\">start the server<\/strong> using the command<\/p>\n<pre><code class=\"cli\">cd \/usr\/local\/mysql ; bin\/mysqld_safe --user=mysql &amp;<\/code><\/pre>\n<p>If <strong class=\"highlight\">anything went wrong<\/strong>, cry for sometime and then <strong class=\"highlight\">consult the documentation<\/strong>.<\/p>\n<h2>Installing Apache 2<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" 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>\n<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>\n<pre><code class=\"cli\">$ mkdir \/usr\/src\/httpd\n$ cp httpd-VERSION.tar.gz \/usr\/src\/httpd\n$ cd \/usr\/src\/httpd\n$ gunzip &lt; httpd-VERSION.tar.gz | tar -xvf -\n$ cd httpd-VERSION<\/code><\/pre>\n<p>Compile and Install&#8230;<\/p>\n<pre><code class=\"cli\">$ .\/configure --prefix=\/usr\/local\/apache2 [add extra options here]\n$ make\n$ make install<\/code><\/pre>\n<p>The configure command I used is given below &#8211; you can change it if you feel like it.<\/p>\n<pre><code class=\"cli\">.\/configure --prefix=\/usr\/local\/apache2 --enable-mime-magic --enable-expires \\\n--enable-headers --enable-ssl --enable-http --enable-info --enable-dir \\\n--enable-rewrite --enable-so<\/code><\/pre>\n<p>We will hold off configuration of Apache until after the PHP installation.<\/p>\n<h2>Installing PHP 5<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.bin-co.com\/blog\/wp-content\/uploads\/2008\/09\/php-logo-1-1.png\" alt=\"\" title=\"PHP Logo Custom\" width=\"179\" height=\"98\" class=\"alignnone size-full wp-image-123\" align=\"right\" \/><\/p>\n<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>\n<pre><code class=\"cli\">$ mkdir \/usr\/src\/php5\n$ cp php-VERSION.tar.gz \/usr\/src\/php5\n$ cd \/usr\/src\/php5\n$ gunzip &lt; php-VERSION.tar.gz | tar -xvf -\n$ cd php-VERSION<\/code><\/pre>\n<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>\n<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>\n<pre><code class=\"cli\">.\/configure \\\n--prefix=\/usr\/local\/php5 \\\n--with-apxs2=\/usr\/local\/apache2\/bin\/apxs \\\n--with-mysql=shared,\/usr\/local\/mysql [add your options here]<\/code><\/pre>\n<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>\n<p>This is the actual command I used&#8230;<\/p>\n<pre><code class=\"cli\">.\/configure --prefix=\/usr\/local\/php5 --with-apxs2=\/usr\/local\/apache2\/bin\/apxs \\\n--with-mysql=shared,\/usr\/local\/mysql --with-zlib --with-gettext --with-gdbm --with-sqlite<\/code><\/pre>\n<p>Now to install the language&#8230;<\/p>\n<pre><code class=\"cli\">$ .\/configure \\\n$ --prefix=\/usr\/local\/php5 \\\n$ --with-apxs2=\/usr\/local\/apache2\/bin\/apxs \\\n$ --with-mysql=shared,\/usr\/local\/mysql [add your options here]\n$ make\n$ make install<\/code><\/pre>\n<p>Now copy the php.ini file to the necessary location&#8230;<\/p>\n<pre><code class=\"cli\">cp php.ini-dist \/usr\/local\/php5\/lib<\/code><\/pre>\n<p>Wonderful! Now we have everything we need &#8211; we just have to configure it.<\/p>\n<h2>Configuring Apache<\/h2>\n<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>\n<h3>Configuration Options<\/h3>\n<p>You may want to change the document root &#8211; replace the line<\/p>\n<pre><code>DocumentRoot \"\/usr\/local\/apache2\/htdocs\"<\/code><\/pre>\n<p>With<\/p>\n<pre><code>DocumentRoot \"\/var\/www\/htdocs\" # Or whatever folder you want to set as the document root.<\/code><\/pre>\n<p>Also change the line<\/p>\n<pre><code>&lt;Directory \"\/usr\/local\/apache2\/htdocs\"&gt;<\/code><\/pre>\n<p>to<\/p>\n<pre><code>&lt;Directory \"\/var\/www\/htdocs\"&gt;<\/code><\/pre>\n<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>\n<p>If you want to use .htaccess file to configure different folders, find the line<\/p>\n<pre><code>AllowOverride None<\/code><\/pre>\n<p>inside the <code>&lt;Directory \"\/usr\/local\/apache2\/htdocs\"&gt; ... &lt;\/Directory&gt;<\/code> tag and change it to <\/p>\n<pre><code>AllowOverride All<\/code><\/pre>\n<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>\n<pre><code>DirectoryIndex index.html index.html.var<\/code><\/pre>\n<p>and replace it with, say,<\/p>\n<pre><code>DirectoryIndex index.php index.html index.html.var<\/code><\/pre>\n<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>\n<p>Now we must associate all files with the extension &#8216;php&#8217; with the PHP scripts handler. For this find the line<\/p>\n<pre><code>AddHandler type-map var<\/code><\/pre>\n<p>and add the following line below that line &#8211; like this<\/p>\n<pre><code>AddHandler type-map var\nAddHandler php5-script\tphp<\/code><\/pre>\n<p>Below that there is a AddType section. Add the following line to this section.<\/p>\n<pre><code>AddType application\/x-httpd-php .php<\/code><\/pre>\n<h2>Start the Server<\/h2>\n<p>You can test your installation by starting your server. Open a terminal and run the following command.<\/p>\n<pre><code class=\"cli\">\/usr\/local\/apache2\/bin\/apachectl start<\/code><\/pre>\n<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>\n<pre><code class=\"php\">&lt;?php\nphp<!-- wp bugfix -->info();\n\n<\/code><\/pre>\n<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>\n<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>\n<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>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>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 &#8211; then we have to install it from source.<\/p>\n<\/div>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,17,21,30],"tags":[82,147,161,173,252,262],"class_list":["post-132","post","type-post","status-publish","format-standard","hentry","category-apache","category-mysql","category-php","category-web-development","tag-compile","tag-install","tag-lamp","tag-linux","tag-server","tag-source"],"_links":{"self":[{"href":"https:\/\/www.bin-co.com\/blog\/wp-json\/wp\/v2\/posts\/132","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bin-co.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bin-co.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bin-co.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bin-co.com\/blog\/wp-json\/wp\/v2\/comments?post=132"}],"version-history":[{"count":0,"href":"https:\/\/www.bin-co.com\/blog\/wp-json\/wp\/v2\/posts\/132\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.bin-co.com\/blog\/wp-json\/wp\/v2\/media?parent=132"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bin-co.com\/blog\/wp-json\/wp\/v2\/categories?post=132"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bin-co.com\/blog\/wp-json\/wp\/v2\/tags?post=132"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}