skip to Main Content

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

2

Answers


  1. Chosen as BEST ANSWER

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


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

    1. sudo apt install php7.3

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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search