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

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.

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.

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

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

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.

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).

Uninstall apache2 and delete these folders:
rm -R /var/www/html/
rm -R /etc/apache2
Then reinstall javascript-common and apache2.

Related

Brew Install Httpd: Welcome to Nginx?

I'm trying to install the brew package httpd (apache). I'm so confused. Every time I do and navigate to http://localhost:8080 I get a big welcome screen that says "Welcome to Nginx." I don't understand.
Am I running nginx and not apache? How could that be?
I'm on macOS 10.15.6.
I'm running pretty basic commands...
brew install openldap libiconv
sudo apachectl stop
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null
brew install httpd
sudo brew services start httpd
And then I get get this...
https://www.dropbox.com/s/yia1yk9uhsootpk/Screen%20Shot%202020-09-18%20at%208.53.39%20PM.png?dl=0
"Welcome to nginx"
What don't I know? A lot probably. If I edit the httpd.conf file to listen to another port, I get the same screen.
╰─ brew list
apr gettext jemalloc libidn2 node powerlevel9k
apr-util httpd libev libunistring openldap wget
brotli icu4c libevent ncurses openssl#1.1 zsh
c-ares jansson libiconv nghttp2 pcre zsh-completions
Can anyone shed some light on this for me?
Update:
lsof -i :8080
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
Brave\x20 1225 user 35u IPv6 0xcdbe6ccead8e5deb 0t0 TCP localhost:53261->localhost:http-alt (CLOSE_WAIT)
I think I narrowed it down to "groonga." First I'm hearing of it, but apparently it's a mariadb brew dependency. I found where the "welcome to nginx" text was coming from.
var/www/index.html
Not sure why it's hard coding that text if it will also display with apache running. Very confusing. However, it adds that file to the default apache DocumentRoot.
Had a similar issue to this, discovered the fact that generic start file at usr/local/var/www/index.html, had been hard-coded to contain the "Welcome to nginx" when I installed nginx and
the message remained that way even I uninstalled it. The Apache (httpd) service also happens calls that index.html file upon startup which makes it appear as if it were nginx rendering that file.
Not too sure why nginx doesn't automatically empty the file upon uninstallation but just manually change/remove the contents of that file after uninstalling nginx and your problem should be fixed :)
Similar problem also addressed here: nginx uninstalled, localhost:8080 still showing nginx welcome page

apache default httpd.conf location

This might be a dumb question, but anyway here it goes.
From the below link I could see that default config link for apache httpd2 is at
"/usr/local/apache2/conf/httpd.conf"
https://wiki.apache.org/httpd/DistrosDefaultLayout
how ever when I install httpd using yum on centos 6 and 7 config files seems to be at "/etc/httpd/conf/httpd.conf
Why doesn't yum install it to the location defined on the default distribution layout.
Default location primary httpd config file for Fedora Core, CentOS, RHEL is /etc/httpd/conf/httpd.conf
In general the path /usr/local is meant for "locally" installed packages. For a single computer that probably just means packages installed outside of the normal distribution. So I would argue a package manager like yum shouldn't even touch anything under /usr/local.
On the other hand it makes sense for the apache project to specify their default paths there, since if you download Apache directly from their site and install it you do it outside of your standard system distribution.
Standard installation of Apache 2.4 on Ubuntu puts the apache2.conf file in /home/miro/etc/apache2. You can locate the main config file using:
/usr/sbin/apache2 -V | grep SERVER_CONFIG_FILE
Modify the path /usr/sbin/ to the location of the installation, if you have changed its default when installing.

how to get permission to access the index.html file that comes with apache on raspberry pi

for a while now I have been attempting to edit the index.html file that is created when you install apache2 / php5 / liapache2 ect. The command I used to install it was:
sudo apt-get install apache2 php5 libapache2-mod-php5
But whenever I try to save my edited version of the index.html, file it comes up with access denied. Furthermore if I try to edit it in nano nothing comes up
these are the commands I used :
cd /var/www/
sudo nano index.html
Any suggestions?
it would mean a lot to me if someone answered this question
Thanks
This is what it says in the Apache documentation from raspberrypi.org:
By default the html directory and index.html file are both owned by the root user. Setting up an Apache web server on a Raspberry Pi
What worked for me is that I changed the owner from root to pi for /www/ and /html/ with this commands:
sudo chown pi: .
sudo chown pi: ..
But note that I'm also just using the Apache server for an local installation and I don't care about security at this point. I don't know how secure this solution is.
Change the permissions of the entire folder
sudo chmod 755 -R /var/www/html

Apache is viewing php files as texts

After I updated to php7.0 now it's viewing the files, I firstly thought it was in apache itself, but i have reinstalled it, what could be the problem..?
ubuntu 15.04
Install PHP 7 and the Apache PHP module as follows:
apt-get -y install php7.0 libapache2-mod-php7.0
Then restart Apache:
service apache2 restart
Another possible reason could be short open tag. Configure php.ini files related line as: short_open_tag = On and restart php service.

mod_rewrite.so is missing under /etc/httpd/modules

I was trying to use mod_rewrite but without success.
I searched online and found some articled but didn't solve my problem.
I finally realised that this article must solve my problem http://www.ewhathow.com/2013/09/how-to-enable-mod_rewrite-on-apache/
but the file mod_rewrite.so is missing under my system.
I have to note that i am using Centos 6 64BIT
.Is there any way to solve this ?
I tried my self to install xampp on an other computer go to modules folder and copy the mod_rewrite.so file and copy it on my server .After that i added
this
LoadModule rewrite_module modules/mod_rewrite.so
on /etc/httpd/conf/httpd.conf
But after restarting apache…apache couldn't start…so i deleted again the line and apache restarted successfully.
I want to make mod_rewrite works on my server.Any help ?
Thanks in advance
I am using Apache on CentOS 6.5 installed from the installation CD and it does have /etc/httpd/modules/mod_rewrite.so file. If this file is missing, I think you would be compiling your own Apache. In this case, you need to modify the SPEC file for apache and add --enable-rewrite to the configure line in the %setup section:
SPEC file %setup section:
%setup
./configure --prefix=%apache_dir --enable-rewrite
Build apache again and install the RPM and the mod_rewrite.so should be in the modules folder after it finished installing.
Options and modules available to compile on Apache:
http://httpd.apache.org/docs/2.2/programs/configure.html
The other thing you could probably do would be to install Apache using yum install httpd on a test system and grab the mod_rewrite.so file from the installation, save and copy to the modules folder on the system you're trying to get working. This would be my last resort method..
Without more information on what you have installed:
rpm -qi httpd
it hard to tell what would work best for your situation.