Contents
1.Install Apache httpd 2.4
Install a web server (Apache2.4) to display the web site.
Installation Requirements
♦Use the latest version of Apache 2.4, 2.4.41
♦Install Apache in /usr/local/src (the standard installation directory as is customary for Linux when installing from source)
♦Installation directory for documents to be published on the Web /var/www/html/
♦Using Virtual Hosts
Before installing Apache, install the necessary libraries.
1.1 Install APR, APR-util, and expat-devel
①Install APR (latest version is 1.7.0)
1 2 3 4 5 6 7 8 |
# cd /usr/local/src # wget http://ftp.riken.jp/net/apache/apr/apr-1.7.0.tar.gz # tar -xvzf apr-1.7.0.tar.gz # cd apr-1.7.0 # ./configure --prefix=/opt/apr/apr-1.7.0 ← installation directory # make # make test # make install |
②Install APR-util (latest version is 1.6.1)
1 2 3 4 5 6 7 8 |
# cd /usr/local/src # wget http://ftp.jaist.ac.jp/pub/apache//apr/apr-util-1.6.1.tar.gz # tar -xvzf apr-util-1.6.1.tar.gz # cd apr-util-1.6.1 # ./configure --prefix=/opt/apr-util/apr-util-1.6.1 --with-apr=/opt/apr/apr-1.7.0 # make # make test # make install |
③Install expat-devel
When compiling apr-util 1.6.0, if you have not installed the "expat-devel" package, you may get the following error.
xml/apr_xml.lo -c xml/apr_xml.c && touch xml/apr_xml.lo
xml/apr_xml.c:35:19: fatal error: expat.h: There are no such files or directories.
#include <expat.h>
Stopped compiling.。 make[1]: *** [xml/apr_xml.lo] error 1
make[1]: directory`/usr/local/src/apr-util-1.6.0' It's coming from
make: *** [all-recursive] error 1
1 2 3 |
# cd /usr/local/src # wget http://mirror.centos.org/centos/7/os/x86_64/Packages/expat-devel-2.1.0-10.el7_3.x86_64.rpm # rpm -Uvh expat-devel-2.1.0-10.el7_3.x86_64.rpm |
1.2 Install Apache 2.4 (latest version is 2.4.41)
Downloading and Deploying Apache 2.4
1 2 3 |
# cd /usr/local/src # wget http://ftp.kddilabs.jp/infosystems/apache//httpd/httpd-2.4.41.tar.gz # tar -xvzf httpd-2.4.41.tar.gz |
Compiling and installing
1 2 3 4 5 6 7 8 9 10 11 |
# cd /usr/local/src/httpd-2.4.41 # ./configure \ --with-layout=Apache \ ← Where to install Apache --enable-module=auth_db \ ← Activate the required modules. --enable-module=so \ ← Activate the required modules. --enable-module=most \ ← Activate the required modules. --enable-mods-shared=reallyall \ ← Activate the required modules. --enable-rewrite \ ← Activate the required modules. --enable-auth_digest ← Activate the required modules. # make # make instal |
Typical Examples of Apache Compilation and Installation Options
Options for Apache Installation
Option | Details |
--with-layout=[F:]ID | Use the installation path layout ID obtained from file F |
--target=TARGET | Install the associated file using the name specified in TARGET |
--prefix=PREFIX | Install Apache (command) in the directory specified by PREFIX. |
--exec-prefix=EPREFIX | Install httpd (daemon) in the directory specified by EPREFIX. |
--bindir=DIR | Specify the bin directory by DIR |
--sbindir=DIR | Specify the sbin directory by DIR |
--libexecdir=DIR | Specify the libexec directory by DIR |
--mandir=DIR | Install man (manual) in the directory specified by DIR. |
--sysconfdir=DIR | Install the configuration file in the directory specified by DIR. |
--datadir=DIR | Install the data files in the directory specified by DIR. |
--iconsdir=DIR | Install the icon files in the directory specified by DIR. |
--htdocsdir=DIR | Set the directory specified by DIR as a document file (index to be published via http). |
--cgidir=DIR | Set the directory specified by DIR as the CGI directory. |
--includedir=DIR | Install the include files in the directory specified by DIR. |
--localstatedir=DIR | Install the modifiable data files in the directory specified by DIR |
--runtimedir=DIR | Install the runtime data in the directory specified by DIR. |
--logfiledir=DIR | Install the log file in the directory specified by DIR. |
--proxycachedir=DIR | Install the proxy cache data in the directory specified by DIR |
⑤Configuring Apache (editing httpd.conf)
Whole apache configuration
Range-specified configuration (per directory, file, path, etc.)
The range specification is done in a section container, and the settings outside the section container become the overall apache settings.
The following range of <Directory "/usr/local/apache2/htdocs">~</Directory> is the section container.
# Specify by directory -- <Directory>
# Specify by file -- <Files>
# Specify by path -- <Location>
# Load other configuration files -- Include
<Directory "/usr/local/apache2/htdocs">
# Setting contents
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# vi /usr/local/apache2/conf/httpd.conf Enable digest authentication LoadModule auth_digest_module modules/mod_auth_digest.soCGI Enable the module (uncomment it out) #LoadModule cgid_module modules/mod_cgid.so → LoadModule cgid_module modules/mod_cgid.so Change the document root (default setting is as shown in the following, but you can comment it out and continue with the default setting if you wish). # DocumentRoot "/usr/local/apache2/htdocs" ServerAdmin Email address ServerName host name Add an index file DirectoryIndex index.html index.htm index.php Virtual Host Configuration <VirtualHost *:80> ServerAdmin Email address ServerName FQDN DocumentRoot "/var/www/html/FQDN" ErrorLog /var/log/httpd/FQDN_error.log CustomLog /var/log/httpd/FQDN_access.log combined AddDefaultCharset UTF-8 <Directory "/var/www/html/FQDN/"> AllowOverride All Require all granted </Directory> </VirtualHost> Enable CGI scripts (uncomment them) #AddHandler cgi-script .cgi → Enable AddHandler cgi-script .cgi httpd-default.conf #Include conf/extra/httpd-default.conf → Include conf/extra/httpd-default.conf |
1 |
# mkdir -p /var/www/html/FQDN/ |
1 |
# systemctl enable httpd |
2.PHP7 Installation
2.1. Download and install the required libraries.
Download
1 2 3 4 5 6 7 |
# wget http://mirror.centos.org/centos/7/os/x86_64/Packages/xz-devel-5.2.2-1.el7.x86_64.rpm # wget http://mirror.centos.org/centos/7/os/x86_64/Packages/libxml2-devel-2.9.1-6.el7_2.3.x86_64.rpm # wget fftp://ftp.pbone.net/mirror/ftp.scientificlinux.org/linux/scientific/7.0/x86_64/updates/security/libjpeg-turbo-devel-1.2.90-6.el7.x86_64.rpm # wget http://mirror.centos.org/centos/7/os/x86_64/Packages/libpng-devel-1.5.13-7.el7_2.x86_64.rpm # wget http://mirror.centos.org/centos/7/os/x86_64/Packages/freetype-2.8-14.el7.x86_64.rpm # wget http://mirror.centos.org/centos/7/os/x86_64/Packages/freetype-devel-2.8-14.el7.x86_64.rpm # wget http://mirror.centos.org/centos/7/os/x86_64/Packages/libcurl-devel-7.29.0-54.el7.x86_64.rpm |
Install
1 |
# rpm -Uvh xz-devel-5.2.2-1.el7.x86_64.rpm libxml2-devel-2.9.1-6.el7_2.3.x86_64.rpm libjpeg-turbo-devel-1.2.90-6.el7.x86_64.rpm libpng-devel-1.5.13-7.el7_2.x86_64.rpm freetype-2.8-14.el7.x86_64.rpm freetype-devel-2.8-14.el7.x86_64.rpm libcurl-devel-7.29.0-54.el7.x86_64.rpm |
2.2 Download and install PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# wget https://www.php.net/distributions/php-7.3.6.tar.gz # tar zxvf php-7.3.6.tar.gz # cd php-7.3.6 # ./configure \ --prefix=/usr/local/php7 \ ← Where to install php7 --with-config-file-path=/usr/local/php7/etc \ ← Location of the php configuration file --with-apxs2=/usr/local/apache2/bin/apxs \ --enable-mbstring \ --enable-mbregex \ --with-gd \ --enable-gd-jis-conv \ --with-freetype-dir=/usr \ --with-png-dir=/usr \ --with-zlib \ --with-jpeg-dir=/usr \ --with-mysqli=mysqlnd \ --with-mysql-sock=/var/lib/mysql/mysql.sock \ --with-curl # make # make install |
2.3 Edit Apache configuration file to work with Apache
Associates the extension (.php) used in PHP with PHP. By registering, when a file with the extension (.php) is accessed, the result of the execution using PHP will be returned to the client. Put the following at the end of the "httpd.conf" file
2.4 Edit PHP configuration file
1 2 3 4 5 6 |
# vi /usr/local/etc/php.ini Add the following to the end extension=curl.so extension=openssl.so date.timezone = Asia/Tokyo |