bigbrovar

February 13, 2009

Configure Apache and public_html on Ubuntu

Filed under: Ubuntu — Bigbrovar @ 4:38 pm
Tags: , ,

I was trying to do this Today at work for my local webserver. but i couldnt find a definite guide on how this could be achieved on Ubuntu. After some trial and errors i was able to figure it out, and thought to share in case anybody out there is trying to implement this

First we installed apache with LAMP ( The linux webserver stack stands for Linux Apache MySQL PHP)

sudo tasksel

choose LAMP and press enter (remember to use the spacebar to select)

during the installation you would be asked for password for mysql root user

once installed

you then need to enable the mod_userdir, so your server’s Apache httpd server will respond to requests like http://yourserver.com/~public_html

hence Apache will handle the contents of /home/[User Name]/public_html/

to enable the mod_userdir we run this command

sudo a2enmod userdir

next we run this

/etc/init.d/apache2 force-reload

once this is done we now edit apache.conf pointing to your public_html

gksudo gedit /etc/apache2/apache2.conf

and we add this at the end of the file

UserDir /home/*/public_html

save and close

don’t forget to create a public_html directory in your home directory

mkdir $HOME/public_html

now we restart Apache

sudo /etc/init.d/apache restart

Now any content you place inside the public_html directory can be view from a browser

Browse to http://localhost/~yourname/ and you will see your stuff.

hope this helps someone.

16 Comments »

  1. Hi, Daniel from Sweden here. Thank you for the guide, worked like a charm.

    Have a good one!

    Comment by rooth — March 23, 2009 @ 10:42 pm | Reply

  2. Hi Daniel Glad to see that it worked for you.. nice Country btw hope to visit there in my life time

    Comment by Bigbrovar — March 24, 2009 @ 6:42 am | Reply

  3. Thank you!

    It worked.

    Comment by Linda — April 24, 2009 @ 5:08 pm | Reply

  4. @Linda am glad it worked, cheers

    Comment by Bigbrovar — April 24, 2009 @ 8:44 pm | Reply

  5. Thank you so much for posting this info😀

    Comment by Bert — June 21, 2009 @ 4:13 am | Reply

  6. I have a question:

    “…and we add this at the end of the file

    UserDir /home/*/public_html”

    Do I copy the exact same line? what I mean is if I have to insert the STAR between home/ and /PUblic html. Or do I have to replace it with something?

    thanks

    Comment by Xtrigit — July 8, 2009 @ 7:53 am | Reply

  7. wow this saved my life

    Comment by handa fanda — January 14, 2010 @ 8:06 pm | Reply

  8. Oh gosh, been looking at different places. This one works!!!!

    Comment by Nate — February 3, 2010 @ 9:58 pm | Reply

  9. I couldn’t figure out why this wasn’t working for me until I realized that I was using a windows machine logged into an ubuntu box elsewhere… duh, obviously http://localhost on this machine is not going to find anything.

    When I went to http://x.x.x.x/~user it was all working like a champ.

    Thanks!

    Comment by jimmyjohn — September 11, 2010 @ 1:40 pm | Reply

  10. Didn’t work.

    Comment by Monsquaz World — April 18, 2011 @ 4:17 pm | Reply

  11. one issue I ran into was that HTML files worked but PHP files did not.
    I Solved the issue by following the instructions in /etc/apache2/mods-enabled/php5.conf
    Basically you have to comment out some lines.

    Comment by Alex — July 29, 2011 @ 9:58 pm | Reply

  12. Very nice, just went through your steps with Ubuntu 11.04 server, have a few notes/updates:

    a) need to run this command (“/etc/init.d/apache2 force-reload”) with a ‘sudo’:

    sudo /etc/init.d/apache2 force-reload

    b) this line won’t work on default install of Ubuntu 11.04, ‘gksudo’ and ‘gedit’ are not included by default, instead use:

    sudo vi /etc/apache2/apache2.conf

    (or other editor, if you don’t like ‘vi’ ;^)

    c) your final step ( ‘sudo /etc/init.d/apache restart’ ) refers to a directory that doesn’t exist:

    sudo /etc/init.d/apache2 restart

    d) I followed Alex’s suggestion about php5.conf to enable PHP processing of files from my new ‘public_html’ directory – they worked great.

    Thanks a ton, hope the above notes help you improve this great resource for others.

    Ken

    Comment by KenKen Hansen — September 1, 2011 @ 4:32 am | Reply

    • I can not thank you enough for your feedback. I will definitely update my post with your observation and credit you. Kindly note that since last year I have migrated this blog to a self host blog at http://www.bigbrovar.aoizora.org, all the previous post here has also been migrated. I noted that you subscribed to this blog. I would recommend that you subscribe to the new blog since this one has not and will no longer be updated. Thanks again for the feedback

      Comment by Bobby (@bigbrovar) — September 1, 2011 @ 8:29 am | Reply

  13. AWESOME

    Comment by Felipe Carvalho — February 4, 2012 @ 6:32 pm | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: