Excellent software and practical tutorials
apache(Apache) official website:http://httpd.apache.org/
The Apache HTTP Server Project is pleased to announce the release of version 2.4.41 of the Apache HTTP Server ("Apache" and " httpd”). This version of Apache is the latest GA release of the new generation 2.4.x branch of Apache HTTPD, representing fifteen years of innovation in the project, and is therefore recommended over all previous versions!
First download the stable version - the latest version 2.4.41, which was released on 2019-08-14. As of March 2020, this version is the latest version!
wget https://downloads.apache.org//httpd/httpd-2.4.41.tar.gz tar xvf httpd-2.4.41.tar.gz cd httpd-2.4.41
After downloading, do not install blindly. 2.4.41 requires the installation of some dependent environments. The following are the installation requirements provided by the official website.
The following requirements are needed to install Apache httpd:
1. APR and APR-Util
Make sure you have APR and APR-Util installed on your system. If you do not, or would rather not use the system-provided versions, download both APR and APR-Util from the latest version of Apache APR, unpack them into /httpd_source_tree_root/srclib/apr and /httpd_source_tree_root/srclib/apr-util (make sure the directory names do not have version numbers; for example, the APR distribution must be under /httpd_source_tree_root/srclib/apr/), and use the --with-included-apr option of ./configure. On some platforms, you may have to install the corresponding -dev packages to allow httpd to build against the installed copies of APR and APR-Util.
2. Perl Compatible Regular Expression Library (PCRE)
This library is required but is no longer bundled with httpd. Download the source from http://www.pcre.org, or install a port or package. If your build system cannot find the pcre-config script installed by the PCRE build, point to it with the --with-pcre argument. On some platforms you may have to install the corresponding -dev package to allow httpd to build against an installed copy of PCRE.
3. Disk Space
Make sure you have at least 50 MB of temporary disk space available. After installation, the server takes up approximately 10 MB of disk space. Actual disk space requirements will vary greatly depending on the configuration options you choose, any third-party modules, and the size of the website or websites on your server.
4.ANSI-C Compiler and Build System
Make sure you have an ANSI-C compiler installed. The GNU C Compiler (GCC) from the Free Software Foundation (FSF) is recommended. If you don't have GCC, at least make sure the vendor's compiler is ANSI compliant. In addition, your PATH must contain basic build tools such as make.
5. Accurate timing
Elements of the HTTP protocol are expressed as the time of day. Therefore, it is time to look into setting up some time synchronization capabilities on your system. This is usually done using the ntpdate or xntpd programs based on the Network Time Protocol (NTP). For more details on NTP software and public time servers, see the NTP home page.
6. Perl 5 [optional]
For some support scripts, such as apxs or dbmmanage (which are written in Perl), a Perl 5 interpreter is required (version 5.003 or higher is sufficient). If the configure script does not find a Perl 5 interpreter, the affected support scripts will not be used. You will, of course, still be able to build and use Apache httpd.
First install OpenSSL:
wget https://www.openssl.org/source/openssl-1.0.2m.tar.gz tar xvf openssl-1.0.2m.tar.gz cd openssl-1.0.2m ./config --prefix=/usr/local/ssl --shared make make install echo /usr/local/ssl/lib >> /etc/ld.so.conf ldconfig
Install Apache 2.4.41:
The download sites for APR and APR-Util are:http://apr.apache.org/download.cgi
Download the two packages to the srclib directory of the apache installation directory. First enter the srclib directory. After downloading, rename them and remove the version number to apr and apr-util
cd srclib wget https://downloads.apache.org//apr/apr-1.7.0.tar.gz wget https://downloads.apache.org//apr/apr-util-1.6.1.tar.gz tar xvf apr-1.7.0.tar.gz tar xvf apr-util-1.6.1.tar.gz mv apr-1.7.0 apr mv apr-util-1.6.1 apr-util cd\
After changing the name, exit the folder and cd into the installation file of httpd-2.4.41 again to install it. If you encounter an error message, the dependency environment is missing. Before installation, you need to install other dependency environments with yum
sudo yum -y install pcre-devel expat-devel libxml2-devel
After the environment is installed, you can configure it. It is installed by default, and no parameters need to be changed. After the default installation, the installation directory is /usr/local/apache2
cd httpd-2.4.41 ./configure --prefix=/usr/local/apache2 --enable-so --enable-rewrite --enable-ssl --with-ssl=/usr/local/ssl --with-mpm=prefork make make install
--prefix specifies the installation path
--enable-so enables the Apache core to load DSO (Dynamic Shared Object)
--enable-rewrite Enable rewrite function
--enable-modules compile modules into apache
--enable-ssl turns on the SSL protocol
--with-mpm specifies the running model
There are three operating modes:
1. Multi-process model: prefork
2. Multi-process and multi-threaded hybrid model: worker
3. Multi-process and multi-threaded hybrid model: event
Configure parameter explanation:
--prefix=/usr/local/apache2 | Specify the Apache installation path |
--enable-so | This supports dynamic sharing modules |
--enable-rewrite | Support URL rewriting |
--enable-ssl | Support SSL |
--with-ssl=/usr/local/openssl | This specifies the installation location of openssl |
--enable-cgi | Enable CGI |
--enable-modules=most | Indicates the modules to be statically compiled into the httpd binary file, all or most, where all means all modules and most means most modules |
--enable-mods-shared=most | Indicates the modules to be compiled in DSO mode, all means all, most means most |
--enable-mpms-shared=all | Enable all supported modes of MPM, so that event, worker, and prefork will be installed in a modular way. You can configure which one to use in httpd.conf |
--with-mpm=event | Specifies to enable mpm mode. By default, enevt mode is used. In the early version of Apache, 2.0 uses prefork by default, 2.2 uses worker, and 2.4 uses event. |
--with-pcre=/usr/local/pcre | Support PCRE |
--with-z=/usr/local/zlib | Using the zlib compression library |
--with-apr=/usr/local/apr | Specify the installation path of apr |
--with-apr-util=/usr/local/apr-util | Specify the installation path of apr-util |
--enable-expires | Activate and control the HTTP "Expires:" and "Cache-Control:" header content through the configuration file, that is, provide client browser cache settings for website images, js, css, etc. This is one of the important options for apache tuning. |
--enable-deflate | Provides support for compressed transmission encoding of content, generally for sites with html, js, css and other content. Using this parameter will greatly increase the transmission speed and improve the visitor's experience. In a production environment, this is one of the important options for apache tuning |
If the openssl version is too low when installing apache2.4, you still need to install openssl.
OpenSSL official website:https://www.openssl.org/
When installing openssl, you need to bring the --enable-shared parameter. The --enable-shared parameter is added to add openssl to the shared library of lib or lib64, otherwise Apache will not be able to find openssl.
Well, Apache 2.4.41 has been installed. The next step is to set up the post-installation settings of Apache 2.4.41.
cd /usr/local/apache2 ls -l cd conf ls -l vi httpd.conf
Edit apache2's configuration file httpd.conf
Change both User and Group to www, then save and exit.
If the www user group and user are not created on this machine, you need to create them.
groupadd www useradd -g www www
Change the user group permissions for the website directory.
chown -R www www /var/www/html
For more detailed configuration information about httpd.conf, please visit:Centos7Detailed interpretation of Apache2.4's httpd.conf configuration file
Add httpd system service
ln -s /usr/local/apache2.4/bin/apachectl /etc/rc.d/init.d/httpd
Off topic: Manual installation is still very troublesome compared to yum installation. Manual installation is not recommended. Uninstallation requires deleting directories one by one, and startup also requires configuration scripts. Manual installation is just to let you understand the installation process.
Set apache2.4.41 to start at boot
Centos7 and below users
vi /etc/rc.d/rc.local
Add the following content to the end of the file, save and exit!
/usr/local/apache2/bin/apachectl start
Add execution permissions to the startup file
chmod +x /etc/rc.d/rc.local
reboot Restart the server! Apache is installed.
Centos7x users can create a new apache startup file, open a non-existent file with VI, and use :wq to save and exit, and the file will be created.
vi /usr/lib/systemd/system/httpd.service
Copy the following content into the httpd.service file
[Unit] Description=The Apache HTTP Server After=network.target remote-fs.target nss-lookup.target Documentation=man:httpd(8) Documentation=man:apachectl(8) [Service] Type=forking #EnvironmentFile=/etc/sysconfig/httpd ExecStart=/usr/local/apache2/bin/httpd $OPTIONS -k start ExecReload=/usr/local/apache2/bin/httpd $OPTIONS -k graceful ExecStop=/bin/kill -WINCH {MAINPID} KillSignal=SIGCONT PrivateTmp=true [Install] WantedBy=multi-user.target
Reload the startup file and then start apache2.4.41
systemctl daemon-reload systemctl start httpd
Use the status command to see if it is started normally!
systemctl status httpd
Now when you open the IP address of your computer, the Apache welcome page will be displayed on the web page! Congratulations, you have successfully installed Apache2.4.41!
"It works!"