How should I place files on apache2 HTTP server - linux

I am on Kali linux which comes with the apache2 http installed. Under /var/www/ there is a index.html file which is the default index page that will show up on localhost. I have this folder containing all my .html .css .js and some pictures that I want to put on the Apache2 server. Should I just copy/paste the folder under /var/www ?

Thats the traditional way to do it.
if you have virtualhosts or something a bit more complex then you might consider something else but typically people just drop everything in under /var/www (or the equivalent for a given disto or OS )

Yes, though you may need to adjust the accsess rights, and if you want you can use the apache config, or mount --bind, or git clone/pull. Start with the simple option then look into the other options to see if they offer you any benefit.

Related

Serving Node.js files from a LXC Turnkey container -Apache configuration needed?

I hope that I will not waste everyone's time, nor embarrass myself, but please hear/read my problem. I am new to this, so please bear with me.
Someone at work wrote a crude code in Node.js and I can see the .html files by having localhost: 8080 as the URL in the browser, while having the VisualStudio starting the npm with npm start command. Am I explaining this clear enough?
The webpages are displayed and all, but now comes the hurdle.
How can i have those pages served from a a Linux server?
If by analogy, I put some.html page inside the /var/www/ in a Apache server, pointing to the server's IP/somepage.html i can visualise it, what needs to be set up on a similar Node.js server?
Where do I have to put those files, inside what directory and what configuration is needed?
I thought to create a small LXC container and have those files and services saved as a template, but first I need to set this up correctly. Can Apache serve those files, do I have to make another configuration first?
I have those files served from a Windows machine from local host, and put the same files in a /node ,/opt/ www directory in a Linux machine, but no dice.

apache2 on ubuntu webserver rejects permission to access any other file than the delivered index.html

I am trying to set up a webserver running on Ubuntu. I have installed Apache and changed the root directory to an other directory within /var/www/. When I copy the index.html provided by Apache to that directory, I can access that file via remote webbrowser. But if I want to use a different index.html file, even really basic ones, I get an error: "Forbidden You don't have permission to access this resource". I have also tried to download that html, alter just a few lines and put it back on to the server with the result that it also shows that error. If I rename the initially provided index.html to index2.html I can still access it. I do not understand how it is possible that only this exact file is working.
I have tried to grant more permissions with Directory and restarted Apache but it won't work. I am rather new to Linux and Apache, can only use the terminal on my webserver and I do not know what else to do. Please help.
Change the permissions on the file, too, not just the folder. Pretty sure this fix it.
For diagnostic correction, allow permission for all by typing:
sudo chmod -R 777 /path/to/index.html

Symlink to raspberry pi webroot breaks

I have my raspberry pi setup as an internal web server. I have an external hard drive connected to the pi and mounted correctly.
I then symlink two folders from the hard drive to the web root on the pi, one is /Movies, and the other is /Series.
Initially this all works fine, as in if I hit http://192.168.1.17/Movies I get a list of all the files, I then click one and it starts playing no problem. However, after leaving it for a while and coming back, I can still get to the file directory in /Movies or /Series, but when I click a file, the web browser cannot open it.
I have no idea what's going on, it seems weird that I can still access the file directory, but playing a file doesn't work?
Any thoughts or help appreciated.
Are you using an apache server?
If so Symlinking is not a good idea.
An alternative which is more secure and may fix your problem is to install Userdir
sudo a2enmod userdir
Then you need to make a directory in home
mkdir public_html
Restart Apache
sudo service apache2 restart
If you want to change the home directory apache points to you can do so in /etc/apache2/mods-enabled/userdir.conf .Then change the <Directory /home/*/public_html> to the directory you want.
To access you're server simply enter ip_of_Rpi/~pi_username. e.g 192.168.0.100/~pi
more details here: http://ubuntuserverguide.com/2012/10/how-to-enable-and-configure-apache2-userdir-module-in-ubuntu-server-12-04.html
If you are using Apache web server, you can use mod_alias to map some directory in a URL path like this
Alias /mnt/external_disk01/movies /Movies
Alias /mnt/external_disk02/series /Series
Before use alias, make sure it is activated.
To activate:
a2enmod alias
more info in http://httpd.apache.org/docs/2.2/mod/mod_alias.html

Where to administer apache fallback directory

I have been put in charge of an Ubuntu 13 server installation. Apache is configured to use /var/www as the default directory which is correct. The issue is that it seems there is a fallback directory configured that points to /usr/share. So if I type into a browser (www.address.com) it will serve the documents out of /var/www, but if I know the name of a directory in /usr/share and type in (www.address.com/sharedir) then it will serve out of the /usr/share directory. I have looked in the apache config file and default site config file and do not see this association. I do not want this behavior and am concerned that this is the default behavior out of the box.
Can anyone guide me to another areas where this behavior may be controlled/managed.
Thanks for any assistance.
Open your
/etc/apache2/sites-available/default
file and replace
/var/www
to
/path/to/folder/you/wish
save and it will be better to restart apache by
service apache2 restart
Now put website contents to the new location /path/to/folder/you/wish.
Once you changed the Document root of the of the site as mentioned above, Then no files will be fetched from any other location. Hopes this will help you. :)
[SOLVED] After a bunch more digging around I discovered that the user that originally set up this server erroneously put .conf files in the 'conf.d' directory and 'mods-enabled' directory that were routing traffic to the other directories. Sorry to anyone that noodled on this one.

How can I make a public HTML folder in Ubuntu?

Simple question, but for some reason I couldn't find the exact answer on Google:
I have a fresh Ubuntu install on Slicehost, and would like to make a public directory in my home dir for a simple website containing a bunch of static HTML files. How do I do this? Is it just a matter of typing mkdir public_html and setting the permissions, or is there a cleaner way? (I remember in the past I've had issues where every time I copied a file into my public_html directory, I would have to manually set its permissions, which was quite frustrating.)
Assuming you've already installed apache, do the following:
sudo a2enmod userdir
sudo service apache2 reload
The first command enables the userdir apache mod, which does exactly what you want. The second reloads apache configurations so that it starts using the new configuration.
To install apache2:
sudo apt-get install apache2
Of course, you'll also need to make sure that the permissions on your public_html folder allow the www-data user to see the files in there -- 755 usually works well. To do this:
mkdir ~/public_html
chmod -R 755 ~/public_html
This will recursively (-R) go through your public_html and set the permissions to 755 (owner rwx, and both group and other r-x, r-x).
The other answers are on the right track with mod_userdir, but using that will give your website the base URL http://www.yourdomain.com/~username/ - for instance, a file /home/username/public_html/index.html would be accessible as http://www.yourdomain.com/~username/index.html. If you want your files to be accessible under the domain root, as http://www.yourdomain.com/index.html for example, then you'll need to put the directive
DocumentRoot /home/username/public_html
in the Apache configuration file.
You need to use mod_userdir for Apache, otherwise you need to set up symlinks from /var/www/ or wherever.
Your permissions issue is because Apache does not have read access to your files. You need to allow read access to www-data (or whatever the user is; distro-specific).

Resources