Configure Apache and public_html on Ubuntu

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

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.

This content is published under the Attribution-Noncommercial-Share Alike 3.0 Unported license.

This entry was posted in Ubuntu and tagged , , . Bookmark the permalink.
  • rooth

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

    Have a good one!

  • Bigbrovar

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

  • Linda

    Thank you!

    It worked.

  • Bigbrovar

    @Linda am glad it worked, cheers

  • Bert

    Thank you so much for posting this info :-D

    • Bigbrovar

      You welcome am glad it worked for you

  • Xtrigit

    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?