No public_html access - apache

I am a neophyte on Apache, but I see some similar questions to this list and hope you can help.
I just want to set up a basic local LAMP system under my Ubuntu 18.04 LTS (Asus VivoBook S15) to test out a website that I have to modify before playing with the version on my commercial ISP host.
The basic installation went fine (Apache/2.4.29, PHP 7.2) and both html and php could be processed from the var/www/html folder through the url localhost. I then did the following to set up public_html access:
i) add in /etc/apache2/apache2.conf the line:
ServerName localhost:80
ii) activate the the UserDir module (sudo a2enmod userdir) and edit the file /etc/apache2/mods-enabled/userdir.conf as follows :
<IfModule mod_userdir.c>
UserDir public_html
UserDir disabled root
<Directory /home/*/public_html>
# AllowOverride FileInfo AuthConfig Limit Indexes
AllowOverride All
# Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
Options ExecCGI Indexes MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
Require method GET POST OPTIONS
</Directory>
</IfModule>
iii) activate default virtual user directory (sudo a2ensite 000-default.conf) and edit the file /etc/apache2/sites-enabled/000-default.conf as follows:
# Global configuration
ServerName localhost
# without port according to recommendation found on the web
and
#ServerAdmin webmaster#localhost
ServerAdmin john#john-VivoBook
#DocumentRoot /var/www/html
DocumentRoot /home/john/public_html
iv) created the public_html directory under my home directory (/home/john) with ownership john:john and permissions 755 (also tried with 777), and added my index.html and index.php files
v) restarted Apache (sudo apache2ctl restart)
vi) configured my Firefox browser not to add www to urls.
When I try to access the url "localhost" I get a blank screen, whereas with "localhost/public_html", "localhost/public_html/index.html" or "localhost/public_html/index.php" I get the message:
Not Found
The requested URL was not found on this server.
Apache/2.4.29 (Ubuntu) Server at localhost Port 80
No errors in the log file /var/log/apache2/error.log
The tail of the log file /var/log/apache2/access log says:
127.0.0.1 - - [05/Apr/2020:13:24:44 +0200] "GET /public_html HTTP/1.1" 404 488 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:74.0) Gecko/20100101 Firefox/74.0"
127.0.0.1 - - [05/Apr/2020:13:26:41 +0200] "GET /public_html/index.html HTTP/1.1" 404 488 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:74.0) Gecko/20100101 Firefox/74.0"
127.0.0.1 - - [05/Apr/2020:13:27:29 +0200] "GET /public_html/index.php HTTP/1.1" 404 488 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:74.0) Gecko/20100101 Firefox/74.0"
The log file /var/log/apache2/other_vhosts_access.log does not exist.
What am I doing wrong?
Thanks and best regards, John

If you want to use 'userdir' feature, you should just install apache2 and enable 'userdir'. You don't have to change the DocumentRoot.
sudo apt install apache2
sudo a2enmod userdir
sudo systemctl restart apache2
Now, switch to the user (in your case, john)
mkdir /home/john/public_html
echo 'hello' >> index.html
And you can now access index.html using "http://localhost/~john/index.html"
If you change your DocumentRoot to /home/john/public_html, then you should access the html page through "http://localhost/index.html", because the directory(/home/john/public_html) is already the Root.
Update after your comment
If you want php work with apache2 user directory feature.
First, install php environment.
sudo apt install php7.3
sudo a2enmod php7.3
Second,
sudo vim /etc/apache2/mods-enabled/php7.3.conf
Comment below block to re-enable PHP in user directories.
#<IfModule mod_userdir.c>
# <Directory /home/*/public_html>
# php_admin_flag engine Off
# </Directory>
#</IfModule>
Third, restart apache2 service.
sudo systemctl restart apache2
You should see the page working perfect through http://localhost/~john/index.php

