Friday, April 20, 2018
   
Text Size

How to Build a Web Server

webserver

Have you got an old desktop or laptop computer sitting in a closet at home? I'm sure that you paid good money for it a few years ago, but now you would probably have a tough time trying to give it away. Did you know that you can easily turn it into a web server and run your own website out of your home? In this tutorial, I'm going to walk you through the process, step by step.

I'm going to assume that if you're interested enough to bother reading this article, you've probably already got an intermediate level knowledge of computer systems, so I apologize for skimming over certain topics.

lamp

First, you need to download and install an operating system for your web server. You can build a web server with Microsoft Windows, but Linux is free! I have a particluar favorite that I use called: Debian Linux. I always install the 64 bit netinst ISO and update with the packages that I need from a repository online. This type of web server is called a LAMPP server. LAMPP is an acronym that stands for Linux Apache MySQL PHP.

During OS installation, Debian will ask you to select the type of server that you are creating. Don't select "web server". Just do a simple vanilla install for now. If you pick "web server" this can cause conflicts with packages that you will install later, especially if you install a XAMPP stack with Joomla. XAMPP is very quick and easy to install and configure, but I have had compatibility issues with it regarding Joomla templates and plugins. I have found that you have much more control over your website if you install Apache/MySQL/PHP manually. That is what this article is for. It will show you how to manualy install everything that you would normally get with a XAMPP stack. I tested this article out myself using 64bit Debian 7 and it worked great.

At this point, you should have successfully installed Linux. Open a terminal and login as "root" by typing: su for "super user" in the command prompt. From this point forward, I have highlighted the text in this article that is "code". The code (in red) is what you will be typing into the command prompt. Hint: If you open this web page using your server's web browser, you can copy and paste the code into the terminal directly from this web page. This will help speed things along.




1.  First we have to install the MySQL database package:

apt-get install mysql-server mysql-client

To make things simple and ensure that I don't forget any passwords as I go through this process, I always use the same password any time that I'm asked to make one up.



2.  Next, we install Apache the popular web server package:

apt-get install apache2

The root folder in Apache (where your website files go) is: /var/www. Apache's configuration file is located at: /etc/apache2/apache2.conf.



3.  Next we install PHP, the free server scripting package used to make websites:

apt-get install php5 libapache2-mod-php5

Restart Apache:

/etc/init.d/apache2 restart



4.  We need MySQL support with PHP, so we need to install the php5-mysql package. It's a good idea to install some other PHP5 modules as well, because you might need them for your applications. You can search for available PHP5 modules like this:

apt-cache search php5

Pick the ones you need and install them like this:

apt-get install php5-mysql php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl

Restart Apache:

/etc/init.d/apache2 restart



5.  APC is a PHP based caching solution for web servers. It can help speed up your PHP pages and also adds a different caching option from the default "file" based caching that comes with Joomla.

Here is how you install APC:

apt-get install php-apc

Restart Apache:

/etc/init.d/apache2 restart



6.  phpMyAdmin is a web based GUI that you can use to manage your MySQL database:

apt-get install phpmyadmin

The installer will ask you two questions:

a. Which web server do you want to auto configure...Apache2
b. Say NO to: Configure database for phpmyadmin with dbconfig-common?

After the installation has completed, add phpmyadmin to your apache configuration. You will need to know how to use vi editor.

Add the phpmyadmin config to the file:

vi /etc/apache2/apache2.conf

[...]
Include /etc/phpmyadmin/apache.conf
[...]

Restart Apache:

/etc/init.d/apache2 restart

You can then access phpmyadmin by typing:
http://localhost/phpmyadmin
into your server's web browser.



7.  You will need an FTP server to upload files to your web server. You want this server to have an encryption capability, especially if you’re using it over the open internet, because your username and password can be observed and stolen. TLS can do this for you. OpenSSL is needed by TLS.
To install ProFTPd and OpenSSL:

aptitude install proftpd openssl

You will be asked a question:

Run proftpd:...standalone

For security reasons you can add the following lines to /etc/proftpd/proftpd.conf

vi /etc/proftpd/proftpd.conf

[...]
DefaultRoot ~
IdentLookups off
ServerIdent on "FTP Server ready."
[...]

In order to use TLS, we must create an SSL certificate. Create it in /etc/proftpd/ssl. You must install "make" and create the directory first:

apt-get install make
mkdir /etc/proftpd/ssl

Afterwards, we can generate the SSL certificate as follows:

openssl req -new -x509 -days 365 -nodes -out
/etc/proftpd/ssl/proftpd.cert.pem -keyout
/etc/proftpd/ssl/proftpd.key.pem

