Now, let's compile a server. 1
I'll take one of the most well-known FTP servers, the ProFTPd which means Professional FTP Daemon. 2
The first step when compiling a program is to get its source code. This is available because it's open 3
source so anyone has access to the source. 4
Go to the official website, proftpd.org, and download the latest release 5
This is 1.3.7a and I’m clicking with the right mouse button on the gzip archive. 6
And I'm selecting copy link address and in the terminal, I'm writing wget -c and I'm 7
pasting the contents of the clipboard. 8
I'm downloading the source code. 9
The file was downloaded in the current directory. 10
This is the file. 11
The second step, which is optional but highly recommended, is to check the integrity of the file, 12
especially if you install it on a production server. 13
You can do it by checking its hash or digital signature. 14
The author publishes the hash on its webpage and I'll calculate it locally as well; if they are the same, 15
then the integrity of the archive was verified. Let's see its hash. 16
This is the md5 hash, and I'm calculating it locally as well. md5sum and the file. 17
Let's compare the hashes. 18
I'm copying it and pasting it in the terminal. 19
I've got the same hash, so I assume that's OK. 20
The third step is to extract the archive. 21
It's compressed as a tar archive, so I'm running tar -xzvf and the file. 22
A new directory that contains the source code of the server, was created in the current one; I'm 23
moving to that directory since all following commands will be relative to that directory. 24
By the way, the source code is in the src/ directory. 25
In this one, this is the source code of the server. 26
In this directory, we see there's an executable file, a script called configure. 27
This is very important since it does two things. 28
It's checking if the requirements and the dependencies of the program you are compiling are satisfied 29
and it's configuring how the program will be compiled, which options will be enabled and which ones 30
will not. 31
If, for example, you don't have the gcc compiler installed or if a required library is missing 32
then configure will show you the error. 33
Troubleshoot the problem and run configure again until there will be no error. 34
Don't go further with the compilation process if configure throws any errors. 35
This script has lots of options to control how the program will be compiled; to learn about its options 36
run ./ configure -- help. By the way, it's recommended to run configure as a 37
nonprivileged user and only the final step of the completion process as root. 38
I am executing the script, using ./ and the script name, because I want the shell to execute 39
the script from the current directory. 40
Let me show you something: if I simply run configure, the shall we search for it in the path and 41
will not find it and you'll get to the error " command not found", so run it by prefixing its name with 42
./ 43
I'm running the script. 44
It has displayed a lot of output, so I'll pipe it to less so that I can navigate through the output 45
| less. 46
Let's take a look at the most important options. 47
--prefix and a directory specify where the software will be installed. If you don't use 48
this option, the application files will go to the standard 49
directories like /bin, /usr/bin, /etc and so on and overwrite any other files with 50
the same name. 51
This could break your system. 52
My advice is to always use the prefix option 53
when compiling a program. You can fine-tune your compilation with many options which are specific to 54
each program. 55
What they want to show you is how to compile or not some features into the final product. Let's search 56
for example, for SSL. 57
And there is an option called enable SSL, which is by default, No. 58
This means that without specifying this option, the FTP server will be compiled without SSL support, 59
so it won't support encrypted connections. 60
If you want it to support SSL, then give this option to configure. 61
This is applicable to any other option; let's search for ipv6. 62
I'm searching backwards. There's disable ipv6, which disables ipv6 support, and by default the option 63
is not given or ipv6 is not disabled. 64
If you know you are not using ipv6, you can disable it using this option. 65
OK, I'm quitting less. 66
I'm running the configures script only with the prefix option. 67
--prefix=/opt/proftpd you can install it anywhere, but it's recommended 68
that programs that are compiled and are not controlled by the package manager to be installed in a directory 69
under /opt. Opt comes from optional software. 70
Also note that you don't have to create the proftpd directory by hand using mkdir, it will be created 71
automatically. 72
I'm hitting enter. See how it's checking 73
the environment; It's looking really nice, like in a hacker movie. 74
If you get any errors, solve them and run configure again. 75
Move to the next step 76
only when the configure script finishes without errors. The common errors are related to missing dependencies. 77
When you compile software by yourself 78
you have to take care of the dependencies as well. 79
We are waiting for it to finish. 80
There is no error, so I can go ahead with the next step; the next step is to run make. 81
This is the GNU utility that will build your application. 82
This means it will take a collection of source files and metadata and transform them into the final 83
product. 84
It does the real compilation by invoking the gcc compiler multiple times. To compile the program 85
make will use a file called Makefile that's in the current directory. 86
This is the makefile. 87
This fire was generated by configure at the prior step and contains details about how the final product 88
should be! I'm executing make! 89
See how make is invoking gcc behind the scenes multiple times. 90
If compilation encounters some problems, then the errors are thrown on the console; they are in general 91
fatal. 92
Try to solve them, run make clean and then make again. 93
I hope there will be no errors. 94
Great; once the compilation is done successfully, then all the required binaries are created. Run make 95
Run make install this time as root which is the final step 96
This will create the directory where the software will be installed, in this example, /opt 97
/proftpd and move all the files there. 98
And it's done! The FTP server was installed by compiling the sources and can be run. At this moment 99
the sources are not necessary anymore and I can remove them. 100
Let's move into the server's directory. 101
This directory contains everything related to the server 102
I've just compiled. There's no other file outside this directory. 103
So to remove the server, just remove this directory; let's start the server. 104
I’m moving to the sbin/ directory which resides in the server’s directory. 105
Take care not to move into/sbin, this is another directory. And the file named proftpd is actually 106
the server. 107
I'm starting the server by running the file as root. In Linux a server can be started only by root. 108
Normally, a server runs in the background is a daemon, so I'm adding an end at the end. 109
And sudo to run as root; the server has started. 110
We can search for the process by running ps -ef | grep proftpd 111
This is the process. 112
Or pgrep-l proftpd; it's the running to stop it run kill ad its process id 113
or pkill and its name, I'm stopping it. 114
And, of course, as root. 115
Let's search for the process again. 116
It's not ranning. 117
It was stopped. 118
The server was killed. 119
Note that you cannot control a server that was compiled using systemstl like you do for one that 120
was installed using the package manager. 121
You start it by running the executable and stop it by running the kill command. To test that 122
it works as expected 123
I'll start it in the foreground in debug mode, using the -n option. 124
When I want to stop it, I press control and C. 125
So sudo 126
./proftpd -n 127
The server started in the foreground; this is just for testing. Let's connect to the server using 128
an FTP client. 129
There are lots of good FTB clients out there FileZilla being across platform one. 130
However, for this simple test, I'll connect to the server using the browser. 131
I'm opening Firefox and I'm connecting to FTP :// double and the server's IP address localhost 132
and it's connected and asking for a username and password. 133
I'll enter a system username and password. 134
So student and its password and I'm hitting enter. 135
It has displayed the home directory of the user; it is working just fine. 136
The main purpose of this lecture was to show you how to compile standard applications, not to configure 137
the proftpd server. 138
But if you want to change the way the server works, you should know that this configuration file is 139
this one /opt/proftpd/etc proftpd.conf This is the configuration file of the server. 140
There were a lot of talks because I want you to deeply understand how to compile programs, but actually 141
we can do anything with only one command. 142
I'm downloading the server again. 143
I'm showing you the fast way. 144
The server source code. 145
I'm extracting the archive. 146
I'm moving to that to the directory and I'm running a single command configure --prefix= 147
opt/proftpd1 148
&& make 149
&& sudo make install 150
You should run all the commands as root or at least the last one, which is make install. And that 's all! 151
This is how you compile and install the server with only one command. 152
It will around the first command, which is configure, if it doesn't return any error, it will run, 153
the make command if make does not throw any error it will the run make install; if any command 154
in the chain returns an error, the next command will not be run. 155
OK, that was a standard compilation guide, which is applicable to most well-known applications. However, 156
there are applications that need to be compiled in a custom way. 157
In that case, you have to get the documentation of the program. 158
It is normally a file called Install or read me in the source directory.