26

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.

2
  • I just had the same issue in froxlor, so for search engine purpose I am adding that comment here. Commented Jan 7, 2021 at 13:06
  • Just had the same issue on ubuntu server... Spent 4 hours trying to migrate our web app from windows to a linux server. Linux is like the french, overly complicated. Commented Oct 10, 2022 at 16:51

6 Answers 6

36

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.

2
  • 3
    I was having this issue for more than a week and this solved it! I know this is an old answer, but thank you! Commented Jul 27, 2018 at 3:34
  • 4
    sudo a2disconf javascript-common.conf is a gentler solution, though I would have preferred explosives. Serious google-fu is required to get here. Thanks for figuring this out.
    – Bob Stein
    Commented Apr 12, 2021 at 12:55
14

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
1
  • 3
    Clean surgical solution. The others are sledgehammers. Commented Feb 8, 2019 at 17:58
11

The issue:

Web applications that use JavaScript need to distribute it through HTTP. Using a common path for every script avoids the need to enable this path in the HTTP server for every package.

This is the package that creates /usr/share/javascript alias and enables it in the Apache webserver.

Recommended fix

And that's it. You won't have any other problem with javascript directories. Another fix could be to rename /usr/share/javascript/ to /usr/share/javascript-common/, then adjust the Alias in javascript-common.conf to point to the renamed directory. I am still not sure if this will affect any future update.

Another Fix:

Go to /etc/apache2/conf-available/javascript-common.conf. You will find this:

Alias /javascript /usr/share/javascript/
<Directory "/usr/share/javascript/">
     Options FollowSymLinks MultiViews
</Directory>

So you just have to comment these lines (with the # char) (it is not recommended to edit the file directly in conf-enabled) to avoid the forbidden error. After that, do this:

a2disconf javascript-common
a2enconf javascript-common
1

I'm on a Debian machine, and there is no a2disconf command. I found the /etc/apache2/conf.d directory is a link to /etc/javascript-common/javascript-common.conf.

I went and edited that file (as root) and changed it to alias /javascript-common instead of /javascript by changing the top line to

Alias /javascript-common /usr/share/javascript/

and saving it and restarting Apache.

1

I just had a similar problem on an Ubuntu system. Apparently the javascript-common package was hosed at some point in time and the configure script wouldn't run properly. Removing javascript-common and reinstalling with apt-get would not fix it. I had to:

dpkg --purge javascript-common

apt-get install javascript-common

And that seemed to fix the problem. This is an Ubuntu 16.04 LTS (Xenial Xerus) system that was upgraded from Ubuntu 14.04 LTS (Trusty Tahr).

1
  • OMG - why is there even this package? It pollutes the complete /javascript namespace. In my case I had also Ubuntu 16.04.6
    – cljk
    Commented Apr 3, 2019 at 6:21
-4

Uninstall apache2 and delete these folders:

  • rm -R /var/www/html/
  • rm -R /etc/apache2

Then reinstall javascript-common and apache2.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.