Apache or NGINX ?

You have several options here. But default web servers look for a file called index.html ( you can change this, but... )
That "It works page", is actually a file called index.html. You can either remove it and create your own index.html
or modify the existing one. Find the line that says It works, and change it to Bagheeras cool page, or whatever you want.

That's probably the easiest option to start with. You can go without a index.html and just have a mycoolpahe.html
file, but then you have to type that html page in as part of the URL, people generally don't like to do that.

Another option is to create /home/bagheera/public_html and put html pages here. index.html is still the first page looked for.
In the old days ( 20 years ago or so ) web servers used to serve from this directory by default, but is it something of a
security concern, and usually not recommended.

The default location depends on your distro, but usually it's /var/www/html/index.html
For Nginx, it's usually /usr/share/nginx/html/index.html
 


If you're new to html you can use this template to help you build your home page for your web site.

Code:
<!DOCTYPE html>
<html lang = "en-US">
     <head>
          <meta charset = "UTF-8">
          <meta name = "description"
                content = "This is the description text.">
          <meta name = "viewport"
                content = "height = device-height,
                           width = device-width, initial-scale = 1.0">
          <title>This will show up on the browser tab as the title of the page</title>
          <style>
               body
               {
                    background-color: #e0e0e0;
                    color: #202020;
                    font-family: sans-serif,utf;
                    font-size: 1vw;
                    font-weight: 400;
                    margin: 0px 0px 0px 0px;
                    padding: 1vw 1vw 1vw 1vw;
                    text-align: justify;
                    text-decoration: none;
               }
          </style>
     </head>
     <body>
The text for your web page goes here.<br>
     </body>
</html>

<!-- EOF /index.html -->

The default file names that your Apache2 web server will look for when a user requests a directory without specifying a file are defined in /etc/apache2/mods-available/dir.conf. You can use the DirectoryIndex directive to define the files to use, in your order of preference, there. This will commonly specify index.html so when a user does not specify a file the server knows what you want it to send.

Signed,

Matthew Campbell
 
Setting up Apache on Linux Mint

Persuaded by contributors here I decided to install Apache rather than NGINX which was easy enough and localhost URL
correctly displays the Ubuntu "It work's page". NOTE: I installed using my default Admin LM login.

Given I'd have thought most people like myself install Apache to develop websites using CGI programs they also write, I'm somewhat surprised I cannot create a new website folder under either var/www/ or var/www/html/ - 'Create new folder' is greyed out and my LM Admin privileges aren't even the owner (despite being used to install) to change permissions.

So ... where and how do I create a folder for say myWebsite/public_html/ ?
See /etc/apaceh2/sites-available/ for the three files that you will need to use to do exactly that. Use the DocumentRoot directive to specify this. Make sure you also specify a Directory directive for that DocumentRoot in /etc/apache2/apache2.conf to specify which IP addresses you want to allow. You might try something like:

Code:
<Directory /var/www/myWebsite/public_html/>
        Options +Indexes +FollowSymLinks +ExecCGI
        AddHandler cgi-script .cgi
        AllowOverride None
        Order deny,allow
        Allow From all
        Deny From none
        Require all granted
</Directory>

This will allow a directory index when an index.html or similar file is not found. It will follow symbolic links, and allow execution of your CGI programs outside of /cgi-bin. It will presume that any file using the extension .cgi is a CGI program and run it instead of sending the program to the user.

Signed,

Matthew Campbell
 
Thanks guys but it seems I didn't explain myself properly. I know HTML, CSS and Perl well enough. I'm trying to create a folder to hold all those documents specific to that website. Then a second folder for a second website and so on. In other words using Apache for two or more discreet websites. Be nice if I can create a structure that has certain Perl pgms and subroutines above the website folders to serve multiple websites.

My problem is I don't have permissions to create those website folders under var/, var/www/ or var/www/html/ even though I installed Apache using my LM admin log-in.

So, can I point localhost <website> to website files completely outside var/www/ ?
The following would be a desirable structure for me ...

Websites (actual directory name)
/cgi-bin (shared Perl pgms)
/subroutines (shared perl subroutines)
/html (shared html documents)
/css (shared CSS documents)
/Javascript (shared javascripts)

baheera1 (1st website)
/cgi-bin (site speciific Perl pgms)
/subroutines (site specific Perl subroutines)
/Javascript (site specific javascripts)
/public_html (html documents including index.html)
/CSS (site specific stylesheets)
/graphics

baheera2 (2nd website)
/cgi-bin (site specific Perl pgms)
/subroutines (site specific Perl subroutines)
/Javascript (site specific javascripts)
/public_html (html documents including index.html)
/CSS (site specific stylesheets)
/graphics
 
Last edited:
Thanks guys but it seems I didn't explain myself properly. I know HTML, CSS and Perl well enough. I'm trying to create a folder to hold all those documents specific to that website. Then a second folder for a second website and so on. In other words using Apache for two or more discreet websites. Be nice if I can create a structure that has certain Perl pgms and subroutines above the website folders to serve multiple websites.

