# HowTo build a web server?

## pmam

I would like to build a web server – My first intention is to learn how it works, and understand all aspects of this system. 

Secondly, I need a web server for my own, and it is a good idea to start with 'Home web server' rather than 'Web hosting company'.  

Please advise minimum required hardware – hope I can use, at least for starting, my old machine.

I saw some tutorials of other Linux's dists, like: 'How to set up a safe and secure Web server' - 

with a simple step by step instructions - Is there something similar of Gentoo?

In general – as a comparison to other Linux dists, from web server aspect–

Of course that Gentoo is my preferable one, as I like it and enjoy your nice support -

but what are Gentoo's advantages? Is it really the right choice for web server? 

Sorry for be a little skeptic - I have this nature regarding technical issues from time to time   :Wink: 

----------

## charles17

Have you looked in gentoo wiki?

----------

## pmam

charles17,

Yes I saw it but as doing it for the first time, without previous experiment,

I need some background info and step by step instructions.

The name of the WIKI confused me since Apache is one part - really main part - so I thought there is more comprehensive WIKI... 

But if you advise me that I can go with this WIKI, and it contains the whole process from the bottom to the entire web-server, I will go a head.

Thanks

----------

## charles17

It's almost the same as installing Apache on any other OS.

http://httpd.apache.org/docs/current/install.html

In fact, Apache might turn out your main reason for running Gentoo.  

When I started learning html I soon needed a local web server for testing. But installing Apache on a laptop with Windws ME wasn't really funny.  Then I've heard about linux and bought my first Suse linux.  Apache was already on the installation CD. It worked well and I could check and learn much about http and html.  But on progress I stuck and people told me I'd have to recompile my apache with some additional module(s). 

Getting the compiler and compilig something on Suse linux? Even less fun than Windows ME.  

Than I came accross distrowatch mentioning Gentoo, and soon every "recomplie your Apache with other module" became so easy ...

----------

## pmam

Dear charles17,

You do not know how much your reply is really encouraging me to continue

and set up Gentoo's web server! I quite hesitated before putting this question here in Gentoo's forum-

One could see it as a non-piloting manner... But sometimes we need to do it in order to be better, the best...

Thanks for sharing with us your experience   :Smile: 

----------

## pmam

I follow the default USE flags in wiki apche - except of ldap that is in use already in my system -

and I see ldap in red color (active) in the list prior emergeing.  

so in total only two USE flags are active: ssl, ldap - Please advise if ok?

```
 /etc/portage/make.conf

USE="... apache2 ..."
```

Is it really needed to add this USE flag to make.conf?

Here last message after emerging apache:

```
 * Attention: cgi and cgid modules are now handled via APACHE2_MODULES flags

 * in make.conf. Make sure to enable those in order to compile them.

 * In general, you should use 'cgid' with threaded MPMs and 'cgi' otherwise.
```

----------

## charles17

 *pmam wrote:*   

> I follow the default USE flags in wiki apche - except of ldap that is in use already in my system -
> 
> and I see ldap in red color (active) in the list prior emergeing.  
> 
> so in total only two USE flags are active: ssl, ldap - Please advise if ok?

 USE flags always depend on what you need or want to do.  And can easily be changed for next recompile.

 *pmam wrote:*   

> 
> 
> ```
>  /etc/portage/make.conf
> 
> ...

 Again, it depends on what you want to do.  If you don't know, you wouldn't need it.

 *pmam wrote:*   

> Here last message after emerging apache:
> 
> ```
>  * Attention: cgi and cgid modules are now handled via APACHE2_MODULES flags
> 
> ...

 Generally I'd start with the smallest possible set of additional features and then only add what's needed by later experience.

----------

## NeddySeagoon

pmam,

Start off by asking yourself where is your content going to come from?

Who will the site serve?

If its on the big bad internet, you will need a static public IP or a domain name or both.

Look at no-ip and similar services.

The more complex the facilities, the harder you need to work to secure it, or to put it another way, the wider you open the window, the more the dirt blows in.

If you only need to serve staic web pages a very basic install will do.

