A Basic Linux webserver with OpenSUSE

A Basic Linux webserver with OpenSUSE

so, I know some people who wanted to know how to setup a Basic Webserver with Linux, if you’re not all to familiar with Linux OpenSUSE is often the easiest to start with, if you are familliar you can use pretty much any Linux distribution you prefer to make a webserver, but this article is focused on using OpenSUSE, as such you will not be able to fully follow along if you use Debian, Ubuntu Server, or otherwise as I will be using YaST to configure the Firewall and service starting on system start-up, and I will be installing software with Zypper.

what you will need to do this guide

you’ll need two computers, one should be your normal PC, which you should use to make your website and manage the server, I’ll call this system your workstation for the rest of the guide.
the other computer will be our server, keep in mind that following this guide anything currently on the second system will be erased, I will call this system the server in the rest of the guide.

System requirements for the Workstation

this actually doesn’t matter a lot, you can use any Windows, Linux, or OS X system.
but a recent system is better, though mostly just cause older systems are slower.
I would recommend to have a supported system, so avoid Windows XP or OS X versions before 10.8.5.

as said, it doesn’t matter much, but you do need a DVD-burner.

System requirements for the Server

the server must be capable of running OpenSUSE, the minimum requirements are:

  • Intel Pentium III 500Mhz or higher
  • 512MB physical Memory
  • 3GB hard disk space
  • 800×600 Display resolution
  • 10/100Mbps network card

please not these are bare-minimum specifications, and actually using this will result in a rather slow system.
the recommended requirements are:

  • Intel Pentium 4 2.4Ghz or higher, or any 64-bit Intel or AMD Processor
  • 1GB (1024MB) Physical memory or more
  • 20GB Hard disk space or more
  • 1024×768 display resolution or higher
  • Gigabit Ethernet Card (10/100/1000Mbps)

for the webserver, you probably won’t need much more, at least not if you follow along, more memory might be nice but isn’t really needed, and starting with 4GB RAM a faster hard disk would help more to get more performance.

Installing OpenSUSE 13.1 with OpenSSH, an no desktop

the first thing you’ll need to do to actually get your server is to install the Linux system you want to use, as said, this article will focus on OpenSUSE, at time of writing the latest version is 13.1, for a server it’s best not to install a graphical desktop, as these use a lot of memory, we also need a way to publish our website to the Server once it’s done, and for that I will be using SFTP, but keep in mind this only really works well if only one person will be managing the website files on the server.

getting OpenSUSE

before you can install OpenSUSE you will need to have it, you can download it for free from the OpenSUSE website: http://software.opensuse.org/

