0

I have multiple questions and I am confused.

Few months back, I was installing a software locally ~/bin. Tools got installed successfully and running fine till date. In installation it automatically created var/www/ and added its folders in ~/bin.

Now, I am trying to learn some php development. I have installed apache from source, locally on ~/someFolder, installation is complete. I did sudo ~/someFoler/bin ./apachetl start; localhost on browser, and It works message received on browser.

I do not want to use sudo, and do all my learning experiments in /usr/local or /usr/var/www. Sorry, I do not understand well these directories.

From what all I have read and gone through, most users work in /usr/var or usr/local. However, while copying, removing or doing anything it requires sudo.

What is the work around for this?

How do I get Apache and PHP working locally without using too many sudo commands?

I read port 80 is required to start the server. Hence, sudo is necessary while starting the server.

Any help in these would be highly appreciated.

machine specification: Linux 3.11.0-15-generic x86_64

Ubuntu 13.10

Edited

If I install apache and php by sudo, would I have to move my web pages to /var/www location?

9
  • 2
    there are a bunch of things wrong with this post. first, try to use exact paths: I have no idea where var/www/ is because I don't know where your current directory is. is it in your home folder? the root? be specific. also, why don't you like sudo? I don't see anything wrong with using Ubuntu's Apache packages. why in the world are you building everything yourself?
    – strugee
    Commented Apr 14, 2014 at 1:22
  • 3
    "I have multiple questions and I am confused." : Yup, so are we :) Please break this post into separate questions. Take each of the questions here and post them as a separate question. This site works by giving specific answers that solve specific problems, it doesn't work well when there are multiple issues combined in a single post. And everything that @strugee said as well.
    – terdon
    Commented Apr 14, 2014 at 1:31
  • sudo's builtin for a reason =)
    – evamvid
    Commented Apr 14, 2014 at 1:36
  • 2
    @evamvid sudo most certainly is not a builtin. It is a separate binary and is not even installed by default on most systems (including, believe it or not, Debian itself).
    – terdon
    Commented Apr 14, 2014 at 2:19
  • 1
    Could OP just use pkexec instead of sudo?
    – evamvid
    Commented Apr 14, 2014 at 2:30

1 Answer 1

4

Built-in Webserver

If your goal is to learn PHP I highly recommend you use PHP's built in webserver, available on PHP version 5.4 and up.

cd ~/mywebsite
php -S localhost:8080

You now have a webserver, tied to the ~/mywebsite directory, and accessible in the browser at

http://localhost:8080

This all runs in user mode so you don't need to sudo anything.


VHost solution

Even if you use the Apache method of serving up files, you can create a directory like ~/mywebsite and then create a VirtualHost entry that points to that location. Then all the files there can be edited normally by your username. Note: the VirtualHost root cannot use tilde (~), it has to be absolute like /home/johndoe/mywebsite

4
  • 1
    One more tip: you can add a line to your /etc/hosts file to setup nicer domain names instead of "localhost". Add a line such as 127.0.0.1 widgets.local and then you can use http://widgets.local in the browser. Commented Apr 14, 2014 at 3:31
  • So, my apache installed locally can work same as sudo? I will need more help to understand this. Where do I create this VirtualHost entry ? Commented Apr 14, 2014 at 16:45
  • @terdon I completely understand, I have to be particular while asking the question, but Apache and php are a bundle. I do not quite understand what has to be present in /var? If I install php and apache with sudo would I continue to use sudo to move files? Do my files have to be present in /var/www? Commented Apr 14, 2014 at 16:50
  • 1
    You can add the <VirtualHost> block anywhere in the apache configuration file. If you installed it as a user, I'm not sure where it is, but you can try find . | grep conf to find it in your home directory. Commented Apr 15, 2014 at 3:54

Not the answer you're looking for? Browse other questions tagged .