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?

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
Death Metal
  • 269
  • 6
  • 15
  • 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 Apr 14 '14 at 01: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 Apr 14 '14 at 01:31
  • sudo's builtin for a reason =) – evamvid Apr 14 '14 at 01: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](http://unix.stackexchange.com/q/106529/22222)). – terdon Apr 14 '14 at 02:19
  • @terdon whoops! My Bad...howbout "sudo's _there_ for a reason"? – evamvid Apr 14 '14 at 02:28
  • 1
    Could OP just use `pkexec` instead of `sudo`? – evamvid Apr 14 '14 at 02:30
  • @strugee: Thank you for your reply. I do not see anything wrong in builtin packages. I have had some issues after installing built in packages of mysql, hence I do not want to play around with them any more. Second, I like trouble shooting from source code installation, if I wouldn't have done that, then probably I wouldn't have come to know port 80 is required for website. :) I am fine with installing with sudo, but I do not want to use `sudo` thereafter. – Death Metal Apr 14 '14 at 16:43
  • @DeathMetal yes, but _why_ don't you want to use `sudo` afterward? your insistence on avoiding it just doesn't make a lot of sense. – strugee Apr 14 '14 at 17:43
  • @strugee. :) I do not want to have all the power with sudo and knowingly, unknowingly disrupt files sometime. – Death Metal Apr 14 '14 at 21:42

1 Answers1

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

Michael Butler
  • 270
  • 2
  • 8
  • 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. – Michael Butler Apr 14 '14 at 03: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` ? – Death Metal Apr 14 '14 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`? – Death Metal Apr 14 '14 at 16:50
  • 1
    You can add the `` 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. – Michael Butler Apr 15 '14 at 03:54