Establish a virtual root environment for Apache in Linux and Solaris

Source: Internet
Author: User
Tags install perl
Article title: create a virtual root environment for Apache in Linux and Solaris. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Abstract: installing a virtual root-environment Apache Directory tree on Linux is quite simple. This example uses Red Hat 6. * and Apache 1.3.12. It also contains PHP4 (as an Apache module) and perl5 installation on the virtual root environment directory tree. In addition, mod-ssl and mod-perl are installed.
  
Introduction
  
?? I used CERN httpd to install and use a Web server in a virtual root environment. Creating a virtual root environment for Web servers has various advantages and disadvantages. In the early stages of Web development, this technology also provides additional valuable security mechanisms. However, in this apache field, this technology does not seem very useful, but it is still very interesting.
  
?? I provide an example of installing a virtual root environment for apache in linux and soloris. it can be used for standard editing (marked as non-DSO when necessary) or edit the dynamic shared object (it will be marked as DSO if necessary ). The Solaris example with the option DSO is not documented, so I didn't test it (I plan to use Solaris 8 during the test ).
  
?? Installing a virtual root-environment Apache Directory tree on Linux is quite simple. This example uses Red Hat 6. * and Apache 1.3.12. It also contains PHP4 (as an Apache module) and perl5 installation on the virtual root environment directory tree. In addition, mod-ssl and mod-perl are installed.
  
?? This example also assumes that the installation of Red Hat is complete (that is, there are enough files, libraries and development tools ). Note: If you use the develm (prefered) configuration and select the development option when installing Red Hat, or you use the server configuration, you will all have a complete development environment.
  
?? Mysql3.22.27 is not installed in the directory tree that implements the virtual root environment, but we include it here for integrity.
  
Statement
  
?? I am not an expert :), especially in terms of encryption (openssl, mod-ssl, and company), my level is even more limited. I am also an ordinary person and will make mistakes. Therefore, if you find anything or have any constructive comments, please let me know.
  
?? I am writing this article just hoping that you can learn something and get some help. I can also provide some RPMs frequently, but if you know that you can create your own modern Web site from a sketch, it will be more interesting. However, on the current Internet, it is up to you to learn and understand various problems and risks related to running a Web site.
  
Solaris example
?? Solaris, which implements virtual root environment for the Web directory tree, is similar to Linux. Of course, if you have not installed the GNU development environment, the solaris example cannot be as easy as the Linux example.
  
?? The Solaris example document is on another Web page.
  
Additional comments
  
Use the tool ldd to discover necessary shared libraries.
In this example, the user prompts:
Root user:
ROOT #
Ordinary user:
$
  
Basically, I compile and install various software as a common user rather than a root user. This helps avoid unnecessary damages to the file system, especially when unfamiliar software is used. This also helps to warn you before performing dangerous operations, such as the "setuid" operation on the installed binary file, and warnings before dangerous operations such as installation of files in unusual places.
In this example, I use soft: soft as a user to compile and install software.
  
