has been engaged in client software development on Windows, often dealing with business related to server interactions. As I wanted to be a full-stack engineer, I was increasingly interested in server-related development on Linux. I can do some technical research on this piece while I have more free time at the end of the year. Although the knowledge is very basic and very old, but it is very interesting for new people like me.
The initial goal is to enable the service in the virtual machine to be successful, and the physical machine can access it. Server I chose the relatively familiar point of the Ubuntu--ubuntu server 14.04.1 LTS 32-bit version (HTTP://RELEASES.UBUNTU.COM/14.04.1/ ubuntu-14.04.1-desktop-i386.iso.torrent). And the service I choose the famous Apache. (reprint please indicate CSDN blog for breaksoftware)
Easy installation Apache
I first install Apache on the software source on the virtual machine's Ubuntu. For simplicity, I used the Tasksel command directly.
Open the Software Configuration interface
Then use the space to select Lamp Server. Use Enter to confirm the selection, which will automatically install the relevant software-including Apache. After installation, use service httpd start to start the HTTP service. This way I can use IP to access the service on the physical machine.
But here's a question, we always visit a static page. In reality, the HTTP server implements more and more complex functions. For example, our daily use of the log service, the general need to parse the URL, and some parameters to do related operations into the database. Obviously such a requirement is not sufficient for a static page.
Compiling Apache
As a well-known service software, to get such a market share, there must be a lot of advantages. One of the advantages must be that its framework is good-and it can be imagined that its framework must be "open to expansion". Otherwise add a little demand, you have to read and modify the Apache source code, will undoubtedly greatly improve the user's difficulty, there will not be so many users. So we want to be able to deal with the simple requirements of URL parsing, and certainly also through the way plug-ins such as the implementation. However, we compile a plug-in, generally need to rely on some libraries-the software comes with libraries, software associated libraries ... So in order not to omit such a library, we need to build an environment--can fully compile the Apache source of the environment--even Apache can compile, then its most basic functions of plug-ins can certainly be compiled.
Download Apache source code from http://httpd.apache.org/download.cgi. This version of 2.4.12 is currently in use. After we get the package, we unzip it into the/USR/SRC directory.
wget http://mirrors.cnnic.cn/apache//httpd/httpd-2.4.12.tar.gztar XVFZ httpd-2.4.12.tar.gz-c/usr/src
We cut into the unzip directory and execute
./configure
We have found that if the environment is not perfect, the APR and Apr-util and pcre libraries will be reported missing.
ARP Library official website:http://apr.apache.org/
wget http://mirror.bit.edu.cn/apache//apr/apr-1.5.1.tar.gztar XVFZ apr-1.5.1.tar.gz-c/usr/src./configure--prefix= /usr/local/aprmakemake Install
Arp-util Library Website:http://apr.apache.org/
wget Http://mirror.bit.edu.cn/apache//apr/apr-util-1.5.4.tar.gztar XVFZ apr-util-1.5.4.tar.gz-c/USR/SRCMV Apr-util-1.5.4/usr/src/./configure--prefix=/usr/local/apr-util--with-apr=/usr/local/aprmakemake Install
Pcre Library official website: http://pcre.org/
wget Ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.36.tar.gztar XVFZ pcre-8.36.tar.gz-c/usr/src./ Configure--prefix=/usr/local/pcremakemake Install
OpenSSL Library
Official website: http://www.openssl.org/source/
Because the HTTPS module will use encryption and other methods, so we need to pull OpenSSL. The Ubuntu system appears to have a library file with OpenSSL. But when we write the plug-in, we use its header file, so we also pull it and compile it.
wget Http://www.openssl.org/source/openssl-1.0.2.tar.gztar XVFZ openssl-1.0.2.tar.gz./config--prefix=/usr/local/ Opensslmakemake Install
When these libraries are ready, we'll go to Apache's decompression directory and execute the./configure (you may need to specify the path to a partial library):/configure There are a lot of parameters to choose from, I'm not here to explain. Because our pre-goal is to build success--it works.
If we have previously installed Apache in the source, then uninstall it--apt-get remove Apache2.
After a long compilation, Apache was finally compiled. But things can not be smooth sailing, I run the executable file httpd, will be reported libpcre.so.1 (64-bit system as if it is reported libpcre.so.0) not found (using LLD httpd to view the file association). Fortunately this problem can not find the file is good to solve:
To start Apache:
Using ifconfig to view IP, we enter IP in the host computer's browser. We will get the following results:
So far, our compiled Apache has run. The environment for compiling the plug-in is also ready.
compiling, adding plugins
There is a axps file in the./bin directory that was compiled by Apache. Its full name is: APache eXtenSion tool. As the name implies, it is a helper tool to help us build the extension (for ease of use, we have to place the directory in the environment variable vim/etc/environment; source/etc/environment). It's very simple to use, for example, we're going to build a plugin called Hello World. Then we use
APXS-G-N Hello_world
Where-G is the indicator APXS generates a template project,-n is used to specify the project name. These two parameters are generally used in a piece.
Then we can compile the module and register the module with the Apache configuration.
Apxs-c-i-a MOD_HELLO_WORLD.C
Compilation success will occur
The-C directive instructs the compilation project; the-i directive instructs the compiled module to be copied to the Apache modules directory (mod_hello_world.so). The-a instruction instructs to modify the Apache configuration file httpd.conf, allowing the module to load the process to load this so.
In general,-C is used alone. -i-a are used in combination, and they can be omitted, as it simply copies the files and modifies the configuration, and we may not need to copy so into the Apache modules directory for development, but only modify the httpd.conf to indicate the path of the so. For example: I added the following line in Conf
We'll come back and see what the logic of the module--MOD_HELLO_WORLD.C
Now we don't read the file, but we have a rough idea of the following points:
- Our request will be related to the Hello_world field.
- We're going to use a specific set of APIs to manipulate internal logic--like the Ap_rpus function.
In this file comment section, tell us to manually modify the httpd.conf file, add the following
This part of the configuration what role, we do not go into this section.
After all, we restarted Apache ——./httpd-k restart.
On the physical machine access
We have interfered with the results of the server's return and completed our initial goal. Later in the chapter, we will examine in detail if you are writing more complex plugins.
Reference information:
Http://wiki.ubuntu.org.cn/Apache
Http://httpd.apache.org/docs/2.4/install.html
Http://httpd.apache.org/docs/2.4/programs/configure.html
Http://httpd.apache.org/docs/2.4/en/programs/apxs.html
Server Setup notes--compiling Apache and its plugins