I am now not sure that PHP was partially OK under Opera, since my index.php code was very short and I may well have mistaken a listing for an output. At any rate I upgraded opera-stable to version 67.0.3575.137 (remember that I have Apache/2.4.29 running under Ubuntu 18.04 LTS and PHP version 7.2.24), and all php files including http://localhost then showed listings rather than executing.
[Sorry, I've struggled for a half hour trying without success to show "sharp" (comment) signs and initial triangular brackets in code, and so am abbreviating without some code.]
I then did the following two steps (both taken from Apache shows php code instead of executing):
edit /etc/apache2/mods-enabled/php7.2.conf to comment out five lines as per the instructions after the commented line "Running PHP scripts in user directories is disabled by default":
At this point http://localhost worked but direct calls to php files still yielded listings only.
edit /etc/apache2/mods-enabled/mime.conf and after the following two commented lines:
comment: AddType allows you to add to or override the MIME configuration
comment: file mime.types for specific file types.
add the following lines:
AddType application/x-httpd-php .php
AddHandler application/x-httpd-php .php
With these two changes, my local php-based website seems to be working fine with both Opera and with Firefox 75.0 64 bits (previously blank screens for http://localhost and for explicit calls to php files).

Related

How to obtain default Apache getting-started.html?

I have simple problem, but for me it's difficult to resolve it.
I had standard /var/www/html directory but then I just delete it and I made virtual hosts but I didn't thought about copy default page (that index.html) but I need it back. Where I can find it or how to send "request" to Apache to generate it in folder in /var/www/*?
I am using CentOS7.
You're using CentOS, so presumably you're running Apache from the httpd package. There is no content in /var/www/html:
[root#a02004d67c2b /]# cat /etc/centos-release
CentOS Linux release 7.4.1708 (Core)
[root#a02004d67c2b /]# find /var/www/html/
/var/www/html/
The default welcome page is provided by /etc/httpd/conf.d/welcome.conf, which looks like:
<LocationMatch "^/+$">
Options -Indexes
ErrorDocument 403 /.noindex.html
</LocationMatch>
<Directory /usr/share/httpd/noindex>
AllowOverride None
Require all granted
</Directory>
Alias /.noindex.html /usr/share/httpd/noindex/index.html
Alias /noindex/css/bootstrap.min.css /usr/share/httpd/noindex/css/bootstrap.min.css
Alias /noindex/css/open-sans.css /usr/share/httpd/noindex/css/open-sans.css
Alias /images/apache_pb.gif /usr/share/httpd/noindex/images/apache_pb.gif
Alias /images/poweredby.png /usr/share/httpd/noindex/images/poweredby.png
That means that if you do not have an index.html in your
DocumentRoot (i.e., /var/www/html), Apache will return a status
code 403 and the content from /usr/share/httpd/noindex/index.html.
You could reproduce the same configuration for your virtual host, or you could just copy the contents of /usr/share/httpd/noindex into your virtual host DocumentRoot.

403 error on accessing nominatim on the virtual host

I have installed nominatiom on virtual qemu ubuntu 16.04 server,
i can access apache's default page using http://127.0.0.1:8080 url in the host machine but i can not access any pages of nomination.
i test http://127.0.0.1:8080/nominatim/search.php either http://127.0.0.1:8080/nominatim/, but all of them response 403 forbidden message.
i created qemu virtual machine by this code:
qemu-system-x86_64 -m 4096 -hda nominatim.img -enable-kvm -redir tcp:8080::80 -redir tcp:2222::22
and this is apache's nominatim.conf file:
<Directory "/srv/nominatim/Nominatim/build/website">
Options FollowSymLinks MultiViews
AddType text/html .php
DirectoryIndex search.php
Require all granted
Order allow,deny
Allow from all
</Directory>
Alias /nominatim /srv/nominatim/Nominatim/build/website
i used this tutorial for installing nominatim :
http://nominatim.org/release-docs/latest/Install-on-Ubuntu-16
I didn't check the directories in the doc page.
source files are in /srv/nominatim/Nominatim-3.0.0/build/website not /srv/nominatim/Nominatim/build/website!
so i edit correct path and it works!.

Apache/2.4.7 (Ubuntu) - mod_dumpio not logging post data

I can't seem to get the Apache module mod_dumpio to log anything.
I have tried the suggestions in this post
To be sure I have tried the following
Disabled all of my vhosts except the one for the site I am working on
Ran a2enmod dump_io, and restarted Apache, can see it in /etc/apache/mods-enabled/dump_io.load
Check that /etc/apache/apache.conf LogLevel is dumpio:trace7 too
I open the log tail -f n 20 /var/log/apache2/packager-access.log
Run the following command to send some post data --data "param1=value1&param2=value2" http://packager.local/api/package/create
Can only see lines like 127.0.0.1 - - [12/Nov/2014:10:07:04 +0000] "POST /api/package/create HTTP/1.1" 500 294 "-" "curl/7.35.0"
The vhost conf is as below
<VirtualHost *:80>
DocumentRoot /var/www/packager/web
ServerName lms-packager.local
ErrorLog ${APACHE_LOG_DIR}/packager-error.log
CustomLog ${APACHE_LOG_DIR}/packager-access.log combined
DumpIOInput On
DumpIOOutput On
LogLevel dumpio:trace7
</VirtualHost>
Is there anything else that I could try
After reading this post, I tried to move the configuration to the server level.
As the post suggests the key point from the Apache manual is
server config This means that the directive may be used in the server
configuration files (e.g., httpd.conf), but not within any
or containers. It is not allowed in
.htaccess files at all.
The following is also important so only check your ErrorLog file (e.g. /var/log/apache2/error.log) rather than any vhost file which makes sense if this is a server config
to be logged (dumped) to the error.log file

How do I set up a web.py apache2 server on an amazon linux ubuntu 13.04 server?

Web.py is free and lightweight. Amazon also provides you with a free web service for a year. How do I set up apache2 onto my server?
*EDIT: Formatting this is impossible. I'll try to do it later. I have such a beautifully written .txt file with fantastic formatting.
I apologize if this isn't thorough. I worked through how to set it up for my very specific setup. However, some of the annoying tricks are solved and may help you on your journey to set it up!!!
I won't walk you through signing up for amazon. There are a million tutorials out there.
Make sure you have an amazon ec2 instance up and running for ubuntu 13.04. Once you're logged in and have your instance launched, get the following going
*I've omitted some numbers as they are specific to our application and don't help.
Give yourself root access
sudo su (if you do this you dont need to sudo anything)
Get Apache 2
apt-get install apache2 apache2.2-common apache2-mpm-prefork apache2-utils libexpat1 ssl-cert
Get Pip
apt-get install python-pip
Get web.py
pip install web.py
Get MySQL
apt-get install python-mysql.connector python-mysqldb mysql-client-core-5.5 mysql-server
set password to: whatever password you want
Get mod_wsgi
apt-get install libapache2-mod-wsgi
6.1 Check to see its working
service apache2 restart
put ip address in web browser to see if it works
enable mod_rewrite
a2enmod rewrite
SFTP (filezilla)
8.1 Giving permissions to allow filezilla in
cd /var/www
mkdir legal #this is our main directory. Name it whatever you want
chown -R ubuntu /var/www/
chmod -R 755 /var/www/
8.2 Connecting in Filezilla
Open Site manager
host: some ip like 54.213.173.233
Port: 22
Protocol: SFTP
Login Type: Normal
User: Ubuntu
Pass: empty
Edit -> Setting -> SFTP: add your key
8.3 Add all of your code Using Filezilla
9 Modifying your code:
go to your main.py
9.1 Wsgifunc()
#add these somewhere in your main file
app = web.application(urls, globals(),autoreload=False)
application = app.wsgifunc()
web.config.debug = True # Change to False
db = web.database(dbn='mysql', host='127.0.0.1', port=3306, user='user goes here', pw='pas goes here', db='')
9.2 Ensure python can find all of your files
AT THE TOP OF YOUR FILE
import os
import sys
root = os.path.join(os.path.dirname(file)+"/")
sys.path.insert(0, root)
modules = os.path.join(os.path.dirname(file)+"/server/")
sys.path.insert(1, modules)
os.chdir(root)
os.environ["SCRIPT_NAME"] =''
os.environ["REAL_SCRIPT_NAME"] = ''
Configuration of apache
cd /etc/apache2/sites-available
10.1 Changing the default file
vim default
change everything to:
*our main folder is called /legal. In it we have our icons and favicons and such in /static. Change these accordingly
ServerAdmin webmaster#localhost
DocumentRoot /var/www/legal/
DirectoryIndex main.py
WSGIScriptAlias / /var/www/legal/
Alias /static /var/www/legal/static/
Options FollowSymLinks
AllowOverride None
Options +Indexes +FollowSymLinks +MultiViews
#changed from non to FileInfo
AllowOverride FileInfo Options
Order allow,deny
allow from all
#ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
#
# AllowOverride None
# Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
# Order allow,deny
# Allow from all
#
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel info
CustomLog ${APACHE_LOG_DIR}/access.log combined
10.2 Test to see if there are errors
apachectl configtest
10.3 Monitor For errors when messing with config files (optional)
tail -f /var/log/apache2/error.log
and
11 Creating a .htaccess file
cd /var/www/legal #this is where our main file is located
vim .htaccess
Then add:
SetHandler wsgi-script
Options +ExecCGI +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^favicon.ico$
RewriteCond %{REQUEST_URI} !^(/.*)+main.py/
RewriteCond %{REQUEST_URI} !^(/.)+.(css|png|js|jpg|ttf|otf|gif|ico)$
RewriteRule ^(.)$ main.py/$1 [PT]
#for reals, it never copies correctly... just a heads up
12 Setting up the database
cd /var/www/legal/server/subapplications
mysql -u root -p'whatever password you want'
12.1 create the database in sql
create database intravires;
###do whatever you need to do here
quit
13 Restart
service apache2 restart
13.1 If broken,Check the logs:
tail -f /var/log/apache2/error.log
14 Profit!

Symfony - name based virtual servers on localhost - is this possible?

I am rapidly coming to the conclusion that this is not feasible, although for some reason, people - most likely who have not implemented the 'advice' they give, seem to think this is possible.
The scenario is quite straightforward. I am developing symfony websites on my local dev machine, running Ubuntu 10.0.4 LTS. I want to be able to run and test multiple sites locally.
Assuming I have the following sites:
site1.localhost
site2.localhost
site3.localhost
Following the documentation here, here and here (none of which work for me), I have done the following:
A. I modified my /etc/hosts file with the first entry to be:
127.0.0.1 site1.localhost site2.localhost hpdtp-ubuntu910
localhost php.localhost
B. I modified my /etc/apache2/ports.conf file (first lines) as follows:
NameVirtualHost localhost:80 Listen 80
C. I have created configuration sites for each of the websites (site1.localhost and site2.localhost). Each configuration is a separate file in /etc/apache2/sites-available
One such configuration file (for site1.localhost) in /etc/apache2/sites-available/site1 looks like this:
<VirtualHost localhost:80>
ServerName site1.localhost
DocumentRoot "/home/morpheous/work/webdev/frameworks/symfony/sites/site1/web"
DirectoryIndex index.php
<Directory "/home/morpheous/work/webdev/frameworks/symfony/sites/site1/web">
AllowOverride All
Allow from All
</Directory>
Alias /sf /lib/vendor/symfony/symfony-1.3.6/data/web/sf
<Directory "/lib/vendor/symfony/symfony-1.3.6/data/web/sf">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
D. I have disabled the default apache site by using (it kept showing up instead)
E. Since I can't enable all the sites I enable to work (like the documentation links above
purport), I have settled for enabling one site at a time, so that Apache dosen't get its confused as to which site to run. When I need to run another site, I disable the current one and enable the one I want to. This is (obviously?) far from ideal - but even this setup is not working - for the reasons listed below.
i). When I restart Apache, I get the following warning:
Reloading web server config apache2
[Sun Jul 18 10:32:23 2010] [warn]
NameVirtualHost localhost:80 has no
VirtualHosts
ii). when I navigate to http://site1.localhost
I get the following error message in FF:
Oops! This link appears to be broken
iii). My apache related errors are appearing in /var/log/apachche2/other_vosts.log
morpheous#hpdtp-ubuntu910:~$ tail /var/log/apache2/other_vhosts_access.log
site1.localhost:80 127.0.0.1 - - [18/Jul/2010:10:08:38 +0100] "GET / HTTP/1.1" 404 506 "-" "Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.2.6) Gecko/20100628 Ubuntu/10.04 (lucid) Firefox/3.6.6 GTB7.1"
site1.localhost:80 127.0.0.1 - - [18/Jul/2010:10:09:30 +0100] "GET / HTTP/1.1" 404 506 "-" "Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.2.6) Gecko/20100628 Ubuntu/10.04 (lucid) Firefox/3.6.6 GTB7.1"
site1.localhost:80 127.0.0.1 - - [18/Jul/2010:10:09:31 +0100] "GET /favicon.ico HTTP/1.1" 404 505 "-" "Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.2.6) Gecko/20100628 Ubuntu/10.04 (lucid) Firefox/3.6.6 GTB7.1"
site1.localhost:80 127.0.0.1 - - [18/Jul/2010:10:09:36 +0100] "GET /favicon.ico HTTP/1.1" 404 505 "-" "Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.2.6) Gecko/20100628 Ubuntu/10.04 (lucid) Firefox/3.6.6 GTB7.1"
My questions are:
Can Apache be setup to handle multiple virtual hosts on localhost? Afterall, all examples I have seen so far involve setting Apache with public facing ip addresses
If Apache can indeed handle multiple sites on localhost, which of the steps above am I doing incorrectly?. AFAICT, I have followed the documentation to the letter.
Yes, you can have several VirtualHosts, on your local machine -- It's exactly the same as when working on a remote server, except the IP address and domain-name are not the same.
What I generally do is :
Edit the hosts file
To add the new domain-names that I want served from my local computer.
For example, I would add :
127.0.0.1 tests
127.0.0.1 blog
And so on, with one line for each domain-name I want.
Add new VirtualHosts to Apache's configuration
Then, I add new VirtualHosts to Apache's configuration.
First site : tests
For example, for my tests domain-name, I would use :
<VirtualHost *:80>
ServerName tests
DocumentRoot /home/squale/developpement/tests
<Directory /home/squale/developpement/tests>
AllowOverride All
Options Indexes FollowSymLinks MultiViews
allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
</VirtualHost>
A couple of things to note here :
The VirtualHost is on *:80
So, it'll listen to any address
The mapping to the domain-name is made by the ServerName directive
Of course, up to you to make sure that this VirtualHost is seen by Apache -- either by placing it's configuration in a loaded file (not recommended), or by :
Placing that configuration in a new file in /etc/apache2/sites-available/
Using a2ensite to enable the site
Which will create a symbolic-link in /etc/apache2/sites-enabled/, pointing to your new configuration file.
Second site : blog
And here the configuration I'd use for a second domain-name, that correspond to blog :
<VirtualHost *:80>
ServerName blog
DocumentRoot /home/squale/developpement/blog.pascal-martin.fr/www
<Directory /home/squale/developpement/blog.pascal-martin.fr/www>
AllowOverride All
Options Indexes FollowSymLinks MultiViews
allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
</VirtualHost>
It's basically exactly the same thing ; only two differences :
The ServerName directive correspond to my second domain-name -- of course
And the DocumentRoot is not the same
Other files ?
I don't really change anything else to Apache's default configuration (I'm on Ubuntu, if that matters).
For example, I don't change anything in the ports.conf file : I still have the default NameVirtualHost and Listen directives :
NameVirtualHost *:80
Listen 80
Only important modifications I do are to enable some modules, like rewrite, expires, ... But that's not much related to your VirtualHosts problem ;-)
Results ?
If I open my browser and go to http://tests/, I get the things I would expect from my tests domain -- a list of directories and files, here.
And if I open my browser and go to http://blog/, I get the development instance of my blog -- well, and error page, saying that I forgot to set up the database ^^
Did you create a link from /etc/apache2/sites-available/site1 to /etc/apache2/sites-enabled/site1 ?
I'm using nginx instead of apache but ubuntu has standarized way of configuration. Usually sites-available includes all your configurations which are not included by apache. It only looks for configurations linked in sites-enabled directory.
I also don't think you need to enable one site a time. All should work. All have different domain names.