Country Name (2 letter code): Enter your Country Name
State or Province Name (full name): Enter your State or Province Name.
Locality Name (eg, city): Enter your City.
Organization Name (eg, company): Enter your Organization Name.
Organizational Unit Name (eg, section): Enter your Organizational Unit Name.
Common Name (eg, YOUR name): Enter the Fully Qualified Domain Name of the system (e.g. "server1.example.com").
Email Address: Enter your Email Address.

In order to enable TLS in ProFTPd, open /etc/proftpd/proftpd.conf and uncomment the "Include /etc/proftpd/tls.conf" line:

vi /etc/proftpd/proftpd.conf

[...]
#
# This is used for FTPS connections
#
Include /etc/proftpd/tls.conf
[...]

Then open /etc/proftpd/tls.conf

cp /etc/proftpd/tls.conf /etc/proftpd/tls.conf_orig
cat /dev/null > /etc/proftpd/tls.conf
vi /etc/proftpd/tls.conf

and make it look as follows:

<IfModule mod_tls.c>
TLSEngine                               on
TLSLog                                   /var/log/proftpd/tls.log
TLSProtocol                            SSLv23
TLSOptions                             NoCertRequest
TLSRSACertificateFile            /etc/proftpd/ssl/proftpd.cert.pem
TLSRSACertificateKeyFile      /etc/proftpd/ssl/proftpd.key.pem
TLSVerifyClient                       off
TLSRequired                           off
</IfModule>

If you use "TLSRequired on", then only TLS connections are allowed. By using "TLSRequired off", both TLS and non-TLS connections are allowed. I would recommend using "TLSRequired off" until after you are completely finished installing Joomla.

Before you login to your FTP server using Filezilla, you’ll want to give yourself permissions to the www folder. The following lines of code will make /var/www writeable by its group and add your account to that group:

adduser username www-data
chown -R www-data:www-data /var/www
chmod -R g+rw /var/www

Before you login to your FTP server, you should configure Filezilla to use TLS (this is a must if you chose TLSRequired on).
In FileZilla, open the Site Manager:
Create a new site with your account info and server IP address.
In the encryption drop-down menu, select FTP with TLS instead of normal FTP.

Restart ProFTPd:

/etc/init.d/proftpd restart



8.  You may also want to change the time zone of your server and ensure that it updates its time from the internet:

apt-get install ntp



9.  Install Joomla by unpacking and uploading the Joomla install files into the root website directory: /var/www/ and then open a web browser and type the URL or IP address of your server. Follow the instructions that Joomla gives but read this first:

You can’t just install Joomla like you normally would with a XAMPP stack. The issue for a regular install is file ownership. There are generally two main server users that end up owning your files - the FTP user, and the Apache/PHP user. Obviously, when you upload files using FTP, the FTP user ends up owning them. Therefore, if you give a file 755 permissions, then ONLY the FTP user can write to that file. If you install Joomla! without the FTP layer, then the files it creates are owned by the Apache/PHP user. If you give the file 755 permissions, then ONLY the Apache/PHP user can write to that file. Just to emphasize, the fact that these username and passwords happen to be the same has no effect whatsoever on anything. They are different subsystems and are unrelated. There are generally two approaches to take:

Option 1: Download and unpack Joomla! using the terminal in Linux. This will generally result in all of the files being owned by the Apache/PHP user. Ensure that the root directory, which all of your Joomla! files are installed in, is writable, so that the installer can create the configuration.php file. Then, install Joomla! WITHOUT the FTP layer.

Option 2: Upload all of the Joomla! files using FTP. This will generally result in all of the files being owned by the FTP user. Make sure that your Joomla! root directory is writable, again, so that the installer can create the configuration.php file. Then install Joomla! WITH the FTP layer.

Ensure that your cache folders are owned by the Apache/PHP user, because these files are written by PHP. If you chose and applied either option 1 or 2, you should get better results and extension installation should work properly via the admin interface. Mixing the two approaches will cause you no end of grief.

A good way to check that everything is in order is to browse to the Administrator section of your site and then to "Site->System Info" from the menu. Click on directory permissions. If you don't have the FTP layer enabled, it is important that everything show up as Writable. If you do have the FTP layer enabled, then it is important that your two Cache directories show up as writable. It is most likely okay that the rest show up as unwritable, because Joomla! can likely write these files using the stored FTP settings.

So that's it. You now have a working web server. Some more things to consider...

1. Get a static IP from your Internet Service Provider.
2. Purchase a URL from a domain registrar like GoDaddy.
3. Forward incoming http requests to your web server (port 80 in your router).
4. Update your Joomla! configuration.php file with your website's URL when you're ready to go live.




blog comments powered by Disqus

Login Form