To serve your users /home/<username>/public.html directories, you have to word a bit harder. Thats like dev.gentoo.org/~neddyseagoon

To serve dynamic content from a database you need cgi support.

Keep it simple to start with. 

```
emerge apache
```

will get you a stie that says 

```
It Works!
```

----------

## khayyam

 *pmam wrote:*   

> I would like to build a web server – My first intention is to learn how it works, and understand all aspects of this system.

 

pmam ... if that's the case then you should start with understanding the basic mechanisms, ie, using socat or (one of the many variations of) netcat/ncat to build basic pipes. These you can just play around with, serving files, text, or html.

Then you might look at some of the more minimal webservers, such as www-servers/lighttpd, or www-servers/bozohttpd ... because 'a webserver' doesn't necessarily have to be apache.

Then there is www-server/nginx which is somewhat of a new, but popular, contender for apache's thrown.

Each one of these has a different method (configuration, etc) of doing the same thing, so each can give you some perspective on how "serving http" works. Also, not all the advice you might read on the internet will be good advice in this regard (ie, see how widely AddHandler is advised).

Obviously don't spend too much time with all this, your not trying to learn everything there is to know, but having some background, and understanding what tool is best for the particular job, can help.

best ... khay

----------

## pmam

NeddySeagoon,

To ask the right questions is an essential step...

Not sure I well understand your questions, but I will try to:

 *Quote:*   

> Start off by asking yourself where is your content going to come from?

 

My first intention is to have a 'Home web server', so the content will be stored here in my server.

 *Quote:*   

> Who will the site serve?

 

Not internal users – will serve 'the big bad Internet'.

Hope I can get it without purchasing domain name etc - I am going to look at no-ip.

 *Quote:*   

> If you only need to serve static web pages a very basic install will do

 

Yes - If that means something like a Blog or a content maintained by php, produced by something like Wordpress.

 *Quote:*   

> To serve your users /home/<username>/public.html directories, you have to word a bit harder. Thats like dev.gentoo.org/~neddyseagoon

 

I saw your link - Is this a 'dynamic content'? I will need a database, but later on - Now I am starting without...

I followed charles17's tips with minimum USE flags, and also installed net-misc/netkit-telnetd and I can connect to server.

I think there are some mistakes in wiki:

The name of the configuration file here - https://wiki.gentoo.org/wiki/Apache#Default configuration -

Should be /etc/apache2/httpd.conf - (with 'd') - It caused some confusion...

Also -  I can access to http://localhost/ and see' Index of /' and see directory called: 'htdig/' and can enter to, but There is no 'It Works!' -

This is missing – please inform if it is ok and need to correct wiki? Please confirm these mistakes so me or someone else will correct it.

Trying to emerge dev-lang/php but get a 'Problem resolving dependencies' - I will handle it in portage forum.

Khayyam,

Let me grasp your important info - I really need it!

When I saw the plenty of stuff to read, my head became much heavier, until I saw:

 *Quote:*   

> Obviously don't spend too much time with all this, your not trying to learn everything there is to know, but having some background, and understanding what tool is best for the particular job, can help. 

 

Important advise! A little relief ...   :Wink: 

Thanks you all

----------

## szatox

 *Quote:*   

> I would like to build a web server
> 
> Please advise minimum required hardware 

 

Hint for a brave guy: try hacking your router

Hint for smart guy: go for the cheapest ARM board you can find.

Since you mentioned you have some old hardware you can use, yes, it will do a fine starter kit. It will take much more power though, so you might still want to consider cheap ARM board if you decide to keep it on all the time.

----------

## NeddySeagoon

pmam,

Do not use telnet.  Its not safe on an internet facing box.  Passwords are sent in clear text.

Set up ssh with root logins disabled. Better yet, set up ssh with key based authentication only. No passwords.

You will get a lot of 'script kiddies' attacking your site.  Don't invite them in.

Static pages can be written with a text editor.  There are no scripts anywhere.

This closes off one attack vector.

Dynamic content means the server assembles the pages it serves somehow. The scripting mechanism can be attacked.

Browse http://bloodnoc.org/ to see the "It works".  My virtual hosts are in a mess, so the site is not working properly.