My problem is I don't have permissions to create those website folders under var/, var/www/ or var/www/html/ even though I installed Apache using my LM admin log-in.

So, can I point localhost <website> to website files completely outside var/www/ ?
The following would be a desirable structure for me ...

Websites (actual directory name)

/cgi-bin
(shared Perl pgms)

/subroutines
(shared perl subroutines)

/html
(shared html documents)

/css
(shared CSS documents)

/Javascript
(shared javascripts)

baheera1 (1st website)
/cgi-bin
(site speciific Perl pgms)
/subroutines
(site speciific Perl subroutines)
/Javascript
(site speciific javascripts)
/public_html
(html documents including index.html)
/CSS
(site specific stylesheets)
/graphics

baheera2 (2nd website)
/cgi-bin
(site speciific Perl pgms)
/subroutines
(site speciific Perl subroutines)
/Javascript
(site speciific javascripts)
/public_html
(html documents including index.html)
/CSS
(site specific stylesheets)
/graphics
I have set up multiple web sites in /var/web/. Each web site would have its own such directories. You can use symlinks for each web site to point to a master set of directories. I use a directory index program that I wrote in C that sits in /var/web/adm/ and I use a symlink in each directory that needs it. The program detects what directory it is being run in and acts accordingly. All you need to do is use a root shell to give your user permission to do whatever it needs to do. You really should use root when installing packages in Linux. You can use chown or chmod to give your user the permission it needs.

Signed,

Matthew Campbell
 
Thing is Matthew I only have the one LM login which is the same one I used when installing LM - I'd be excused for believing that login has root privileges? When I install LM updates, that is the login I use when prompted ... it accepts it fine. It's also exactly the same login I used to install Apache. So how come I don't have ownership of var/www ? As such I cannot even add one folder anywhere under the var directory structure.
 
Thing is Matthew I only have the one LM login which is the same one I used when installing LM - I'd be excused for believing that login has root privileges? When I install LM updates, that is the login I use when prompted ... it accepts it fine. It's also exactly the same login I used to install Apache. So how come I don't have ownership of var/www ? As such I cannot even add one folder anywhere under the var directory structure.
Are you on some kind of VM? Try using the command whoami or id to see who you are. If you have sudo access you can use sudo bash to get a root shell. It will ask you for your current user password that you use to log in. Use ls -al to see owner and group information for files and directories. The id command should show you what groups you're in. You can also use the groups command to find out. You will likely need to be in the sudo group and be listed in the /etc/sudoers file.

Signed,

Matthew Campbell
 
It was a new laptop I performed a standard LM 21.2 install for so doubt I'm using any kind of VM. I successfully used sudo to install apache. Just really surprised it doesn't give the installer user id, permissions to add directories underneath var. 'whoami' reports my correct user name. 'id' reports uid=1000(bagheera) gid=1000(bagheera) groups=1000(bagheera),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),115(lpadmin),136(sambashare)

Sorry but I don't know what a sudo bash is.
 
Last edited:
It was a new laptop I performed a standard LM 21.2 install for so doubt I'm using any kind of VM. I successfully used sudo to install apache. Just really surprised it doesn't give the installer user id, permissions to add directories underneath var. 'whoami' reports my correct user name. 'id' reports uid=1000(bagheera) gid=1000(bagheera) groups=1000(bagheera),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),115(lpadmin),136(sambashare)

Sorry but I don't know what a sudo bash is.
It looks like your user has been set up to be an admin. /usr/bin/sudo can run a command as root and /usr/bin/bash is the bash command shell. Open a terminal, like xterm, and type sudo bash at the command prompt. Your GUI probably recognizes you as an admin user which probably asked polkit for permission to install the web server package. sudo runs a command with an euid of root, but leaves your uid, egid, and gid the way it is. Run "sudo bash" without the quotes and you should get a # prompt instead of a $ prompt. Then try using the whoami and id commands.

Signed,

Matthew Campbell
 
I think NGINX is pretty neat, reverse proxy is a very cool feature. I mean, Netflix uses it...must be good . I really don't know much though, as I'm pretty new too.
 
It looks like your user has been set up to be an admin. /usr/bin/sudo can run a command as root and /usr/bin/bash is the bash command shell. Open a terminal, like xterm, and type sudo bash at the command prompt. Your GUI probably recognizes you as an admin user which probably asked polkit for permission to install the web server package. sudo runs a command with an euid of root, but leaves your uid, egid, and gid the way it is. Run "sudo bash" without the quotes and you should get a # prompt instead of a $ prompt. Then try using the whoami and id commands.

Signed,

Matthew Campbell

Yes you're right Matthew, I get the # prompt.
'whoami' now reports root and 'id' now reports
uid=0(root) gid=0(root) groups=0(root)
 