In fact, you only need to ensure that the ID of the software owner is different from that of the Apache Directory tree user (in this example, we use 888.
  
In Red Hat's default root environment, an interactive switch-I is added to the command cp, mv, and rm. If you do not have these settings in your root environment, we recommend that you add them. You can check the following files:
  
ROOT # alias | grep '-I'
Alias cp = 'CP-I'
Alias mv = 'MV-I'
Alias rm = 'rm-I'
  
You should make your configuration as simple as possible-do not install modules that are useless or unnecessary at all. Generally, a standard non-DSO (non-dynamic shared object) Apache is sufficient for most people to install perl.
Notes about DSO and mod-ssl:
If you want to compile everything according to the DSO template, you must first establish mod-ssl, and then you must create your own Apache Directory tree in the following order. Mod-ssl will obviously modify the directory tree created by Apache. in my experience, the following sequence is the simplest when we use the software version we just mentioned:
  
Create Apache
Create and add mod-ssl in Apache
Create and add php and mod-perl in Apache.
You should record in a proper place how you compile your directory tree for reference. (You can print it out and add comments)
After installing various software, the final virtual root environment directory tree contains 23 MB, including 8 MB shared libraries and perl. The following is a summary of the DSO-based files (expressed in KB ):
ROOT # pwd
/Www
ROOT # du-s.
22737.
ROOT # du-s *
6832 ?? Apache
0 ?? Bin
1 ?? Dev
7 ?? Etc
6679 ?? Lib
1 ?? Tmp
9215 ?? Usr
1 ?? Webhome
ROOT # du-s apache /*
600 ?? Apache/bin
3 ?? Apache/cgi-bin
125 ?? Apache/conf
1560 ?? Apache/htdocs
133 ?? Apache/icons
392 ?? Apache/include
3925 ?? Apache/libexec
64 ?? Apache/man
29 ?? Apache/var
ROOT # du-s usr /*
8410 ?? Usr/Local
336 ?? Usr/bin
340 ?? Usr/lib
128 ?? Usr/share
1. obtain the source code
  
?? If you want to add a package to your virtual root-environment directory tree, you must obtain the source code of any file in the package. (This method is suitable for scenarios with limited bandwidth ).
  
?? In the Red Hat system, you install Source as the root user:
  
?? ROOT # rpm-I/path/to/SRPMfile. src. rpm
  
?? Then, extract the source code from the/usr/src/redhat/SOURCES/directory.
  
?? In our example, I will point out where you can obtain the source code on the Internet:
  
?? Software package ???? Version ???????? Source code ?????????? Document Information
?? Apache ??? 1.3.12 ???? Www.apache.org/dist /????? Www.apache.org/docs/
?? MySQL ???? 3.22.27 ??? Www.mysql.com/downloads ??? Www.mysql.com/documentation/
?? PHP ????? 4.0.2 ????? Www.php.net/downloads.php ?? Www.php.net/docs.php
?? Perl ???? 5.00503 ??? Www.cpan.org/src /?????? Www.cpan.org/doc/manual/html/index.html
?? Mod_perl ?? 1.24 ????? Perl.apache.org/dist /???? Perl.apache.org/?docs
?? Hello. pm ?????????????????????????? Perl.apache.org/dist/contrib/
?? Mod_ssl ?? 2.6.6-1.3.12 ftp://ftp.modssl.org/source? Www.modssl.org/docs/2.6/
?? OpenSSL ?? 0.9.5a ???? Ftp://ftp.openssl.org/source? Www.openssl.org/support/faq.html
?? RSAref ??? 2.0 ?????? Google search ????????? Google search
  
2. step details
  
?? Prepare a virtual root environment file system
  
2.1 install the directory tree anywhere
  
?? Note: it is best to install it on another disk or on a non-system partition. This will prevent other users from establishing connections to files outside the Web directory tree, but you can use symlink (for example: /www) connection to find this directory tree.
  
?? ROOT # mkdir/export/misc/www
?? ROOT # ln-s/export/misc/www
  
2.2 generate the basic directory. bin will be the connection of usr/bin.
  
?? Note: In these examples (except for the code I copied directly from a general file system), I have omitted the leading "/". therefore, be sure not to confuse your virtual root-environment directory tree with the real.
  
?? Below I will mark the virtual root environment file in Red
  
?? ROOT # cd/www
?? ROOT # mkdir-p usr/bin usr/lib etc tmp dev webhome
?? ROOT # ln-s usr/bin
  
2.3/tmp is assumed dedicated perms
  
?? ROOT # chmod 777 tmp
?? ROOT # chmod + t tmp
  
2.4 Construct special device dev/null
  
?? ROOT # mknod-m 666 dev/null c 1 3
  
2.5 set the time zone information for your own time zone (MET is used here)
  
?? ROOT # mkdir-p usr/share/zoneinfo
?? ROOT # cp-pi/usr/share/zoneinfo/MET usr/share/zoneinfo/
?? ROOT # cd etc
?? ROOT # ln-s ../usr/share/zoneinfo/MET localtime
?? ROOT # cd ..
  
2.6 you will find that perl and mod-perl are inconvenient due to the lack of local settings, but you can overcome it by installing local files in the directory tree that implements the virtual root environment:
  
?? ROOT # set | grep LANG
?? LANG = en_US
?? ROOT # mkdir/www/usr/share/locale
?? ROOT # cp-a/usr/share/locale/en_US/www/usr/share/locale/
  
2.7 now, the shared libraries of file systems that provide a very basic virtual root environment
  
?? ROOT # cp-pi/lib/libtermcap. so.2/lib/ld-linux.so.2/lib/libc. so.6 lib/
  
2.8 test your directory tree ("cat" will be used after Apachect1, but it is not required)
  
?? ROOT # cp-pi/bin/ls/bin/sh/bin/cat bin/
?? ROOT # chroot/www/bin/ls-l/
  
?? Lrwxrwxrwx 1 0 ???? 0 ?????
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.