Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache doesn't serve files in "javascript" directory. Why?

All of the sudden I started getting 404s for files like http://example.localhost/javascript/jquery.min.js

Earlier everything was working just fine. I didn't change any configs, at least not manually.

But now if I'd try to access the /javascript directory itself I would get "Cannot serve directory /usr/share/javascript/: No matching DirectoryIndex (index.html,index.cgi,index.pl,index.php,index.xhtml,index.htm) found, and server-generated directory index forbidden by Options directive in the Apache error log.

like image 527
uKolka Avatar asked Feb 11 '14 15:02

uKolka


People also ask

Does Apache work with Javascript?

While Javascript is a client-side executing coding language, it still has to have permission from the Apache Web server in order to run properly. If Apache is configured incorrectly, the Javascript on your Web server may not work properly.

Where does Apache serve files from?

All the configuration files for Apache are located in /etc/httpd/conf and /etc/httpd/conf. d . The data for websites you'll run with Apache is located in /var/www by default, but you can change that if you want.

Where should I put my javascript files?

You can place any number of scripts in an HTML document. Scripts can be placed in the <body> , or in the <head> section of an HTML page, or in both.


2 Answers

I was trying to find solution to this on Stack Overflow, but I couldn't. So I'm just leaving this here if anyone happens to encounter the same problem.

So why the hell would it look in the /usr/share/javascript instead of what I had configured in the VirtualHost. To figure that out I did something like the following:

$ cd /etc/apache2
$ grep -R Alias * | grep share

...
conf-enabled/javascript-common.conf:Alias /javascript /usr/share/javascript/
...

After googling for that configuration file name I found some explanation.

I don't know why, but I had the javascript-common package installed. It doesn't seem harmful to get rid of it, so doing $ sudo apt-get purge javascript-common solved the problem for me.

like image 194
uKolka Avatar answered Sep 20 '22 13:09

uKolka


You don't need to edit the conf file or purge the package just disable it.

a2disconf javascript-common
service apache2 reload

If for some reason you want to use that conf:

a2enconf javascript-common
service apache2 reload
like image 39
gregjor Avatar answered Sep 19 '22 13:09

gregjor