Yes you're right Matthew, I get the # prompt.
'whoami' now reports root and 'id' now reports
uid=0(root) gid=0(root) groups=0(root)
Look's like you're in business. I'm glad I could be helpful to you.

Signed,

Matthew Campbell
 
Great to hear you got Apache installed successfully! The issue you're encountering is likely due to permissions. Even though you installed Apache with your admin privileges, the /var/www/ and /var/www/html/ directories are owned by the root user by default.

To create your website folder, you’ll need to either change the ownership of the folder or use sudo to create it. Here's a quick way to handle this:
  1. Open a terminal.
  2. Use sudo to create the directory for your website. For example:
    1727164680461.png

    This will create a folder named myWebsite and set you as the owner.

  3. Once done, you can start adding your files to /var/www/html/myWebsite and Apache will be able to serve them. You’ll also want to ensure that the public_html folder is set to the correct permissions for web access, like:
    1727164711354.png


    This should get you up and running! Let us know if you run into any other issues.
 
Thanks Larry, I can tell that you can tell I'm not a Linux Guru - you explained that in a way I can much better understand. Can I ask why it's necessary to first run sudo bash - what does the bash # prompt signify ... that I'm running in a root shell? Must admit whilst I've heard the term 'shell' I don't really know what it is, I'm now guessing a temporary 'environment' - in this instance a temporary root environment with root privileges?

Once done, how would I then come out of the bash prompt and return to $ prompt?

Will this mean in future I'd be able to add new website folders underneath 'myWebsites' using the std Linux File manager and modify the permissions accordingly through the file manager?

As you already well know most website default index.html documents reside on host servers inside 'public_html' subsequent to the call to the URL. Will my Apache localhost call to a website underneath 'myWebsites' look for index.html also within public_html?
 
I think NGINX is pretty neat, reverse proxy is a very cool feature. I mean, Netflix uses it...must be good . I really don't know much though, as I'm pretty new too.
I think a lot of bona-fide web-servers use NGINX now. I can't begin to understand what a 'reverse' proxy means.
 
Thanks Larry, I can tell that you can tell I'm not a Linux Guru - you explained that in a way I can much better understand. Can I ask why it's necessary to first run sudo bash - what does the bash # prompt signify ... that I'm running in a root shell? Must admit whilst I've heard the term 'shell' I don't really know what it is, I'm now guessing a temporary 'environment' - in this instance a temporary root environment with root privileges?

Once done, how would I then come out of the bash prompt and return to $ prompt?

Will this mean in future I'd be able to add new website folders underneath 'myWebsites' using the std Linux File manager and modify the permissions accordingly through the file manager?

As you already well know most website default index.html documents reside on host servers inside 'public_html' subsequent to the call to the URL. Will my Apache localhost call to a website underneath 'myWebsites' look for index.html also within public_html?
The $ prompt in a bash shell means you are a normal user. A # prompt in a bash shell means you are the root user. You can exit the subshell that sudo created by using the exit command to get back to the $ prompt to be yourself again.

A shell is a command shell, like command.com in Windows. It allows you to have a command line interface to issue commands to your Linux computer instead of using a graphical interface. Much can be done with a command shell and it is certainly worthwhile to learn how to use it. Many shell scripts are written for bash. Whenever you see #!/bin/bash or #!/usr/bin/bash on the first line of a shell script it means the bash shell should be used to process it. sudo creates what is known as a subshell because you already had a shell process running. That first shell process used shell level 1 and that new shell will use shell level 2, if you are the same user, but not while using sudo. Try echo $SHLVL to see what shell level you are currently using. sudo bash will still say SHLVL=1 since you'll become a different user. You can open a bash shell in your xterm and then type bash again to run a subshell. At this point you should have SHLVL=2. If you "exit" from that subshell you will return to your first shell at SHLVL=1. If you use your root shell to change the ownership of the relevant files and directories in your web server's space so that your normal user account owns them then you will have access to that space. You might consider adding yourself to the web server's group and providing group ownership and access so the web server can access those files and directories too, or you'll get an error message from you server when it tries to do so. You will need to log out of your xterm and back in again after adding yourself to the web server's group to get that change to take effect. You would use permission drwxr-x--- for directories and -rw-r----- for files and set the files and directories to youruser:webgroup. Substitute your normal user name and the group name for the web server into that. Use chown to do that. See chown(1). "man chown" Please let me know if I can be of further assitance to you.

Signed,

Matthew Campbell
 
That's fantastic thanks again Matthew. What you describe about 'shells' reminds me of my old professional IBM midrange days (in a different life) where you had the programming language RPG but to talk to the operating system, something called OCL. You could package up OCL statements into a 'procedure' (In Linux/Unix speak, I imagine called a script) and store it as if it's a kind of program in itself.

On my Linux Mint system, once I've been able to 'manage' my website directories, my next task will be to install an integrated Perl. I know Perl quite well, at least well enough to process forms and modify outbound HTML docs. I'm assuming if I just do a sudo install perl, it won't be integrated in with the Apache.
 

Members online


Top