I don't actually use the main site at all. Its all sub domains and users public.html directories. I probably won't fix it until the weekend.

dev.gentoo.org/~neddyseagoon is all static.  Well thats not quite true

Some of the documents are written in Gentoos version of XML (GuideXML). 

That would still be considered static as pages are not compiled in direct response to requests. They are rendered into html.

/etc/apache2/httpd.conf  is correct. Feel free to fix the wiki

The file /var/www/localhost/htdocs/index.html is what the default install of Apache serves.

The idea is that you put your content here and remove or rewrite the index page.

----------

## aahjnnot

 *pmam wrote:*   

> 
> 
> Please advise minimum required hardware – hope I can use, at least for starting, my old machine.

 

You could do worse than a Raspberry Pi for $35. My Model B Pi runs Mediawiki just fine and it sips just a few watts of power - important for a device that's powers 24x7.

The new Pi 2 is the same price but has 6x the processor power and 2x the RAM of the earlier Pi. It should be perfect for a light duty web server. There's already a waiting list but they're apparently making 50,000 units a week just a few miles from where I live, so you shouldn't have to wait too long.

Gentoo runs perfectly on the new Pi, BTW.

----------

## pmam

NeddySeagoon,

 *Quote:*   

> Do not use telnet. Its not safe on an internet facing box. Passwords are sent in clear text.

 

I know - I just follow the wiki/apache that suggests how to see if can connect to server with Telnet.

 *Quote:*   

> Set up ssh with root logins disabled. Better yet, set up ssh with key based authentication only. No passwords. 

 

Thanks to your tips.  I am going to see how to implement...

 *Quote:*   

> Dynamic content means the server assembles the pages it serves somehow.

 

If I well understand - i.e:  Web site with database that can be changed by the user actions -

Is this an example of a Dynamic content, that required scripts to handle these activity on database, and these scripts can be attacked?

 *Quote:*   

> /etc/apache2/httpd.conf is correct. Feel free to fix the wiki 

 

I have fixed it.  No doubt - Historic moment - My first wiki's correction   :Wink: 

Waiting for someone to check if getting "It works" from http://localhost/, or not.

I continued with wiki/apache and installed php but regarding this:

 *Quote:*   

> Now, suppress or rename /var/www/localhost/htdocs/index.html and open the test page: http://localhost/. You should see a table describing the PHP settings 

 

When I open the test page: http://localhost/, I can see the new 'index.php', but there no data inside - Do not know if it is ok, or not?

BTW: What does it mean: 'suppress or rename /var/www/localhost/htdocs/index.html'?

In order to get some idea how to design my web site, It could be nice to view some examples:

Can I see some web sites of Gentoo's users from different type and concept - Static, Dynamic, based on ARM board/Raspberry Pi  etc - 

If it is not a secret, Of course. As I see that many users have web server,

I am curious to know what are the main missions/utilities of these sites? It could give me some new ideas.

Is there a category here in the forum for introducing Gentoo's users 'creations'? 

Thanks

----------

## szatox

 *Quote:*   

> If I well understand - i.e: Web site with database that can be changed by the user actions -
> 
> Is this an example of a Dynamic content, that required scripts to handle these activity on database, and these scripts can be attacked? 

 You understand well and yes, those scripts can be attacked, while it's damn hard to attack flat html as nothing gets executed on the server in latter case. Well, one can still attack apache itself, but it's still less likely than injection attacks against that dynamic content.

 *Quote:*   

> 
> 
> When I open the test page: http://localhost/, I can see the new 'index.php', but there no data inside - Do not know if it is ok, or not? 

 

it is OK. Otherwise it would throw you an error in your face.

 *Quote:*   

> BTW: What does it mean: 'suppress or rename /var/www/localhost/htdocs/index.html'? 

 

It means *exacly* what it says. Rename that file. Or delete it.

 *Quote:*   

> 
> 
> Can I see some web sites of Gentoo's users from different type and concept - Static, Dynamic, based on ARM board/Raspberry Pi etc -
> 
> If it is not a secret, Of course. As I see that many users have web server, 

  You can think of it as a cake.

