Access other folder then /var/www/html in Apache2 over http
Solution 1
Symlink way
If you want you can simply make an symlink to it, like i did on my Raspberry Pi, but I'm not sure if it's safe when your website is public. It works in home network.
Let's say you want to access /home/j
(because "j" is my username) from your /var/www
. To do that you'll need command ln -s /home/j jhome
. Make sure you are in /var/www
while running this command.
Now you should be able to access it simply using cd jhome
. You can test it by putting html file inside /home/j
and linking to it by for example your index.html
.
You can do same thing with other directories and names.
More professional, Apache configuration way
Also, I've found some Apache documentation here and Stack Overflow topic, I think it's more professional way to do same thing and I believe it's right way to do it.
It turns out that you need to add Alias /alias_directory /path_on_your_machine
line to your Apache config file (which for me is /etc/apache2/apache2.conf
). (it also works for me) I recommend backuping file before editing it.
Here are exact commands I used:
-
cp /etc/apache2/apache2.conf{,.bak}
- make backup -
echo "Alias /jhome /home/j" >> /etc/apache2/apache2.conf
- append line, you can also do that withnano
or other text editor. -
service apache2 restart
- restart Apache, it won't work without it
Remember to run commands as root, because You'll get permission errors without it.
I hope I helped you in some way. :)
Solution 2
If you have phpMyAdmin up and running, you probably have installed apache2. The process of mapping an http address to a directory in your localmachine is called a virtual host. Read more on this here. Or google for how to create a virtual host and a domain for my local machine.
I can guide you if you need more assistance on this matter.
Related videos on Youtube
DrugCrazedRebel
Updated on September 18, 2022Comments
-
DrugCrazedRebel over 1 year
JUST FOUND THIS; FOR PPL WITH APACHE PROBLEMS MAYBE. ALSO THIS SOLUTION SEEMS TO BE FOR THE PATIENT ONES xD
http://sites.duke.edu/workblog/files/2014/12/www.dedoimedo.com-apache-web-server-lm.pdf
I have been working on this for 3 days now. Finally able to acces http://[my.domain].com/ (installed mySQL and PHPmyAdmin, but I just read that those are not really needed? Cant work with them (yet) anyway so!)
when entering [mydomain]/com/ in a browser, without my /website.html, I get Index of/.
With indeed my website listed.Is there a nice and simple way to make HTML links inside website.html point to certain files and/or folders in my /home/..../Downloads/?
Or otherwise include a link onto the "Index of /" that appears in my browser? So i guess my question is, how should I make a 2nd Directory root?
When I have not been clear enough Im sorry! Just tell me what you need to know! Also thank you all very much for your time and effort! Really appreaciate it!
-
DrugCrazedRebel about 9 yearsill edit my main post for clearity
-
Jacajack about 9 years@DrugCrazedRebel Did any of described methods help you?
-
Nasik Shafeek about 9 years@DrugCrazedRebel I can explain you how to create a virtual host and add a local domain name for it if you want? And if that is exactly what you want from this question.
-
DrugCrazedRebel about 9 yearsty very much! I thinks im getting close from Jacajack's link--> Just dont get this.....
-
DrugCrazedRebel about 9 years"UserDir directive used Translated path UserDir public_html ~bob/public_html/one/two.html UserDir /usr/web /usr/web/bob/one/two.html UserDir /home/*/www /home/bob/www/one/two.html The following directives will send redirects to the client: UserDir directive used Translated path UserDir example.com/users example.com/users/bob/one/two.html UserDir example.com*/usr example.com/bob/usr/one/two.html UserDir example.com/~*/ example.com/~bob/one/two.html"
-
DrugCrazedRebel about 9 yearsso whats it gonna be? UserDir /home/dcr/Downloads UserDir /usr/web/dcr/Downloads or more like UserDir dcr.asuscomm.com/dcr/Downloads? So as far as i understand, i should add 1(?) of those to userdir.conf?
-
DrugCrazedRebel about 9 yearsTy very much also! at first Alias confused me, but getting closer and closer. But as far as I understand, Apache2 is fully capable on hosting a website + directory all by itself? With the complete LAMP stack? Cause php and mySQL don't really help, with my current knowledge it just makes it more incomprehensible! @kisanme
-
Jacajack about 9 years@DrugCrazedRebel I have to admit that I'm not any Apache or web expert, but I use it, and it works for me very good. I don't use databases, but I can tell you that php works for me and I can use RPi GPIO without any configuration.
-
DrugCrazedRebel about 9 yearsmaybe you can try this... dcr.asuscomm.com/new.html xD Just to confirm my failure, OR succes on the website matter
-
Jacajack about 9 years@DrugCrazedRebel In link you sen there's big "451 -" text. I'm not sure if it's some kind of error or something. I can try to help you tomorrow, because it's almost 1:00 am here and I'd like to go to sleep. ;)