208 Comments

  1. amit

    great post.n Thanks

    Reply
  2. Mark

    Hi Linerd -

    Your tutorial worked beautifully for me - every step.

    Just reached the point where I downloaded the actual site and DB from my provider (for my first "test site") and the strangest thing is happening. I don't know what to make of it.

    + Before downloading the site files (pretty much a base installation of WordPress thus far) and DB - I would go to http://site1.com on my local machine and see the "Hello World" index.html that I wrote. Just fine.

    + After downloading (and configuring teh local database) - when I go to what I would expect to be the "local instance" of this site again (the non-www URL), it's automatically mapping to the "www" URL and taking me to the live site on the real web server. I validate this explicitly by pulling the network cable -- and wouldn't you know it... I get a connection timeout!!

    Do you have any idea why my local machine is now connecting to the [real] web server server when it didn't before? Is there something in my site that's making this mapping that I need to override? Any thoughts??

    Sorry if this is a noob question... but hey, I'm a noob!

    Any insights most appreciated. Thanks!

    Mark

    Reply
    • Linerd

      So you downloaded the files from your provider rather than manually installing WordPress? The only thing I can figure is that there is a 301 redirect that's set up in one of the files from your provider's server. Take a look at this page: http://www.dailyblogtips.com/how-to-setup-a-301-redirect/

      The redirect will be either the one of the PHP methods or one of the Apache methods. ASP is for Microsoft servers. I'm betting it's an Apache redirect in your .htaccess file.

      If you can't find it, I suggest you blow away everything you downloaded and do a fresh local WordPress installation. http://tuxtweaks.com/2009/11/how-to-install-wordpress-on-ubuntu-part-1/

      I just work on my website theme locally and then upload the theme folder to my provider's server when I have things looking the way I want.

      One final thought. You said in your comment that you go to site1.com. You might want to try changing it to just site1.

      Reply
      • Mark

        Thanks -

        Had only a little while to work this, but, I took your last comment and reworked my set-up so that mt local directories are truly site1, site2, etc... no longer site1.com, site2.com. That definely sounds better. It didn't resolve the problem yet, but it's cleaner.

        No obvious 301 redirects that weren't in the fresh WordPress download files. When I "grep 301 *" there were five php files with a 301 string - both my original WordPress and the new WordPress files matched on this front!

        Will try the fresh install via your other on-line links. We'll see how it goes...

        One question per another comment you made, though -

        So the core goal here is merely to modify my template, then? I'm trying to educate myself - and this clearly rings true. I have one site partially-functional (a small amount of initial content), but I do indeed want to significantly modify the template. If that's the case - I shouldn't be terribly worried about having my local content match as that's moot. It's all about the site design on the LAMP environment (and, naturally using as a repository for backups). Is that pretty much the philosophy?

        Thanks again!!

        Mark

        Reply
        • Linerd

          Yeah, I just use the local LAMP setup for theme development and customizing. I don't really use it for backups of my site. My provider has a backup system available in Cpanel that will backup all of the site files and databases in one shot. Then I just download the archive to save it locally.

          Reply
  3. Squimpleton

    It worked the first day, but when I came back after, it didn't. I realized it was because the host file kept resetting to what it was before I saved it. So I re-edited it to add the various permissions.

    And now Site 1 and Site 2 are available, but for some reason they're accessing the files from my original localhost site. I checked the site1 and site2 config files and they still have home/myname/webdev/site1 and site2 as their documentroots and directories. So I don't get why they're pulling the files from localhost.

    Help?

    Reply
    • Squimpleton

      Never mind. I had skipped a small step.

      Reply
  4. Paul

    Hey, Great Tutorial.

    I am attempting to setup a testing environment using unbuntu, however I am having some difficulties getting my site to work properly once placed into the var/www/ folder.

    It seems none of the relative paths work. In my index.php file for example, I have a bunch of includes and images, however none of them appear when I view the page, only the basic html text appears.

    I am assuming the most likely reason is that the file does not have read access to those files? Is this the case?

    Is there a quick terminal command to fix this if it is?
    Any help would be much appreciated.

    Reply
    • Linerd

      I'm not sure what the correct permissions are. I'm thinking the files will need read and execute permission. To give everything read and execute permission, use this command.

      sudo chmod -R a+rx /var/www
      Reply
  5. Sumesh Gupta

    I have done exactly as you have described above and site1 and site2 are working absolutely wonderfully. I wish to know if I can create name base virtual hosts in apache with localhost and access them from same machine?
    (www.myname.com etc)
    I tried the process after reading a few howto's in ubuntu forums. However whenever I restart apache a warning is received that unnumbered virtual hosts and numbered virtual hosts port 80 are not supported and reloading fails. Can I get some help with this problem?

    Reply
    • Linerd

      Sorry, I can't help you with that one. That's beyond the scope of anything I've tried to do. The Ubuntu Forums are probably a better place to find help for this. Good Luck.

      Reply
  6. Patrick

    Hi Linerd,

    Great tutorial, finally managed to get two sites going on a LAMP server.
    This may be a stupid question, but how do i get to the sites without modifying the hosts file, what address?
    I've tried the obvious http://localhost/site1 & http://localhost/site1/index.html

    Reply
    • Linerd

      Hmm... I gave this a try and http://localhost/site1/ works for me. Did you make sure to enable the sites? Did you make sure to reload Apache?

      sudo a2ensite site1
      sudo /etc/init.d/apache2 reload

      Edit: Interesting, I just added the sites back to my hosts file and the change wouldn't take until I did a full restart of Apache, so maybe that's the trick to get it working for you.

      sudo /etc/init.d/apache2 restart
      Reply
      • Patrick

        Hi Linerd,

        Thanks for the quick reply. I tried restarting Apache - no joy, I even tried undoing the fqdn fix you posted in case that was affecting it - no joy.

        Turns out to be able to access site1 & site2 via http://localhost/site1/ or http://localhost/site2/ I needed to put the site1 & site2 folder under /var/www/ as opposed to /home/patrick/webdev/ and edit the /etc/apache2/sites-enabled/site1 & /etc/apache2/sites-enabled/site2 files appropriately.

        Although as yet I haven't tested it from another machine, I'm guessing I will now be able to access it from http://192.168.1.82/site1 etc.

        Just thought I would post back in case any other users have been spending as much time trying to get that going as i have! LOL

        Thanks for the great tutorial. Feel free to edit this comment to keep it concise if you wish.

        Reply
  7. Bobot

    Hi Linerd,

    I just had a fresh install on a new HDD and followed your tutorial for the third time and it worked again.

    Muchas gracias

    Bobot

    Reply
    • Linerd

      De nada.

      Reply
  8. noip

    Thanks for the tutorial. Just wish I understood how those commands worked. :) I've set up WAMP several times, but this is my first LAMP.

    Reply
  9. Lee Boone

    is there a way for other machines on a local network to view these sites? I can view the /var/www/index.html page using either the ip address (http://192.168.1.100) or the name (http://linux-box) of my linux machine, but can't seem to find the custom sites. (Which work perfectly on the linux computer, thank you)

    Reply
  10. Rudy

    Actually, I do have to add that it will only allow __.sytes.com to point to one of the site and it will not work in a __.sytes.net/site1 and __.sytes.net/site 2 way.

    Still need to figure out this one.

    Reply
  11. Rudy

    Is the configuration the same if using a no ip tool like NO-IP?
    I cannot reach any of the 2 sites when using the NO-IP URL (.syte.net).
    I tried adding the following entry in /etc/hosts:
    192.168.1.100 site1 site2
    (192.168.1.100 being the IP address of my Linux box)
    Although, if using the URL .sytes.net, I do reach the 'It Works!' Apache test page from my webserver.
    Any help would be greatly appreciated.

    Thx!

    Reply
    • Linerd

      Rudy, I haven't tried this setup with a dynamic DNS setup. I'm thinking you would most likely have to modify the Apache configuration. However, it might work like it does when accessing the host machine web server from a VirtualBox guest. Have you tried __.sytes.net/site1 or __.sytes.net/site2?

      Reply
      • Rudy

        Linerd,
        Thx for the quick reply.
        Yes I did try __.sytes.net/site1 or /site2 without luck.
        I actually figured it out. I had to disable the default config under /etc/apache2/sites-available by using the 'a2dissite' command (sudo a2dessite default).

        Reply
  12. Ryan

    Just found the hack under the older posts...sorry should have checked there first

    Reply
  13. Ryan

    Fantastic post!!!!
    I managed to get this working so if I VNC onto my ubuntu desktop server I can visit http://site1/ no problems but if i try from my laptop I get an error... should I be adding site1 to the second line of /etc/hosts @127.0.1.1 instead of 127.0.0.1 localhost?

    Thanks a million

    Reply
  14. DINESH BHATT

    I NEEDED SOME MATERIAL TO FINISH MY REPORT ,I THINK I GOT IT THANK U

    Reply
  15. Jeff

    Awesome post! It worked great!

    Reply
  16. James

    Linerd,

    Thanks for cleaning up the comments. I fixed the issue. I had the database call parameters typed as strings ( ' ' ) by removing the single string quotes I was able to get the database to connect and the page would then load.

    Thanks again for the tutorial to set up the multiple web application development environment for apache.

    Reply
  17. James

    I installed LAMP on a setup of Ubuntu 10.04 and added the site1 site2 environments exactly as you show. Both sites worked just as you described. I have started using site1 to follow a series of tutorials on php.

    I have run into a problem and am baffled. Using firfox, I can got to localhost/site1 and call the index.html page and see the "Site 1 works!" in the browser
    I have copied the testing.php into site1 and when I call the page it gives me the php page, so I know that apache is serving up php from site1 as well.

    I have built the following page called index.php which calls for a MySQL database called gwdb and a table in the database called guitarwars. I have written the code exactly as it is written in the tutorial changing only the location of the database to site1 in the call to connect to the database; $dbc = mysqli_connect('site1','root', 'password', 'gwdb')

    All I am getting in firefox is a blank page. In chromium web browser I am getting "Oops this link appears to be broken"

    I am new to Linux and PHP and trying to learn and I can't see what is causing this break in the link. I have included the code below:

    
    <html xmls="http://www.w3.org/1999/xhtml"
    xml:lang"en" lang="en">
    
    <head>
    <title>Guitar Wars - High Scores</title>
    <link rel="stylehseet" type="text/css" href="style.css" />
    </head>
    <body>
           <H2>Guitar Wars - High Scores</h2>
           <P>Welcome, Guitar Warrior, do you have
           what it takes to crack the high score list?  
           If so, just <a href="addscore.php">add
           your own score</a>.</p>
           <hr />
    
    <?php
           // Connect to the database
           $dbc = mysqli_connect('site1','root', 'mailbox1823', 'gwdb')
                   or die('Error connecting to database');
    
           // Retrieve the score data from MySQL
           $query = "SELECT * FROM guitarwars";
           $data = mysqli_query($dbc, $query);
                   or die('Error quering database');
    
           // Loop through the array of score data, formatting it as HTML
           echo '<table>';
           while ($row = mysqli_fetch_array($data)) {
                   // Display the scare data
                   echo '<tr><td class="scoreinfo">';
                   echo '<span class="score">' . $row['score'] . '</span><br />';
                   echo '<strong>Name:</strong> ' . $row['name'] . '<br />';
                   echo '<strong>Date:</strong> ' . $row['date'] . '</td></tr>';
           }
           echo '</table>';
    
           mysqli_close($dbc);
    ?>
    
    </body>
    </html>
    
    
    Reply
    • Linerd

      James - I edited your comments into one to capture the spirit of what I think you were trying to show.

      I'm no php pro, so I doubt I'll be much help. I did try your file on my machine and it doesn't load. The file does work if I remove the php portion. Maybe another reader can offer some advice.

      Reply
    • David

      in your mysqli_connect statement you should still be using localhost not site1 because the mysql server is on localhost.

      Reply
  18. Pragasan

    Hi Linerd

    Thanks for the tutorial. I'm a newbie trying to set up my own ubuntu linux server for a production enviroment to host some of my applications. Is the setup tutorial for lamp and apache suitable for production environments? Also if we want to keep Ubuntu lamp installation up to date is there a command that we use?

    Thanks again for the great tutorial.

    Reply
    • Linerd

      Hi Pragasan - I'm confident that the LAMP setup would be fine for a production environment. The Apache configuration, I'm not sure. I know little more than what I've documented on this website. I'm not sure that I've followed best practices for Apache, but the setup here works well for an offline development environment. I'd encourage you to consult the Apache documentation if you want to set up a production environment.

      As far as keeping things up to date; if you're running Ubuntu Desktop, then the update manager should keep you up to date. Otherwise, you can update your system with

      sudo apt-get update
      sudo apt-get upgrade
      Reply
      • Pragasan

        Hi Linerd

        Thanks for all the help.

        take car

        Reply
  19. Korouu

    Hey man! You are too great! What others cannot do, you have done. Now my long time desire has become possible because of your tutorial. And thanks to the almighty for showing me to this website.

    Reply
  20. roy byer

    Hello there

    I have followed the tutorial and it seemed to work on the command line but when I tried to access http://site1/ i get 403 forbidden
    You don't have permission to access / on this server.
    where did I go wrong.
    regards

    roy

    Reply
    • Linerd

      Check out the comments from Larry. He had the 403 error and it turned out to be a permissions problem. Do you have read permission open on your home directory?

      Reply
      • roy byer

        Hello Linerd

        Thank you very much that was the problem. Great tutorial.
        Thanks again

        Roy

        Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>