There is a physical board at the bottom. Second layer is software. This must be compiled for architecture compatable with your board. Doesn't matter what architecture it actually is as long as it is the same for board, operating system and the application.

Third layer in this case is the content. This is what the user can see. Doesn't matter what stuff you use to serve it, it won't change by a bit.

----------

## NeddySeagoon

pmam,

Gentoo sets up Apache with a default virtual host that serves the main site.

If the file  /var/www/localhost/htdocs/index.html exists it will served to visitors. Thats the It Work!, until you change it.

If you delete  /var/www/localhost/htdocs/index.html  and put some files or directories in  /var/www/localhost/htdocs/ Apache will serve a directory listing of /var/www/localhost/htdocs/ , rather like gentoo.org/~neddyseagoon.

http://www.grytpype-thynne.org/ just serves the It works!

http://kernel-seeds.grytpype-thynne.org/ serves the kernel-seeds virtual server from the same server.

Thats a static site.

Try using the "View Page Source" in your web browser.

The first link will show you 

```
<html><body><h1>It works!</h1></body></html>
```

As others have said, any hardware will do to let you dip a toe in the water.  No need for an investment in a low power ARM board.

I also have a mirror of kernel seeds on the SDCARD of a Raspberry Pi server. One visitor at a time could not tell the difference between the Pi and the AMD64 grytpype-thynne.org, which is in a data centre somewhere in France.

-- edit --

For completeness http://www.grytpype-thynne.org/~roy, serves my /home/roy/public_html directory.  You need to know its there to reach it as nothing links there.

At least, as far as I know.

----------

## pmam

szatox & NeddySeagoon,

 *Quote:*   

> This is what the user can see. Doesn't matter what stuff you use to serve it, it won't change by a bit. 

 

I was not so clear - Of course, I know that users do not care.. (Though the explanations are nice) -

I just wanted to see some examples of web sites that Gentoo's users have -

different types: static, dynamic etc - just to get some ideas. I think that a category of Gentoo's users web sites, in this forum, could be helpful. 

In addition, I mentioned that I would like to see web sites based on ARM board/Raspberry Pi - just to see how this 'little machine' handle activities of the site...

 *Quote:*   

> No need for an investment in a low power ARM board. 

 

Yes - I am going to start with my old desktop, to learn how to build the site - later on I will consider this low power machines.

However, please attach any link of this ARM board - just for viewing...

I need to put together all the needed stuff for building web server - I still do not have the whole vision of this process - 

wiki/apache is good for someone who already know how to build the content and organization/maintenance of the site. 

However for someone who do it for the first time... I guess that do not need to create pages with html -

may be some adjustments - I assume there are some tools that facilitate this process.

I guess there are many tutorials for 'How to build the content of web site' - with guidelines that help to see the whole picture -

can you please recommend on some of them?

Thanks

----------

## aahjnnot

 *pmam wrote:*   

> 
> 
> However, please attach any link of this ARM board - just for viewing...
> 
> 

 

Here's the Raspberry Pi project page. Retail distribution varies by country, but it generally costs the local equivalent of $35 plus delivery and taxes. The new board has a quad-core processor and 1GB of RAM and is actually snappy enough to use as a desktop machine. It would be more than adequate for a headless server - I use the original version with a slower single core processor to run a web server (Apache, Mediawiki, Squirrelmail), mail server (Postfix, Dovecot), user identification and authentication (OpenLDAP, Kerberos) and network services (Bind9, ISC-DHCP); it does the job perfectly.

5 million people can't be wrong...

----------

## NeddySeagoon

pmam,

First of all, you need some hardware.  Unless you only want to view your website at http://localhost, the hardware needs a network interface.

The architechure of the hardware does not matter. 

The next layer is an operating system suitable for your hardware.  This hides the hardware from your applications, so the applications don't care about the hardware.

The next layer is your applications. You need a web server application here. There are many to choose from, you don't have to choose Apache. Pick one that has the features you need.

Try several.

The Icing on this layer cake is you web content. 

Now to help you with some of your choices.  First the hardware.

Where will the hardware be located? 

How much bandwidth will it have? 

How much traffic do you expect to serve?

How much will it all cost?

None of the answers are constants. You will already have considered some constraints.  Starting out, its likely to be, home, whatever my home uplink speed is, not much - it has te fit in my home uplink, procurement cost, nothing, as its old redundant hardware, running cost abount 80w, or 2 units of electricity a day, runnitg 24/7. Thats just over 720 units a year.

Its likely that the constraint here is your uplink speed.  

The operating system is probably going to be Linux.

----------

## cwr

I built a small webserver for someone who wanted to test their site code using a Pentium III

laptop and Ubuntu and lighttpd; I run that server with a static page on my own laptop to serve

documents, and it uses very few resources.

If you want to learn Apache, then run Apache perhaps on more powerful hardware.  Otherwise

messing with Lighttpd on some obsolete local hardware is entirely practical.

Will

----------

## pmam

NeddySeagoon,

Start with one desktop at home with duo2cores and it is ok.

Linux/Gentoo as operating system, and of course that applications do not care...

It could be apache or nginx as khayyam suggested - I need to read and decide - no problem

As you said:' You already have considered some constraints.' - At the moment I am not dealing with bandwidth, traffic and etc -

I want to learn how to build a web server, and see all aspects,but -

Process should be  in a way that once having a working web-server, and considering all what you have asked me (bandwidth etc), 

then I will be able to switch to the real web-server with minimum changes. If it will required to do it all over again, it is not the best case, however,  it will be easier to repeat.

My big X (unknown) is regarding building the content and organize it - 

Though it is not under Gentoo's umbrella, please advise some preferable directions - 

nice free tools - that help to handle the content issue. 

Cwr,

 *Quote:*   

> If you want to learn Apache, then run Apache perhaps on more powerful hardware. Otherwise messing with Lighttpd on some obsolete local hardware is entirely practical. 

 

Yes, I want to learn, and as you can see in this post - Duo2cores will be ok - BTW: I think that you mean: 'entirely NOT practical' - Right?

One thing quite disturbs me – Recently facing with critical problems after system updating. The desktop intents to be webserver, for few days without X server after system updating – and still  it's an open topic with no solution! I had a similar problem in another machine. I assume that the regular Gentoo's system updating process is inevitable and acceptable, but when a web-server lost its X server ,Ah, that is not ok. I wish  it would be my fault, so can learn how to prevent it, but seems it from the 'dark side of the moon' - 

upgrading one package/driver or whatever, without considering the whole system, could break down the system – a problem for regular machine, but for web server it is critical... Once finding out the missing package, it will be fixed right a way, however, few days without X server it is really a big deal! 

aahjnnot,

New  Raspberry Pi looks very nice and I understated that you have some sentiments as it is manufactured very near to you...  :Smile: 

However, can you attach a link of other ARM boards of similar functionality as PI?

Thanks

----------

## charles17

 *pmam wrote:*   

> The desktop intents to be webserver, for few days without X server after system updating – and still  it's an open topic with no solution! 

 Why do you think you need X on a web server? See http://en.wikipedia.org/wiki/LAMP_%28software_bundle%29.

Testing should better be done from another computer.

----------

## pmam

charles17,

Thanks for the important link!

 *Quote:*   

> Why do you think you need X on a web server? Testing should better be done from another computer.

 

At least you agree that X server is needed for the 'other computer'...    :Wink: 

----------

## charles17

 *pmam wrote:*   

> At least you agree that X server is needed for the 'other computer'...   

 Only if you need or want to run graphical applications on the 'other computer'.

----------

## NeddySeagoon

pmam,

How easy it is to to move your content depends on what you want to move it to.  If you are looking at paid for solutions, in order of complexity there is

1. rent a whole server in a data centre. 

2. rent a Virtual Machine on a server in a data centre.

3. rent web hosting.

For 1. you get a whole server, you install it remotely.  Its all yours. you get to keep the pieces if it won't boot but defective hardware is replaced.

2. normally does not give you much choice of operating systems.  You get root access, so you can install things.

3. You just upload your content and away you go. 

Costs for all three vary from free to huge, depending on what you want.

-- Edit ... Check your PM ---

----------