at the top you should see a button “4.7GB DVD (also suitable for USB Stick”, this is already expanded, so directly under it you should see a few options: Download Method and Type of computer.
the download method Direct Link and Type of computer 32 bit PC should be pre-selected.
Even if you have a 64-bit PC it will run 32-bit, but a 32-bit PC will not run 64-bit, so these options should work from anyone, so if you don’t know whether your PC is 32-bit or 64-bit, just click on the “Download DVD” button and you should get a file called “openSUSE-13.1-DVD-i586.iso” (the 13.1 will change with newer versions, so depending on when you try to use this guide it might be a other number).

If you know your PC is 64-bit, select 64 bit PC under Type of Computer and then click Download DVD.

since for this guide I assume you’ll be using an older PC that you happened to have standing around, I’ll go with the 32-bit version, but all configuration is exactly the same, just keep in mind that if any screenshots show “i386”, “i568” or “i686” you will see “amd64” if you use the 64-bit version.

preparing your installation media

you will need to burn the downloaded file to an image, or you will need to make a bootable USB drive, for the latter you need a server that can boot from USB drives, and older computer might not be able to, so if you are uncertain it’s likely easier to make the DVD.

in recent Windows versions Windows includes the Windows disk image burner, in Windows 7 just double click the downloaded file and this will open by default if you don’t have any other burning software installed.
in Windows 8 and 8.1 Windows will ‘mount’ the disk image by default, which isn’t what we want, so you need to right-click and select “Burn Disk image” or pick “Windows Disk Image Burner” under “Open with…”.

under OS X open Disk Utility, to do so press Cmd+Space and just search Disk in Spotlight, if it won’t find it, this can happen sometimes, either open Launchpad and open the Utilities stack (it may be called Other in some versions) and pick Disk Utility.
if you use a version of OS X that doesn’t have Launchpad, or if you don’t like it, open the Applications folder in Finder and navigate to the Utilities folder and open Disk Utility from there.
in disk Utility go to the Images menu, choose Burn…, select the downloaded image and click Burn.

on some recent Mac’s you might need a USB DVD drive to burn the disk, as Apple ships most systems without an Optical drive now.

doing the actual installation

to install you need your computer to start from the DVD you burned, commonly it will do so by default, especially on older systems, if it seems to ignore the DVD while starting, it might be it is configured to boot (or start) from your hard disk first, which isn’t what we want, to change this you need to go to the BIOS Setup, the first screen your computer gives might say something about a specific keyboard key starting setup, but it might also just show a logo or may go by so fast you can’t see any messages.

sadly there is no standard key, but there are some commonly used keys: F2, F10, Delete and Escape.

if you have the right key it will likely say something about “Entering SETUP” or “Setup…”, on most computers the BIOS uses Tabs at the top for catigories of settings, if you don’t know what a setting means please do not touch it, as it can cause trouble, there is often a tab called Boot, you can usually switch tabs with the left and right arrow keys, move over to the Boot tab.

OpenSUSE 13.1-2014-06-11-16-12-52

hopefully it looks a bit like this, if it does, you can use the + and – keys to move items in the list, and use the up and down arrows to select (highlight) an item in the list, find your DVD drive (note at it might be called CD-ROM even if it also supports DVD’s), and move it to the top of the list.
in my BIOS I have the open to Save and Exit with F10, as shown in the bottom green bar on the bottom right, your computer might have this as well, if it doesn’t you can always still swithc to the exit tab and it will have an option “Exit saving changes”, highlight that and press enter, you will likely get a confirmation screen if you want to save changes and exit, highlight yes and press enter.

OpenSUSE 13.1-2014-06-11-16-16-32

 

 

once at this screen you need to press the down arrow once to select “Installation”, if you don’t it will boot from the hard disk anyway after a short time-out.

after highlighting Installation you need to press enter to start it, the screen will show some text and later a progress bar on the bottom, just wait until you get the screen shown below.

OpenSUSE 13.1-2014-06-11-16-19-41

this is the Language Selection screen, which also shows the License Agreement, just click on the green Next button in the bottom right hand corner.

it will start to Probe the system (detect hardware), after which you get to select the Installation mode, choose New installation and make sure to uncheck “Use automated configuration”, as easy as this sounds it won’t give us the installation we want in this event, after unchecking this click the Next button.

the next page you get is the Clock and Time Zone screen, you can either click your region in the map, which may be a bit difficult to click the right place, or select a region and then a timezone with the two drop-down lists under the map, make your selection and click Next.

after that you get the Desktop Selection, as I said we do not want a Desktop, so our server has more memory available for it’s server tasks.
KDE Desktop should be selected as it’s the default for OpenSUSE, select Other and from the new options that appear select “Minimal Server Selection (Text Mode)” and click next.

now we get to the Suggested Partitioning page, I’d recommend to check “Create LVM based proposal” (but do not select Encrypt Volume Group, doing so would require you to type a password anytime the system starts, which we don’t want for a server.).
further, uncheck “Propose Seperate Home Partition”, the Home partition is used for /home which is for use directories, since this is a server those will remain mostly empty, and the Home partition would get most of the available disk space, which we want to have available for the website.

after selection your screen should look like this:

OpenSUSE 13.1-2014-06-11-16-28-00

in the top it will show what it will do, one thing that is a bit odd is that it makes a “volume group” or 39.60GB but only uses 20.00GB for /, and 1.96GB for the swap, meaning a lot of space isn’t used, let’s make sure we do use all available space for /, to do so click on the “Edit Partition Setup…” button.
this issue may not occur for you, to check add up /dev/system/root (20.00GB in my case) and /dev/system/swap (1.96GB in my case) these should add up to the size mentioned din the rest line (“Create volume group system (SIZE GB) from /dev/…), which is 39.60GB in my case, and they only add up to 21.96, so I’m missing some space.

OpenSUSE 13.1-2014-06-11-16-31-41

you should get a screen similar to the above, look for the entry with /dev/system/root under Device, and right-click it, pick Resize.

in the dialog that pops-up select Maximum (if it isn’t selected already), and just click the OK button.
after this the size should be updated to the maximum space that was available, click on the green Accept button.

you should now return to the previous screen but with the size for / (/dev/system/root) be the maximum space you had (listed int he red line).

OpenSUSE 13.1-2014-06-11-16-36-42

 

this time, if I add up the sizes for /dev/system/root (forth line) and /dev/system/swap (fifth line) they add up to the total space listed in the red (third) line.

so we can click next, and setup a user, the name and password are up to you, OpenSUSE will use a package called cracklib to check if the password is weak password or not, if it is it will warn about this, but you can say you want to use the password anyway, it is best to use a strong password.
OpenSUSE 13.1-2014-06-11-16-40-01

make sure “Use this password for system administrator” is checked, and uncheck “Automatic Login”, as for a server this is just a security risk, you won’t need to login on the system itself much so those few times you do it’s really worth the additional security of having to login manually, the rest of the settings are fine as they are so we once again click next.

in the “Installation Settings” we do want to make few changes, most settings are fine, but we need the SSH Server to run, we can configure that later, but it only take a single click to setup now.

OpenSUSE 13.1-2014-06-11-16-42-47

at the bottom of the list you see the line “SSH Service will be disabled, SSH port will be blocked” and a link Enable and open after it, just click on that link and the text will change to “SSH Service will be enabled, SSH port will be open”.

an extra line to check, is the one under the “Default Runlevel” header, it says 3: Full multiuser with network, which is what we want, if it says anything else, click the Defaul runlevel header and selection “3: Full multiuser with network”.

with that done, click Install, this will give you a pop-up “Confirm installation”, click the Install button on this window.

this will bring you to a slide-show about OpenSUSE while it installs, you can click on the tabs above to switch to Details if you like, or read the release notes during installation.

depending on the speed of your computer this might be a good time to get a coffee or such.

Configuring your installation

Once the actual installation is done the system will restart, we want to boot from the hard disk, your system should still boot the DVD but the DVD will make the system boot from the Hard disk if we just wait, so we don’t have to worry about that.

since we’ve chosen not to install a desktop, we should get YaST 2, Yet Another System Tool 2, which will let us configure the basic system options.

first is the Host name and Domain name, the host name should already be selected and has a proposed name, and the proposed domain name of site, we aren’t really going to use this host-name or domain name so we can leave it as is, though you may just give it a name you like, after you’re done just press tab until the Next button it highlighted and press enter, or you can press Alt+N.

for a server you probably want a static IP, yet that is a bit more difficult to setup, often your DHCP Server (usually your router) will also allow you to set it up so a specific computer will always get the same IP, which is much easier, but how it works does vary a bit.

I’ll get back to this later, but for now just leave it as it is and use DHCP.
following this it will want to do a network test, specifically an internet test, I do recommend you do this so just press Alt+N in this.

the next window is a bit unclear but has a line “Test result”, once that changes to Success, you can press Alt+N again, and since we used DHCP it will probably just work.

Online update it the next we get, but I personal find it easier to do this alter, so I chose Skip (Alt+S) and then go to the next screen with Alt+N.

we again get the release notes, which we can go further from with Alt+N.

last step of the installation, finish up with Alt+F.

installing the Apache webserver software

with the installation done we should get a login screen.

it should show a line with welcome text followed by a line with the hostname we setup earlier followed by login:

you can login using the username and password you created during the installation, after loggin in you get a command shell, to install Apache just type the command sudo zypper in apache2 you will be asked for your password, after which Apache will be installed.

to start Apache run sudo systemctl start apache2.service
make sure Apache is actually running, use sudo systemctl status apache2.service.
this second command will give a fair amount of information, but we are only interested in a green bit of text which should say “Active (running)”, if you see a red line it’s not working, but since the reason can vary I can’t provide much information on how to fix that now.

 

Configuring the Firewall

ok, so we have OpenSUSE installed, Apache is installed and we have OpenSSH running, but if you’re trying to actually visit your website it will probably not work right now, this is because while Apache is installed the Firewall is still disallowing anyone from actually connecting to it.

use the command sudo /sbin/yast, from here we can configure various features of the system, including the firewall.

OpenSUSE 13.1-2014-06-11-17-15-17

when you start YaST Software should be highlighted on the left, press the down arrow key until Security and Users is highlighted, then press tab to highlight Firewall and press Alt+R to open the Firewall Configuration.

in the left menu press the down arrow until Allowed services is highlighted and press enter.

OpenSUSE 13.1-2014-06-11-17-16-41

under “Services to Allow” (which you can select quickly by pressing Alt+S), choose HTTP Server from the drop-down menu and press Alt+A to add it to the list of services.

you may also notice that “Secure Shell Server” is already in the list, this is because we enabled it during the installation.

when done, press Alt+N to get to the Firewall Configuration: Summary Screen.

OpenSUSE 13.1-2014-06-11-17-19-16

and press Alt+F to finish and save the firewall configuration.
you should return to YaST’s main screen, and close YaST by pressing Alt+Q

Making Apache start automatically

all is working well now, but you do still have to start Apache manually every time the server starts again, that doesn’t really work well for a web-server, so let’s make Apache start automatically whenever we start the server.

now comes a slight problem, we need the Yast Services Manager to easily configure that Apache has to start, but it seems to be missing in 13.1, so we need to install it, sudo zypper in yast2-services-manager, after this we need to start YaST again, sudo /sbin/yast.

this time, int he left menu go to System, press tab, highlight Services Manager and press Alt+R.

at this point, Apache should be listed, but it will be shown as Disabled and Active.

OpenSUSE 13.1-2014-06-11-17-36-57it’s active because we started it manual before, the Disabled is the state Apache will be in when the server it started.

that’s to say, like this Apache will not run as soon as the server is started up, since Apache is the webserver we do want it to run, so it has to be enabled, simply highlight Apache2 in the list, and press Alt+E to enable it, then press Alt+O to confirm the new settings.

you will just see “writing settings…” before returning to the YaST Main screen, press Alt+Q to close YaST.

Finding the Server’s IP Adress

to actually upload our website and to visit it later, we need the Server’s IP adress, also called it’s network adress.

to get this, use the command sudo /sbin/ifconfig, you will be asked for you password, and then get quite a lot of information about the network settings.

OpenSUSE 13.1-2014-06-11-17-41-43

what your network card is called depends on the kind of card you have, but the lo if a local “loopback” inferface, you only care about the other option, in my case eno167777, the second line of each interface will start with “inet addr: …” that is your IP adress, in my case 192.168.126.130, write down this number somewhere, you’ll need it in a sec.

since we are done with this part, type exit or logout to logout of the local command shell.

uploading your website to the server

as I said, we’ll use SFTP to upload our site, to do so we need a program that supports this, like Filezilla Download filezilla Client.

note for 13″ MacBook Pro (non-Retina) users: Filezilla may not work well on a 13″ MacBook pro which does not have a retina display, as the resolution is much lower Filezilla may partially get behind the dock, it can still be used but may be a bit difficult to use, a other option is Cyberduck which you can find in the AppStore, in the App Store Cyberduck costs around $24 but you can also download it for free from the Cyberduck website, buying it in the App Store is essentially used as a donation, please note that I will not further talk about Cyberduck, though it’s easy to learn to use.

at the top of the screen of Filezilla, below the main icon bar is a Quick Connect bar, this is all we need right now, for the host part type “SFTP://your.servers.IP.Address” note that you should replace “your.servers.IP.Address” with the adrress you got earlier.
in my case it’s SFTP://192.168.126.130/ the username must be root and you should use the same password as for the account you logged in locally with.

Filezilla will give a message about an unkown Host-key, and asks if you want to continue, confirm this, you can also check “always trust this host, and add the key to the cache” so it won’t ask this again.

in Filezilla there are two file windows, one left for the Local site and one on the right for the remote site.

remote site is the server, you should start in /root, navigate up one folder (..) and then navigate to srv -> www -> htdocs, this folder should be empty at this time.

on the left, navigate to the folder in which you have your website stored.

simply drag the contents of the folder with your website, to the right file window and filezilla will upload them.

note that the files of your website should be directly in /srv/www/htdocs, not in a folder in it.

 

and that should do it, your site should now be on the server, simply navigate to http://your.servers.IP.address/ with your favorite web-browser to view the site.