Contents
Installa apache2 and virtual host configuration
1.Install apache2
①Download httpd-2.4.39
1 2 |
# cd /usr/local/src # wget http://archive.apache.org/dist/httpd/httpd-2.4.39.tar.gz |
➁Extracting the Apache tar file
1 |
# tar zxvf httpd-2.4.39.tar.gz |
➂Download and extract apr and apr-util
1 2 3 4 5 6 |
# wget https://archive.apache.org/dist/apr/apr-1.6.3.tar.gz # wget https://archive.apache.org/dist/apr/apr-util-1.6.1.tar.gz # tar zxvf apr-1.6.3.tar.gz # tar zxvf apr-util-1.6.1.tar.gz # mv apr-1.6.3 httpd-2.4.39/srclib/apr # mv apr-util-1.6.1 httpd-2.4.39/srclib/apr-util |
④Install expat-devel
1 2 3 4 5 6 |
# wget https://github.com/libexpat/libexpat/releases/download/R_2_2_7/expat-2.2.7.tar.gz # tar xvfz expat-2.2.7.tar.gz # cd expat-2.2.7 # ./configure --prefix=/usr/local/expat/2_2_7 # make # make install |
⑤Create an expat symbolic link
Create a symbolic link to the installed library under "/usr/local".
Create a symbolic link to the installed library under "/usr/local".
※ /usr/local/bin
1 |
# ln -s /usr/local/expat/2_2_7/bin/xmlwf /usr/local/bin/ |
※ /usr/local/include
1 2 3 |
# ln -s /usr/local/expat/2_2_7/include/expat.h /usr/local/include/ ln -s /usr/local/expat/2_2_7/include/expat_config.h /usr/local/include/ ln -s /usr/local/expat/2_2_7/include/expat_external.h /usr/local/include/ |
※ /usr/local/lib
1 2 3 4 5 |
# ln -s /usr/local/expat/2_2_7/lib/libexpat.a /usr/local/lib/ ln -s /usr/local/expat/2_2_7/lib/libexpat.la /usr/local/lib/ ln -s /usr/local/expat/2_2_7/lib/libexpat.so /usr/local/lib/ ln -s /usr/local/expat/2_2_7/lib/libexpat.so.1 /usr/local/lib/ ln -s /usr/local/expat/2_2_7/lib/libexpat.so.1.6.9 /usr/local/lib/ |
⑥Install PCRE
1 2 3 4 5 6 7 |
# cd /usr/local/src # wget https://ja.osdn.net/projects/sfnet_pcre/downloads/pcre/8.45/pcre-8.45.tar.gz # tar xvfz pcre-8.45.tar.gz # cd pcre-8.45 # ./configure --prefix=/usr/local/pcre/8_45 --enable-jit # make # make install |
⑦Create a symbolic link
Create a symbolic link to the installed library under "/usr/local".
Create a symbolic link to the installed library under "/usr/local".
※ /usr/local/bin
1 2 3 |
# ln -s /usr/local/pcre/8_45/bin/pcre-config /usr/local/bin/ ln -s /usr/local/pcre/8_45/bin/pcregrep /usr/local/bin/ ln -s /usr/local/pcre/8_45/bin/pcretest /usr/local/bin/ |
※ /usr/local/include
1 2 3 4 5 6 |
# ln -s /usr/local/pcre/8_45/include/pcre.h /usr/local/include/ ln -s /usr/local/pcre/8_45/include/pcre_scanner.h /usr/local/include/ ln -s /usr/local/pcre/8_45/include/pcre_stringpiece.h /usr/local/include/ ln -s /usr/local/pcre/8_45/include/pcrecpp.h /usr/local/include/ ln -s /usr/local/pcre/8_45/include/pcrecpparg.h /usr/local/include/ ln -s /usr/local/pcre/8_45/include/pcreposix.h /usr/local/include/ |
※ /usr/local/lib
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# ln -s /usr/local/pcre/8_45/lib/libpcre.a /usr/local/lib/ ln -s /usr/local/pcre/8_45/lib/libpcre.la /usr/local/lib/ ln -s /usr/local/pcre/8_45/lib/libpcre.so /usr/local/lib/ ln -s /usr/local/pcre/8_45/lib/libpcre.so.1 /usr/local/lib/ ln -s /usr/local/pcre/8_45/lib/libpcre.so.1.2.11 /usr/local/lib/ ln -s /usr/local/pcre/8_45/lib/libpcrecpp.a /usr/local/lib/ ln -s /usr/local/pcre/8_45/lib/libpcrecpp.la /usr/local/lib/ ln -s /usr/local/pcre/8_45/lib/libpcrecpp.so /usr/local/lib/ ln -s /usr/local/pcre/8_45/lib/libpcrecpp.so.0 /usr/local/lib/ ln -s /usr/local/pcre/8_45/lib/libpcrecpp.so.0.0.1 /usr/local/lib/ ln -s /usr/local/pcre/8_45/lib/libpcreposix.a /usr/local/lib/ ln -s /usr/local/pcre/8_45/lib/libpcreposix.la /usr/local/lib/ ln -s /usr/local/pcre/8_45/lib/libpcreposix.so /usr/local/lib/ ln -s /usr/local/pcre/8_45/lib/libpcreposix.so.0 /usr/local/lib/ ln -s /usr/local/pcre/8_45/lib/libpcreposix.so.0.0.6 /usr/local/lib/ |
⑧Run configure, compile, and install
1 2 3 4 5 6 7 8 9 10 11 |
# cd ../httpd-2.4.39 # ./configure \ --with-layout=Apache \ --enable-module=auth_db \ --enable-module=so \ --enable-module=most \ --enable-mods-shared=reallyall \ --enable-rewrite \ --enable-auth_digest # make # make install |
2.Configure Apache
①Edit the httpd.conf file
1 |
# cp /usr/local/apache2/conf/httpd.conf /usr/local/apache2/conf/httpd.conf_bak |
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 38 39 |
# vi /usr/local/apache2/conf/httpd.conf ●Per line 83 Enable digest authentication 「LoadModule auth_digest_module modules/mod_auth_digest.so」Remove the "#" from the beginning of the line ●Per line 170 Enable the CGI module. 「LoadModule cgid_module modules/mod_cgid.so」Remove the "#" from the beginning of the line ●Per line 228 Change ServerName Add "ServerName [host name]" under "#ServerName www.example.com:80". ●Per line 251 Change the document root 「DocumentRoot "/usr/local/apache2/htdocs"」Type "#" at the beginning of the line to comment it out ●Per line 279 Add the following <VirtualHost *:80> ServerAdmin <Administrator email address> DocumentRoot /var/www/html/<FQDN>/ ←I'm using the domain name for clarity. ServerName <FQDN> ErrorLog "| /usr/local/apache2/bin/rotatelogs /var/log/httpd/<FQDN>_error_log_%Y%m%d 86400 540" CustomLog "| /usr/local/apache2/bin/rotatelogs /var/log/httpd/<FQDN >_access_log_%Y%m%d 86400 540" combined ErrorDocument 404 / </VirtualHost> <Directory "/var/www/html/<FQDN>"> Options Indexes Includes FollowSymLinks MultiViews ExecCGI Require all granted Allow from all AddHandler server-parsed .html </Directory> ●Per line298 Add an index file Add "index.htm index.php". <IfModule dir_module> DirectoryIndex index.html index.htm index.php </IfModule> ●Per line316 Change the error_log output directory 「ErrorLog "logs/error_log"」Add "#" at the beginning and add "ErrorLog "/var/log/httpd/error_log"" below it #ErrorLog "logs/error_log" ErrorLog "/var/log/httpd/error_log" ●Per line345 Comment out the log settings. #CustomLog "logs/access_log" common ●Per line445 「AddHandler cgi-script .cgi」Remove the "#" from the beginning of the line ●Per line532 Enable httpd-default.conf 「Include conf/extra/httpd-default.conf」Remove the "#" from the beginning of the line |
②Edit the httpd-default.conf file
1 2 3 |
# vi /usr/local/apache2/conf/extra/httpd-default.conf ●Per line10 Change the timeout period. Timeout 300 |
③Create the necessary directories.
1 2 |
# mkdir -p /var/www/html/<FQDN>/ # mkdir /var/log/httpd |
④Directory owner and permissions to display the web site.
1 2 |
# chown -R <user>:<user> /var/www/ # chmod 755 /var/www/html/<FQDN>/ |
⑤Auto-start configuration for Apache
1 2 |
# cd /lib/systemd/system/ # vi httpd.service |
Contents of httpd.service
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
[Unit] Description=The Apache HTTP Server After=network.target remote-fs.target nss-lookup.target [Service] Type = forking ExecStart=/usr/local/apache2/bin/apachectl start ExecStop=/usr/local/apache2/bin/apachectl stop # We want systemd to give httpd some time to finish gracefully, but still want # it to kill httpd after TimeoutStopSec if something went wrong during the # graceful stop. Normally, Systemd sends SIGTERM signal right after the # ExecStop, which would kill httpd. We are sending useless SIGCONT here to give # httpd time to finish. KillSignal=SIGCONT PrivateTmp=true [Install] WantedBy=multi-user.target |
⑥Apache Autostart Configuration and Startup
1 2 |
# systemctl enable httpd.service Created symlink from /etc/systemd/system/multi -user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service. |
1 |
# systemctl start httpd.service |
⑦Checking the operation of Apache
Open ports with firewalld
Open ports with firewalld
1 2 3 |
# firewall-cmd --permanent --add-service=http # firewall-cmd --permanent --add-service=https # firewall-cmd --reload |
In your browser, go to http://<domain>.
If you see "Index of /", it's OK.
If you see "Index of /", it's OK.
Installation and configuration of PHP ( PHP-7.3.6 )
1.advance preparation
Install the software needed to install PHP
1 2 3 4 5 |
# dnf -y install xz-devel libxml2-devel # dnf -y install libjpeg-turbo-devel # dnf -y install libpng-devel # dnf -y install freetype freetype-devel # dnf -y install libcurl-devel |
2.Install PHP
①Install
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# cd /usr/local/src # wget https://www.php.net/distributions/php-7.3.6.tar.gz (# wget --no-check-certificate 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 \ --with-config-file-path=/usr/local/php7/etc \ --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 |
②Editing Apache configuration files
1 2 3 |
# vi /usr/local/apache2/conf/httpd.conf ●Per line188 Add "AddType application/x-httpd-php .php" under "LoadModule php7_module modules/libphp7.so". |
③Edit the PHP configuration file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# cp php.ini-development /usr/local/php7/etc/php.ini # vi /usr/local/php7/etc/php.ini ●Per line401 Change "memory_limit = 128M" to "memory_limit = 512M" ●Per line474 Change "display_errors = On" to "display_errors = Off". ●Per line686 Change "post_max_size = 8M" to "post_max_size = 128M". ●Per line838 Change "upload_max_filesize = 2M" to "upload_max_filesize = 2000M". ●Per 941 Add "extension=curl.so" and "extension=openssl.so". ;extension=xsl extension=curl.so extension=openssl.so ●Per line954 Add "date.timezone = Asia/Tokyo" ;date.timezone = date.timezone = Asia/Tokyo |
④ Generating the curl.so file
1 2 3 4 5 6 7 8 9 |
# cd /usr/local/src/php-7.3.6/ext/curl/ # /usr/local/php7/bin/phpize # ./configure --with-curl -with-php-config=/usr/local/php7/bin/php-config # make # make install # ls -l /usr/local/php7/lib/php/extensions/no-debug-zts-20180731/ total 3356 -rwxr-xr-x 1 root root 517720 Feb 3 19:49 curl.so -rwxr-xr-x 1 root root 2913912 Feb 3 19:42 opcache.so |
⑤Checking the operation of PHP
Create the following file
Create the following file
1 2 |
# vi /var/www/html/<FQDN>/test.php <?php phpinfo(); ?> |
Restart Apache
1 |
# systemctl restart httpd.service |