1. Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

Guide: Setting up LAMP in vmware for development/deployment

Discussion in 'Programming & Webmastering' started by streetfighter 2, Feb 19, 2011.

  1. streetfighter 2

    streetfighter 2 New Member

    Joined:
    Jul 26, 2010
    Messages:
    1,658 (0.97/day)
    Thanks Received:
    732
    Location:
    Philly
    Setting up rPath LAMP VMware Appliance for Development
    What’s LAMP?
    LAMP is an acronym which stands for Linux Apache MySQL Perl/PHP/Python. The Windows version of LAMP is . . . WAMP. If you’re not sure what any of that is or why it’s useful, you should probably move along :).

    What’s rPath?
    rPath is a company that happens to provide a linux distribution aptly named rPath Linux. rPath uses the conary package system.

    What’s it to you?
    I needed a safe, simple and free development environment for SQL and my various ASP.NET/PHP web apps, and this post explains how I went about it. The rPath LAMP image isn’t particularly special (or is it?), it was just the first one to pop-up on a google search. Be warned, security is not a priority in this tutorial!

    Prerequisites to use this tutorial
    -basic understand of file structure in Windows/linux
    -basic file/folder manipulation skills in bash
    -WinSCP or other such file transfer client
    -some experience using vmware player
    -rudimentary scripting capabilities (editing XML files, etc.)
    -some conceptual knowledge of SQL, linux, apache, .NET/mono, etc. is a plus ;)

    LAMP version information used in tutorial
    Column 1 Column 2
    0 Component Version
    1 rPath LAMP 3.0.1
    2 kernel 2.6.29.3
    3 apache 2.2.9
    4 mono 1.2.6
    5 mod_mono 1.2.1
    6 php 5.2.8
    7 vbnc (optional) 2.1 (see attached)
    8 MySQL 5.0.51a


    This is my 1000th post. I hope you find it useful! :toast:

    [hr]
    Configuration
    [HIGHLIGHT]NOTICE:[/HIGHLIGHT] Other than the first two steps, none of the steps are required to run rPath LAMP. If you do not care for a particular feature that I added then simply skip the step.

    1 [HIGHLIGHT]Getting started[/HIGHLIGHT]
    Download and install vmware player if you don’t have it.
    Download and unzip LAMP vmware appliance where ever you want to run it from.

    2 [HIGHLIGHT]Accessing phpMyAdmin[/HIGHLIGHT]
    1. Boot up the LAMP VM by selecting it through vmware player or double-click the vmx file. You're almost done :laugh:!
      (If you’re following the official instructions it’ll tell you to login to the web interface to configure your password. I’d recommend doing that if you’re making it publicly accessible.)
    2. Once the VM is booted up you’ll see a screen to login; ignore it. Instead, hit ctrl+alt+space (to disable the ctrl+alt key combo) followed by ctrl+alt+f2. Doing so will bring you to the *real* login screen which gives you terminal access.
    3. Use the login “root" with no password. I’d suggest setting passwords for the root and web account:
      Code:
      passwd root
      Passwd web
    4. Once a password is set for the web account you can use it to login to phpMyAdmin by browsing to http://<vm_ip>/phpMyAdmin/

    3 [HIGHLIGHT]Adding MySQL exception to firewall rules[/HIGHLIGHT]
    Even though phpMyAdmin is an excellent administration tool it’s still not as interactive as MySQL Workbench and it lacks the charm of the classic MySQL CLI. If you agree with me you’ll need to add an exception for MySQL in the firewall rules. The order of rules listed in iptables is important, which is why the last rule needs to be temporarily removed. Here are the commands:
    Code:
    iptables -D RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited
    iptables -A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
    iptables -A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited
    service iptables save
    4 [HIGHLIGHT]Using ASP.NET v1.0/1.1 assemblies (precompiled or C#)[/Highlight]
    rPath comes with mod_mono preconfigured, but it only supports .NET v1.0/1.1 assemblies that are precompiled or written in C#. All you need to do to is put your aspx and cs files in /srv/www/html.

    5 [HIGHLIGHT]Changing mod_mono to ASP.NET v2.0[/Highlight]
    1. Open /etc/httpd/conf.d/mod_mono.conf
    2. Add the following line just below AddMonoApplications default "/:/srv/www/html":
      Code:
      MonoServerPath default /usr/bin/mod-mono-server2
    3. To enable debug information open /etc/mono/2.0/web.config
    4. Add <customErrors mode="Off"/> near the top according to:
      Code:
       	<configuration>
      	  <system.web>
      		<customErrors mode="Off"/> 
    5. Restart the httpd service with the command:
      Code:
      service httpd restart

    6 [HIGHLIGHT]Adding MySQL Connector/NET to mono[/Highlight]
    (This won’t work unless you completed step 5.)
    1. Download Connector/NET for .NET & Mono. The file should be named something like mysql-connector-net-6.3.6-noinstall.zip,
    2. Copy the file mysql.data.dll in the zip’s v2 folder to the LAMP VM (I suggest ~/connector-net).
    3. Run the following commands to correct the case and permissions:
      Code:
      mv mysql.data.dll mysql.data.dll.old
      cp mysql.data.dll.old MySql.Data.dll
      rm mysql.data.dll.old
      chmod ugo+x MySql.Data.dll
    4. (OPTIONAL) Copy MySql.Data.dll to /usr/lib (in case you get reference errors).
    5. Register MySql.Data.dll so it can be used in mono using the following command:
      Code:
      gacutil /i MySql.Data.dll
    6. Open /etc/mono/2.0/web.config and add the line <add assembly="MySql.Data" /> like so:
      Code:
       	<configuration>
      	  <system.web>
      		<compilation>
      		  <assemblies>
      			<add assembly="MySql.Data" />
    7. Restart the httpd service with the command:
      Code:
      service httpd restart

    7 [HIGHLIGHT]Adding VB.NET support to mod_mono[/Highlight]
    (This won’t work unless you completed step 5.)
    1. Download the pre-packed vbnc for rPath.
    2. Unzip it and copy it somewhere innocuous on the LAMP VM (like ~/vbnc)
    3. I’ve included an install script for vbnc. You’ll need to run it as root:
      Code:
      chmod 755 ./install.sh
      sudo ./install.sh
    4. Assuming the installer completes successfully, just restart the httpd service:
      Code:
      service httpd restart
    [hr]
    Examples
    Script Examples
    To use the following examples you must have completed steps 1, 2, 5 & 6. You will also need a single table database that I provided with the included tpu.sql. (My example database is only for proving the functionality of the example scripts and is not suitable for learning SQL. If you’re interested in learning SQL try the sakila sample db.)

    Loading the sample database
    I suggest using phpMyAdmin which can be found by opening a browser and going to the following URL:
    http://<vm_ip>/phpMyAdmin/
    1. Login to phpMyAdmin with the web account and the password you made in step 2 of the configuration.
    2. Click on the Import link on the main page.
    3. Click the button Choose... and browse to the location of tpu.sql that you downloaded.
    4. Press Go and the database will be created and the data entered.
    5. All the tutorial scripts were written for user tut_user with password password. To simplify the tutorial process repeat steps 3 & 4 of this section with the file tut_user.sql.

    phpSQL.php – A php based MySQL query example
    PHP:
    <html>
      <head>
        <meta charset="utf-8" />
        <title>php MySQL Database Query</title>
      </head>
      <body>
        <?php
        $db 
    mysql_connect('localhost''tut_user''password') or die(mysql_error());
        
    mysql_select_db ('tpu'$db) or die(mysql_error());
        
        
    $output "<table cellspacing=\"0\" rules=\"all\" border=\"1\" style=\"border-collapse:collapse\\;\">\n";
        
    $output .= "<tr><td>thread</td><td>time_rel</td><td>user_name</td><td>posts</td></tr>\n";
        
    $query mysql_query('SELECT * FROM latest',$db) or die(mysql_error());
        While( 
    $rows mysql_fetch_array($query)) {
          
    $thread      $rows['thread'];
          
    $time_rel    $rows['time_rel'];
          
    $user_name      $rows['user_name'];
          
    $posts      $rows['posts'];
          
    $output   .= "<tr><td>$thread</td><td>$time_rel</td><td>$user_name</td><td>$posts</td></tr>\n";
        }
        
    mysql_free_result($query);
        
    mysql_close($db);
        
        echo 
    "$output\n";
        echo 
    "</table>\n";
        
    ?>
        </body>
    </html>
    csSQL.aspx – An ASP.NET C# based MySQL query example
    PHP:
    <%@ Page Language="C#" debug="true" %>
    <%@ 
    Import Namespace = "System.Data" %>
    <%@ 
    Import Namespace = "MySql.Data.MySqlClient" %>
    <
    script language="C#" runat="server">
        protected 
    override void OnLoad(EventArgs e)
        {
            
    DisplayQuery();
            
    base.OnLoad (e);
        }

        private 
    void DisplayQuery()
        {
            
    DataSet dataset = new DataSet();
            
    string connectionString =
              
    "Server=localhost;" +
              
    "Database=tpu;" +
              
    "User ID=tut_user;" +
              
    "Password=password;" +
              
    "Pooling=false";
            
    string sql "SELECT * " "FROM latest";
            
    MySqlConnection conn = new MySqlConnection(connectionString);
            
    MySqlDataAdapter adapter = new MySqlDataAdapter();
            
    adapter.SelectCommand = new MySqlCommand(sqlconn);
            
    adapter.Fill(dataset);

            
    MySQLDataGrid.DataSource dataset;
            
    MySQLDataGrid.DataBind();
        }
    </script>

    <html>
        <head>
            <title>C# MySQL Database Query</title>
        </head>
        <body>
            <form runat="server">
                <asp:DataGrid id="MySQLDataGrid" runat="server" />
            </form>
        </body>
    </html>
    vbSQL.aspx – An ASP.NET VB based MySQL query example (requires step 7)
    PHP:
    <%@ Page Language="VB" debug="true" %>
    <%@ 
    Import Namespace = "System.Data" %>
    <%@ 
    Import Namespace = "MySql.Data.MySqlClient" %>
    <
    script language="VB" runat="server">

    Sub Page_Load(sender As ObjectAs EventArgs)

        
    Dim myConnection  As MySqlConnection
        Dim myDataAdapter 
    As MySqlDataAdapter
        Dim myDataSet     
    As DataSet

        Dim strSQL        
    As String
        Dim iRecordCount  
    As Integer

        myConnection 
    = New MySqlConnection("Server=localhost;Database=tpu;User ID=tut_user;Password=password;Pooling=false;")

        
    strSQL "SELECT * FROM latest;"

        
    myDataAdapter = New MySqlDataAdapter(strSQLmyConnection)
        
    myDataSet = New Dataset()
        
    myDataAdapter.Fill(myDataSet"latest")

        
    MySQLDataGrid.DataSource myDataSet
        MySQLDataGrid
    .DataBind()

    End Sub

    </script>

    <html>
        <head>
            <title>VB MySQL Database Query</title>
        </head>
        <body>
            <form runat="server">
                <asp:DataGrid id="MySQLDataGrid" runat="server" />
            </form>
        </body>
    </html>
    That’s all for now. I have code-behind examples that I may upload later. Please help yourself to the references that I used in writing this tutorial, and have fun!

    References:
    http://wiki.rpath.com/wiki/Appliance:Apache_Appliance
    http://docs.rpath.com/rbuilder/5.5/rBuilder_Administration_Guide/ch-command-line_access.html
    http://wiki.rpath.com/wiki/Appliance:LAMP_Appliance
    http://wiki.rpath.com/wiki/Appliance_Talk:LAMP_Appliance
    http://www.codeproject.com/KB/cross-platform/introtomono2.aspx
    http://www.mono-project.com/Mod_mono#ASP.NET_2_apps_do_not_work
    http://dev.mysql.com/doc/refman/5.1/en/connector-net-installation.html
    http://www.mono-project.com/FAQ:_ASP.NET
    http://msdn.microsoft.com/en-us/library/015103yb.aspx
    http://www.mono-project.com/VisualBasic.NET_support
    http://dev.mysql.com/doc/refman/5.0/es/connector-net-examples.html
    https://github.com/mono/mono-basic/archives/master
     

    Attached Files:

    Last edited: Feb 22, 2011

Currently Active Users Viewing This Thread: 1 (0 members and 1 guest)

Share This Page