- slide 1 of 6
Linux web server software is something that a lot of us require but do not quite know how to set up. This guide will go through a couple of simple, effective and secure ways to set up your server whether it's for testing or a scalable hosting environment. I will assume that you are using a Linux distribution with an APT repository (such as Debian and Ubuntu.) You may have to substitute some commands if your Linux distribution uses another method of installation.
- slide 2 of 6
Apache2 - Web Server
Many shared hosting companies use Apache2 because of its stability and security and it is the most favoured open-source web server daemon. If you are installing this on a home server to only be accessed from other home computers ensure that port 80 is blocked on your wireless router or modem so that others cannot pick you up as a web server when scanning for IP addresses.
In order to install it you can use the APT repository for your distribution and can usually just type as root or with root permissions: apt-get install apache2
This should start Apache2 installing with the default settings which are suitable for most home servers and it will also activate your web server. Once it is installed you should be able to point your web browser towards http://localhost or http://127.0.0.1 and see a message informing you that your web server has been set up successfully, by default your web root directory is /var/www
There may be a problem with accessing this directory as your normal user so you may want to chown the directory to your own user.
- slide 3 of 6
PHP - Hypertext Preprocessor
This involves a bit more donkey work and terminal magic but has the advantage of setting up the PHP scripting language on your server as well if you need to use it. Follow the instructions above and test that it works then we will need to install some other programs.
The first thing you will need to install is PHP, version 5 is the current version so that is the one we are going to install, if you have programs that only work with version 4 change the number accordingly. In order to install PHP and get Apache2 to recognise that it is there and use it we are going to install 2 programs, php5 and libapache2-mod-php5. Install them as you did above by typing: apt-get install php5 libapache2-mod-php5 into your terminal with root access or sudo.
In order to test that PHP is set up properly create a PHP page by using the following command in the terminal
echo "<?php phpinfo(); ?>" > /var/www/test.php
The command will create a PHP page in your web directory (/var/www) which will have the PHP info of the server inside it, if you now go to http://localhost/test.php you should see all of your information.
- slide 4 of 6
MySQL is an Open Source database application that on its own will do very little for your server but alongside PHP you can use the database to store and manipulate data. A lot of text-based games on the internet are made using PHP and MySQL as well as a lot of interesting and useful applications.
The package you are after is usually called "mysql-server" and if you have APT you may install it using this command in the terminal: apt-get install mysql-server
After you have put the command into the terminal it may ask for some details from you, mainly your MySQL root password, make this a strong password and not the same as any of the users on your machine. Finally we are going to install two programs to allow PHP to communicate with the MySQL database: apt-get install libapache2-mod-auth-mysql php5-mysql
- slide 5 of 6
If your terminal does not recognise the commands I have given at all then your Linux distribution does not use APT and may use RPM or another method of package distribution, for this you will have to read up on the commands that your package manager uses and create the installation lines yourself using your manager, if you can't figure out how to do this please feel free to comment below with your Linux distribution and I will create and comment back with the commands you need to use.
If your terminal recognises apt (apt-get -v brings information back) and does not recognise the package names it means your Linux distribution has called them something different, you may need to check with others using your distribution to find out what the packages are called.
- slide 6 of 6
You should hopefully now have a simple web server running with Apache2 and optionally PHP and MySQL, it may require a computer restart before Apache2, PHP and MySQL play along nicely with each other.
By default Apache2 will install itself as a service and start up at every boot, if you do not want this behavior to occur, try to run:
update-rc.d apache2 remove