Installer H2O-webserveren på CentOS 7

H2O er en ny generation af HTTP-server, der har en fantastisk, fuldt udstyret HTTP/2-implementering af alle de nuværende webservere, der er i brug. Med H2O som din webserver kan du drage fordel af de nye funktioner i HTTP/2-specifikationen, såsom latency-optimering, server-push og server-side prioritering, der kan drage fordel af moderne browser-funktioner, der sjældent tales om.

I denne detaljerede vejledning viser jeg dig trin for trin, hvordan du får H2O til at køre på din CentOS 7 x64-instans.

Forudsætninger

  • En CentOS 7 x64-serverinstans.
  • En sudo- bruger.
  • Et SSL-certifikat (valgfrit)

Trin 1: Opdater systemet

Log ind via SSH med de legitimationsoplysninger, der findes under din instans, og opdater systemet som følger.

sudo yum install epel-release -y
sudo yum clean all && sudo yum update -y

Trin 2: Installer H2O

For at installere H2O på CentOS 7 skal du tilføje Bintray RPM-lageret for at installere de forudbyggede H2O-binære filer. Brug Nano-editoren til at oprette en brugerdefineret repo.

sudo nano /etc/yum.repos.d/bintray-h2o-rpm.repo

Kopiér og indsæt teksten nedenfor i repo-filen.

[bintray-h2o-rpm]
name=bintray-h2o-rpm
baseurl=https://dl.bintray.com/tatsushid/h2o-rpm/centos/$releasever/$basearch/
gpgcheck=0
repo_gpgcheck=0
enabled=1

Installer derefter H2O.

sudo yum install h2o -y

Nu hvor H2O er installeret, men før du aktiverer og starter tjenesten, kræves en korrekt konfiguration, og vi skal oprette en specifik bruger og gruppe, som H2O kan køre under. Opret en gruppe og bruger, som H2O kan køre under navnet h2o.

sudo groupadd -g 101 h2o
sudo useradd -d /etc/h2o -g 101 -M -s /sbin/nologin -u 101 h2o

Trin 3: Konfiguration af H2O-webserveren

De følgende trin vil give eksempler på konfigurationsopsætninger for forskellige unencrypted, encrypted, staticog dynamicserveropsætninger; samt en kombination af alle fire.


Omdiriger http://www.example.comtil http://example.com(statiske HTML-sider, ingen PHP) konfiguration

Naviger til /etc/h2o/biblioteket.

cd /etc/h2o/

Omdøb standarden h2o.conftil h2o.conf.original.

sudo mv h2o.conf h2o.conf.original

Opret en ny h2o.conffil.

sudo nano h2o.conf

Kopier og indsæt teksten nedenfor i h2o.conffilen.

access-log: /var/log/h2o/access.log
compress: ON
error-log: /var/log/h2o/error.log
expires: 1 day
file.index: [ 'index.html' ]
hosts:
  "example.com:80":
    listen:
      port: 80
    paths:
      "/":
        file.dir: /var/www/example.com
  "www.example.com:80":
    listen:
      port: 80
    paths:
      "/":
        redirect:
          status: 301
          url: "http://example.com/"
pid-file: /var/run/h2o/h2o.pid
send-server-name: OFF
setenv:
  HTTP_PROXY: ""
user: h2o

Aktiver og start H2O-serveren.

sudo systemctl enable h2o
sudo systemctl start h2o

Opret en standard index.htmlved hjælp af skabelonen i /var/www/htmlbiblioteksindstillingen file.dirovenfor i /var/www/example.com.

sudo cp -var /var/www/html /var/www/example.com

Åbn nu din browser og indtast serverens domænenavn ( example.comeller www.example.com) for din forekomst. Får du en Unable to connecteller en This site can’t be reachedbesked? CentOS' standard firewall-indstilling tillader ikke indgående forbindelser til http-porten. Udfør følgende for at åbne den.

sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --reload

Opdater siden i din browser ( F5), og du vil få denne besked.


Welcome to H2O - an optimized HTTP server

It works!

Omdiriger http://example.comtil http://www.example.com(statiske HTML-sider, ingen PHP) konfiguration

Naviger til /etc/h2o/biblioteket.

cd /etc/h2o/

Omdøb standarden h2o.conftil h2o.conf.original.

sudo mv h2o.conf h2o.conf.original

Opret en ny h2o.conffil.

sudo nano h2o.conf

Kopier og indsæt følgende tekst i h2o.conffilen.

access-log: /var/log/h2o/access.log
compress: ON
error-log: /var/log/h2o/error.log
expires: 1 day
file.index: [ 'index.html' ]
hosts:
  "example.com:80":
    listen:
      port: 80
    paths:
      "/":
        redirect:
          status: 301
          url: "http://www.example.com/"
  "www.example.com:80":
    listen:
      port: 80
    paths:
      "/":
        file.dir: /var/www/www.example.com
pid-file: /var/run/h2o/h2o.pid
send-server-name: OFF
setenv:
  HTTP_PROXY: ""
user: h2o

Aktiver og start H2O-serveren.

sudo systemctl enable h2o
sudo systemctl start h2o

Opret en standardfil index.htmlved hjælp af skabelonen i /var/www/htmlden mappeindstilling, der er file.dirangivet ovenfor i /var/www/www.example.com.

sudo cp -var /var/www/html /var/www/www.example.com

Åbn nu din browser og indtast serverens domænenavn ( example.comeller www.example.com) for din forekomst. Får du en Unable to connecteller en This site can’t be reachedbesked? CentOS' standard firewall-indstilling tillader ikke indgående forbindelser til http-porten. Gør følgende for at åbne den.

sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --reload

Opdater siden i din browser ( F5), og du vil få denne besked.


Welcome to H2O - an optimized HTTP server

It works!

Omdiriger http://www.example.comtil http://example.com(dynamisk side, PHP-FPM 5.6.x) konfiguration

Naviger til /etc/h2o/biblioteket.

cd /etc/h2o/

Omdøb standarden h2o.conftil h2o.conf.original.

sudo mv h2o.conf h2o.conf.original

Opret en ny h2o.conffil.

sudo nano h2o.conf

Kopier og indsæt følgende tekst i h2o.conffilen.

access-log: /var/log/h2o/access.log
compress: ON
error-log: /var/log/h2o/error.log
expires: 1 day
file.index: [ 'index.php' ]
hosts:
  "example.com:80":
    listen:
      port: 80
    paths:
      "/":
        file.dir: /var/www/example.com
        redirect:
          internal: YES
          status: 307
          url: /index.php
  "www.example.com:80":
    listen:
      port: 80
    paths:
      "/":
        redirect:
          status: 301
          url: "http://example.com/"
file.custom-handler:
  extension: .php
  fastcgi.connect:
    port: /run/php-fpm-5.6.sock
    type: unix
pid-file: /var/run/h2o/h2o.pid
send-server-name: OFF
setenv:
  HTTP_PROXY: ""
user: h2o

In order to process PHP, the PHP-FPM 5.6 daemon must be installed and configured. In order to install a version of PHP-FPM newer than the default 5.4.x, the REMI repo must be installed which contains PHP versions 5.6.x, 7.0.x and 7.1.x. Install PHP version 5.6.x.

sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y
sudo yum install php56-php-fpm -y

Navigate to the /opt/remi/php56/root/etc/ directory.

cd /opt/remi/php56/root/etc/

Rename the default php-fpm.conf to php-fpm.conf.original.

sudo mv php-fpm.conf php-fpm.conf.original

Create a new php-fpm.conf file.

sudo nano php-fpm.conf

Copy and paste the text below into the php-fpm.conf file.

include=/opt/remi/php56/root/etc/php-fpm.d/*.conf
[global]
daemonize = yes
emergency_restart_threshold = 2
emergency_restart_interval = 1m
error_log = /var/log/php-fpm/php-fpm-5.6-error.log
pid = /var/run/php-fpm-5.6.pid
process_control_timeout = 10s

Rename the default www.conf file in the php-fpm.d directory.

sudo mv php-fpm.d/www.conf php-fpm.d/www.conf.original

Create a new www.conf file.

sudo nano php-fpm.d/www.conf

Copy and paste the text below into the www.conf file. Change your pm.max\_children to match the number of CPUs in accordance with your VPS instance.

[www]
group = h2o
listen = /var/run/php-fpm-5.6.sock
listen.backlog = 65536
listen.owner = h2o
listen.group = h2o
pm = static
pm.max_children = 2
pm.max_requests = 10240
user = h2o

Rename the default php.ini file.

sudo mv php.ini php.ini.original

Create a new php.ini file.

sudo nano php.ini

Copy and paste the text below into the new php.ini file. Change the memory\_limit, post\_max\_size, upload\_max\_filesize and date.timezone in accordance with your VPS instance.

[PHP]
allow_url_fopen = On
always_populate_raw_post_data = -1
display_errors = Off
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
expose_php = Off
log_errors = On
memory_limit = 256M
output_buffering = 4096
post_max_size = 64M
register_argc_argv = Off
request_order = "GP"
upload_max_filesize = 64M
variables_order = "GPCS"
[Date]
date.timezone = America/New_York
[Session]
session.cache_limiter =
session.gc_divisor = 1000
session.hash_bits_per_character = 5
session.save_handler = files
session.save_path = "/opt/remi/php56/root/var/lib/php/session/"
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"

Change the group ownership for the /opt/remi/php56/root/var/lib/php/session/ directory from the apache group to the h2o group.

sudo chown root.h2o /opt/remi/php56/root/var/lib/php/session/

Create a directory where the PHP-FPM server logs will reside.

sudo mkdir /var/log/php-fpm/

Enable and start the PHP-FPM server.

sudo systemctl enable php56-php-fpm 
sudo systemctl start php56-php-fpm

Enable and start the H2O server.

sudo systemctl enable h2o
sudo systemctl start h2o

Create a directory where the default index.php will reside listed by the directory option file.dir above in /var/www/example.com.

sudo mkdir /var/www/example.com

Create a default index.php using the phpinfo command to test PHP.

sudo nano /var/www/example.com/index.php

Copy and paste the text below in the new index.php file.

<?php
phpinfo();
?>

Now, open your browser and enter the server domain name (example.com or www.example.com) for your instance. Are you getting an Unable to connect or a This site can’t be reached message? CentOS's default firewall setting disallows incoming connections to the http port. Do the following to open it.

sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --reload

Refresh the page in your browser (F5) and you will get the standard PHP info page.


Redirect http://example.com To http://www.example.com (Dynamic Page, PHP-FPM 5.6.x) Configuration

Navigate to the /etc/h2o/ directory.

cd /etc/h2o/

Rename the default h2o.conf to h2o.conf.original.

sudo mv h2o.conf h2o.conf.original

Create a new h2o.conf file.

sudo nano h2o.conf

Copy and paste the text below into the h2o.conf file.

access-log: /var/log/h2o/access.log
compress: ON
error-log: /var/log/h2o/error.log
expires: 1 day
file.index: [ 'index.php' ]
hosts:
  "example.com:80":
    listen:
      port: 80
    paths:
      "/":
        redirect:
          status: 301
          url: "http://www.example.com/"
  "www.example.com:80":
    listen:
      port: 80
    paths:
      "/":
        file.dir: /var/www/www.example.com
        redirect:
          internal: YES
          status: 307
          url: /index.php
file.custom-handler:
  extension: .php
  fastcgi.connect:
    port: /run/php-fpm-5.6.sock
    type: unix
pid-file: /var/run/h2o/h2o.pid
send-server-name: OFF
setenv:
  HTTP_PROXY: ""
user: h2o

In order to process PHP, the PHP-FPM 5.6 daemon must be installed and configured. In order to install a version of PHP-FPM newer than the default 5.4.x, the REMI repo must be installed which contains PHP versions 5.6.x, 7.0.x and 7.1.x. Type the following commands to install PHP version 5.6.x.

sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y
sudo yum install php56-php-fpm -y

Navigate to the /opt/remi/php56/root/etc/ directory.

cd /opt/remi/php56/root/etc/

Rename the default php-fpm.conf to php-fpm.conf.original.

sudo mv php-fpm.conf php-fpm.conf.original

Create a new php-fpm.conf file.

sudo nano php-fpm.conf

Copy and paste the text below into the php-fpm.conf file.

include=/opt/remi/php56/root/etc/php-fpm.d/*.conf
[global]
daemonize = yes
emergency_restart_threshold = 2
emergency_restart_interval = 1m
error_log = /var/log/php-fpm/php-fpm-5.6-error.log
pid = /var/run/php-fpm-5.6.pid
process_control_timeout = 10s

Rename the default www.conf file in the php-fpm.d directory.

sudo mv php-fpm.d/www.conf php-fpm.d/www.conf.original

Create a new www.conf file.

sudo nano php-fpm.d/www.conf

Copy and paste the following text into the www.conf file. Change your pm.max\_children to match the number of CPUs in accordance with your VPS instance.

[www]
group = h2o
listen = /var/run/php-fpm-5.6.sock
listen.backlog = 65536
listen.owner = h2o
listen.group = h2o
pm = static
pm.max_children = 2
pm.max_requests = 10240
user = h2o

Rename the default php.ini file.

sudo mv php.ini php.ini.original

Create a new php.ini file.

sudo nano php.ini

Copy and paste the following text below into the new php.ini file. Change the memory\_limit, post\_max\_size, upload\_max\_filesize and date.timezone in accordance with your VPS instance.

[PHP]
allow_url_fopen = On
always_populate_raw_post_data = -1
display_errors = Off
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
expose_php = Off
log_errors = On
memory_limit = 256M
output_buffering = 4096
post_max_size = 64M
register_argc_argv = Off
request_order = "GP"
upload_max_filesize = 64M
variables_order = "GPCS"
[Date]
date.timezone = America/New_York
[Session]
session.cache_limiter =
session.gc_divisor = 1000
session.hash_bits_per_character = 5
session.save_handler = files
session.save_path = "/opt/remi/php56/root/var/lib/php/session/"
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"

Change the group ownership for the /opt/remi/php56/root/var/lib/php/session/ directory from the apache group to the h2o group.

sudo chown root.h2o /opt/remi/php56/root/var/lib/php/session/

Create a directory where the PHP-FPM server logs will reside.

sudo mkdir /var/log/php-fpm/

Enable and start the PHP-FPM server.

sudo systemctl enable php56-php-fpm 
sudo systemctl start php56-php-fpm

Enable and start the H2O server.

sudo systemctl enable h2o
sudo systemctl start h2o

Create a directory where the default index.php will reside listed by the directory option file.dir above in /var/www/www.example.com.

sudo mkdir /var/www/www.example.com

Create a default index.php using the phpinfo command to test PHP.

sudo nano /var/www/www.example.com/index.php

Copy and paste the text below in the new index.php file.

<?php
phpinfo();
?>

Now, open your browser and enter the server domain name (example.com or www.example.com) for your instance. Are you getting an Unable to connect or a This site can’t be reached message? CentOS's default firewall setting disallows incoming connections to the http port. Do the following to open it.

sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --reload

Refresh the page in your browser (F5) and you will get the standard PHP info page.


Redirect http://www.example.com To http://example.com (Dynamic Page, PHP-FPM 7.1.x) Configuration

Navigate to the /etc/h2o/ directory.

cd /etc/h2o/

Rename the default h2o.conf to h2o.conf.original.

sudo mv h2o.conf h2o.conf.original

Create a new h2o.conf file.

sudo nano h2o.conf

Copy and paste the text below into the h2o.conf file.

access-log: /var/log/h2o/access.log
compress: ON
error-log: /var/log/h2o/error.log
expires: 1 day
file.index: [ 'index.php' ]
hosts:
  "example.com:80":
    listen:
      port: 80
    paths:
      "/":
        file.dir: /var/www/example.com
        redirect:
          internal: YES
          status: 307
          url: /index.php
  "www.example.com:80":
    listen:
      port: 80
    paths:
      "/":
        redirect:
          status: 301
          url: "http://example.com/"
file.custom-handler:
  extension: .php
  fastcgi.connect:
    port: /run/php-fpm-7.1.sock
    type: unix
pid-file: /var/run/h2o/h2o.pid
send-server-name: OFF
setenv:
  HTTP_PROXY: ""
user: h2o

In order to process PHP, the PHP-FPM 7.1 daemon must be installed and configured. In order to install a version of PHP-FPM newer than the default 5.4.x, the REMI repo must be installed which contains PHP versions 5.6.x, 7.0.x and 7.1.x. Type the following commands below to install PHP version 7.1.x.

sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y
sudo yum install php71-php-fpm -y

Navigate to the /etc/opt/remi/php71/ directory.

cd /etc/opt/remi/php71/

Rename the default php-fpm.conf to php-fpm.conf.original.

sudo mv php-fpm.conf php-fpm.conf.original

Create a new php-fpm.conf file.

sudo nano php-fpm.conf

Copy and paste the following text into the php-fpm.conf file.

include=/etc/opt/remi/php71/php-fpm.d/*.conf
[global]
daemonize = yes
emergency_restart_threshold = 2
emergency_restart_interval = 1m
error_log = /var/log/php-fpm/php-fpm-7.1-error.log
pid = /var/run/php-fpm-7.1.pid
process_control_timeout = 10s

Rename the default www.conf file in the php-fpm.d directory.

sudo mv php-fpm.d/www.conf php-fpm.d/www.conf.original

Create a new www.conf file.

sudo nano php-fpm.d/www.conf

Copy and paste the text below into the www.conf file. Change your pm.max\_children to match the number of CPUs in accordance with your VPS instance.

[www]
group = h2o
listen = /var/run/php-fpm-7.1.sock
listen.backlog = 65536
listen.owner = h2o
listen.group = h2o
pm = static
pm.max_children = 2
pm.max_requests = 10240
user = h2o

Rename the default php.ini file.

sudo mv php.ini php.ini.original

Create a new php.ini file.

sudo nano php.ini

Copy and paste the text below into the new php.ini file. Change the memory\_limit, post\_max\_size, upload\_max\_filesize and date.timezone in accordance with your VPS instance.

[PHP]
allow_url_fopen = On
always_populate_raw_post_data = -1
display_errors = Off
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
expose_php = Off
log_errors = On
memory_limit = 256M
output_buffering = 4096
post_max_size = 64M
register_argc_argv = Off
request_order = "GP"
upload_max_filesize = 64M
variables_order = "GPCS"
[Date]
date.timezone = America/New_York
[Session]
session.cache_limiter =
session.gc_divisor = 1000
session.hash_bits_per_character = 5
session.save_handler = files
session.save_path = "/var/opt/remi/php71/lib/php/session/"
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"

Change the group ownership for the /var/opt/remi/php71/lib/php/session/ directory from the apache group to the h2o group.

sudo chown root.h2o /var/opt/remi/php71/lib/php/session/

Create a directory where the PHP-FPM server logs will reside.

sudo mkdir /var/log/php-fpm/

Enable and start the PHP-FPM server.

sudo systemctl enable php71-php-fpm 
sudo systemctl start php71-php-fpm

Enable and start the H2O server.

sudo systemctl enable h2o
sudo systemctl start h2o

Create a directory where the default index.php will reside listed by the directory option file.dir above in /var/www/example.com.

sudo mkdir /var/www/example.com

Create a default index.php using the phpinfo command to test PHP.

sudo nano /var/www/example.com/index.php

Copy and paste the text below in the new index.php file.

<?php
phpinfo();
?>

Now, open your browser and enter the server domain name (example.com or www.example.com) for your instance. Are you getting an Unable to connect or a This site can’t be reached message? CentOS's default firewall setting disallows incoming connections to the http port. Do the following to open it.

sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --reload

Refresh the page in your browser (F5) and you will get the standard PHP info page.


Redirect http://example.com To http://www.example.com (Dynamic Page, PHP-FPM 7.1.x) Configuration

Navigate to the /etc/h2o/ directory.

cd /etc/h2o/

Rename the default h2o.conf to h2o.conf.original.

sudo mv h2o.conf h2o.conf.original

Create a new h2o.conf file.

sudo nano h2o.conf

Copy and paste the text below into the h2o.conf file.

access-log: /var/log/h2o/access.log
compress: ON
error-log: /var/log/h2o/error.log
expires: 1 day
file.index: [ 'index.php' ]
hosts:
  "example.com:80":
    listen:
      port: 80
    paths:
      "/":
        redirect:
          status: 301
          url: "http://www.example.com/"
  "www.example.com:80":
    listen:
      port: 80
    paths:
      "/":
        file.dir: /var/www/www.example.com
        redirect:
          internal: YES
          status: 307
          url: /index.php
file.custom-handler:
  extension: .php
  fastcgi.connect:
    port: /run/php-fpm-7.1.sock
    type: unix
pid-file: /var/run/h2o/h2o.pid
send-server-name: OFF
setenv:
  HTTP_PROXY: ""
user: h2o

In order to process PHP, the PHP-FPM 7.1 daemon must be installed and configured. In order to install a version of PHP-FPM newer than the default 5.4.x, the REMI repo must be installed which contains PHP versions 5.6.x, 7.0.x and 7.1.x. Type the following commands below to install PHP version 7.1.x.

sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y
sudo yum install php71-php-fpm -y

Navigate to the /etc/opt/remi/php71/ directory.

cd /etc/opt/remi/php71/

Rename the default php-fpm.conf to php-fpm.conf.original.

sudo mv php-fpm.conf php-fpm.conf.original

Create a new php-fpm.conf file.

sudo nano php-fpm.conf

Copy and paste the text below into the php-fpm.conf file.

include=/etc/opt/remi/php71/php-fpm.d/*.conf
[global]
daemonize = yes
emergency_restart_threshold = 2
emergency_restart_interval = 1m
error_log = /var/log/php-fpm/php-fpm-7.1-error.log
pid = /var/run/php-fpm-7.1.pid
process_control_timeout = 10s

Rename the default www.conf file in the php-fpm.d directory.

sudo mv php-fpm.d/www.conf php-fpm.d/www.conf.original

Create a new www.conf file.

sudo nano php-fpm.d/www.conf

Copy and paste the following text into the www.conf file. Change your pm.max\_children to match the number of CPUs in accordance with your VPS instance.

[www]
group = h2o
listen = /var/run/php-fpm-7.1.sock
listen.backlog = 65536
listen.owner = h2o
listen.group = h2o
pm = static
pm.max_children = 2
pm.max_requests = 10240
user = h2o

Rename the default php.ini file.

sudo mv php.ini php.ini.original

Create a new php.ini file.

sudo nano php.ini

Copy and paste the following text into the new php.ini file. Change the memory\_limit, post\_max\_size, upload\_max\_filesize and date.timezone in accordance with your VPS instance.

[PHP]
allow_url_fopen = On
always_populate_raw_post_data = -1
display_errors = Off
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
expose_php = Off
log_errors = On
memory_limit = 256M
output_buffering = 4096
post_max_size = 64M
register_argc_argv = Off
request_order = "GP"
upload_max_filesize = 64M
variables_order = "GPCS"
[Date]
date.timezone = America/New_York
[Session]
session.cache_limiter =
session.gc_divisor = 1000
session.hash_bits_per_character = 5
session.save_handler = files
session.save_path = "/var/opt/remi/php71/lib/php/session"
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"

Change the group ownership for the /var/opt/remi/php71/lib/php/session/ directory from the apache group to the h2o group.

sudo chown root.h2o /var/opt/remi/php71/lib/php/session/

Create a directory where the PHP-FPM server logs will reside.

sudo mkdir /var/log/php-fpm/

Enable and start the PHP-FPM server.

sudo systemctl enable php71-php-fpm 
sudo systemctl start php71-php-fpm

Enable and start the H2O server.

sudo systemctl enable h2o
sudo systemctl start h2o

Create a directory where the default index.php will reside listed by the directory option file.dir above in /var/www/example.com.

sudo mkdir /var/www/www.example.com

Create a default index.php using the phpinfo command to test PHP.

sudo nano /var/www/www.example.com/index.php

Copy and paste the text below in the new index.php file.

<?php
phpinfo();
?>

Now, open your browser and enter the server domain name (example.com or www.example.com) for your instance. Are you getting an Unable to connect or a This site can’t be reached message? CentOS's default firewall setting disallows incoming connections to the http port. Do the following to open it.

sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --reload

Refresh the page in your browser (F5) and you will get the standard PHP info page.


Redirect http://example.com, http://www.example.com, and https://www.example.com to https://example.com (Static HTML Pages, No PHP) Configuration

Navigate to the /etc/h2o/ directory.

cd /etc/h2o/

Rename the default h2o.conf to h2o.conf.original.

sudo mv h2o.conf h2o.conf.original

Create a new h2o.conf file.

sudo nano h2o.conf

Copy and paste the text below into the h2o.conf file.

access-log: /var/log/h2o/access.log
compress: ON
error-log: /var/log/h2o/error.log
expires: 1 day
file.index: [ 'index.html' ]
hosts:
  "example.com:80":
    listen:
      port: 80
    paths:
      "/":
        redirect:
          status: 301
          url: "https://example.com/"
  "www.example.com:80":
    listen:
      port: 80
    paths:
      "/":
        redirect:
          status: 301
          url: "https://www.example.com/"
  "example.com:443":
    listen:
      port: 443
      ssl:
        <<: !file /etc/h2o/conf.d/ssl.conf
        certificate-file: /location/of/certificate/file/fullchain.ext
        key-file: /location/of/private/key/file/privkey.ext
    paths:
      "/":
        file.dir: /var/www/example.com
        header.add: "strict-transport-security: max-age=31536000; includeSubDomains; preload"
  "www.example.com:443":
    listen:
      port: 443
      ssl:
        <<: !file /etc/h2o/conf.d/ssl.conf
        certificate-file: /location/of/certificate/file/fullchain.ext
        key-file: /location/of/private/key/file/privkey.ext
    paths:
      "/":
        header.add: "strict-transport-security: max-age=31536000; includeSubDomains; preload"
        redirect:
          status: 301
          url: "https://example.com/"
pid-file: /var/run/h2o/h2o.pid
send-server-name: OFF
setenv:
  HTTP_PROXY: ""
user: h2o

Create a custom directory to store the default SSL options for all websites that use SSL.

sudo mkdir conf.d

Create a new ssl.conf file.

sudo nano conf.d/ssl.conf

Copy and paste the following text into the ssl.conf file.

cipher-preference: server
cipher-suite: ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256
dh-file: /etc/ssl/h2o/dhparam_2048.pem

Make a directory to store the dhparam_2048.pem file that will be regenerated daily via a cronjob.

sudo mkdir /etc/ssl/h2o/

Create a new regenerate_dhparam file.

sudo nano /etc/cron.daily/regenerate_dhparam

Copy and paste the following text into the regenerate_dhparam file.

#!/bin/bash
cd /etc/ssl/h2o
umask 022
for length in 2048
do
openssl dhparam -out dhparam_$length.tmp $length && mv dhparam_$length.tmp dhparam_$length.pem
chmod 444 dhparam_$length.pem
done

Make the bash file just created executable.

sudo chmod +x /etc/cron.daily/regenerate_dhparam

Execute the bash script for a first run as H2O won't start properly if it's not generated. This will take about a minute or two to generate on first run.

sudo /etc/cron.daily/regenerate_dhparam

Enable and start the H2O server.

sudo systemctl enable h2o
sudo systemctl start h2o

Create a default index.html using the template in /var/www/html to the directory option file.dir listed above in /var/www/example.com.

sudo cp -var /var/www/html /var/www/example.com

Now, open your browser and enter the server domain name (example.com or www.example.com) for your instance. Are you getting an Unable to connect or a This site can’t be reached message? CentOS's default firewall setting disallows incoming connections to the http port. Do the following to open it.

sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload

Refresh the page in your browser (F5) and you will get this message.


Welcome to H2O - an optimized HTTP server

It works!

Redirect http://example.com, http://www.example.com, and https://example.com to https://www.example.com (Static HTML Pages, No PHP) Configuration

Navigate to the /etc/h2o/ directory.

cd /etc/h2o/

Rename the default h2o.conf to h2o.conf.original.

sudo mv h2o.conf h2o.conf.original

Create a new h2o.conf file.

sudo nano h2o.conf

Copy and paste the text below into the h2o.conf file.

access-log: /var/log/h2o/access.log
compress: ON
error-log: /var/log/h2o/error.log
expires: 1 day
file.index: [ 'index.html' ]
hosts:
  "example.com:80":
    listen:
      port: 80
    paths:
      "/":
        redirect:
          status: 301
          url: "https://example.com/"
  "www.example.com:80":
    listen:
      port: 80
    paths:
      "/":
        redirect:
          status: 301
          url: "https://www.example.com/"
  "example.com:443":
    listen:
      port: 443
      ssl:
        <<: !file /etc/h2o/conf.d/ssl.conf
        certificate-file: /location/of/certificate/file/fullchain.ext
        key-file: /location/of/private/key/file/privkey.ext
    paths:
      "/":
        header.add: "strict-transport-security: max-age=31536000; includeSubDomains; preload"
        redirect:
          status: 301
          url: "https://www.example.com/"
  "www.example.com:443":
    listen:
      port: 443
      ssl:
        <<: !file /etc/h2o/conf.d/ssl.conf
        certificate-file: /location/of/certificate/file/fullchain.ext
        key-file: /location/of/private/key/file/privkey.ext
    paths:
      "/":
        file.dir: /var/www/www.example.com
        header.add: "strict-transport-security: max-age=31536000; includeSubDomains; preload"
pid-file: /var/run/h2o/h2o.pid
send-server-name: OFF
setenv:
  HTTP_PROXY: ""
user: h2o

Create a custom directory to store the default SSL options for all websites that use SSL.

sudo mkdir conf.d

Create a new ssl.conf file.

sudo nano conf.d/ssl.conf

Copy and paste the following text into the ssl.conf file.

cipher-preference: server
cipher-suite: ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256
dh-file: /etc/ssl/h2o/dhparam_2048.pem

Make a directory to store the dhparam_2048.pem file that will be regenerated daily via a cronjob.

sudo mkdir /etc/ssl/h2o/

Create a new regenerate_dhparam file.

sudo nano /etc/cron.daily/regenerate_dhparam

Copy and paste the following text inside of the regenerate_dhparam file.

#!/bin/bash
cd /etc/ssl/h2o
umask 022
for length in 2048
do
openssl dhparam -out dhparam_$length.tmp $length && mv dhparam_$length.tmp dhparam_$length.pem
chmod 444 dhparam_$length.pem
done

Make the bash file just created executable.

sudo chmod +x /etc/cron.daily/regenerate_dhparam

Execute the bash script for a first run as H2O won't start properly if it's not generated. This will take about a minute or two to generate on first run.

sudo /etc/cron.daily/regenerate_dhparam

Enable and start the H2O server.

sudo systemctl enable h2o
sudo systemctl start h2o

Create a default index.html using the template in /var/www/html to the directory option file.dir listed above in /var/www/www.example.com.

sudo cp -var /var/www/html /var/www/www.example.com

Now, open your browser and enter the server domain name (example.com or www.example.com) for your instance. Are you getting an Unable to connect or a This site can’t be reached message? CentOS's default firewall setting disallows incoming connections to the http port. Do the following to open it.

sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload

Refresh the page in your browser (F5) and you will get this message.


Welcome to H2O - an optimized HTTP server

It works!

Redirect http://example.com, http://www.example.com, and https://www.example.com to https://example.com (Dynamic Page, PHP-FPM 5.6.x) Configuration

Navigate to the /etc/h2o/ directory.

cd /etc/h2o/

Rename the default h2o.conf to h2o.conf.original.

sudo mv h2o.conf h2o.conf.original

Create a new h2o.conf file.

sudo nano h2o.conf

Copy and paste the text below into the h2o.conf file.

access-log: /var/log/h2o/access.log
compress: ON
error-log: /var/log/h2o/error.log
expires: 1 day
file.index: [ 'index.php' ]
hosts:
  "example.com:80":
    listen:
      port: 80
    paths:
      "/":
        redirect:
          status: 301
          url: "https://example.com/"
  "www.example.com:80":
    listen:
      port: 80
    paths:
      "/":
        redirect:
          status: 301
          url: "https://www.example.com/"
  "example.com:443":
    listen:
      port: 443
      ssl:
        <<: !file /etc/h2o/conf.d/ssl.conf
        certificate-file: /location/of/certificate/file/fullchain.ext
        key-file: /location/of/private/key/file/privkey.ext
    paths:
      "/":
        file.dir: /var/www/example.com
        header.add: "strict-transport-security: max-age=31536000; includeSubDomains; preload"
        redirect:
          internal: YES
          status: 307
          url: /index.php
  "www.example.com:443":
    listen:
      port: 443
      ssl:
        <<: !file /etc/h2o/conf.d/ssl.conf
        certificate-file: /location/of/certificate/file/fullchain.ext
        key-file: /location/of/private/key/file/privkey.ext
    paths:
      "/":
        header.add: "strict-transport-security: max-age=31536000; includeSubDomains; preload"
        redirect:
          status: 301
          url: "https://example.com/"
file.custom-handler:
  extension: .php
  fastcgi.connect:
    port: /run/php-fpm-5.6.sock
    type: unix
pid-file: /var/run/h2o/h2o.pid
send-server-name: OFF
setenv:
  HTTP_PROXY: ""
user: h2o

Create a custom directory to store the default SSL options for all websites that use SSL.

sudo mkdir conf.d

Create a new ssl.conf file.

sudo nano conf.d/ssl.conf

Copy and paste the text below into the ssl.conf file.

cipher-preference: server
cipher-suite: ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256
dh-file: /etc/ssl/h2o/dhparam_2048.pem

Make a directory to store the dhparam_2048.pem file that will be regenerated daily via a cronjob.

sudo mkdir /etc/ssl/h2o/

Create a new regenerate_dhparam file.

sudo nano /etc/cron.daily/regenerate_dhparam

Copy and paste the following text inside of the regenerate_dhparam file.

#!/bin/bash
cd /etc/ssl/h2o
umask 022
for length in 2048
do
openssl dhparam -out dhparam_$length.tmp $length && mv dhparam_$length.tmp dhparam_$length.pem
chmod 444 dhparam_$length.pem
done

Make the bash file just created executable.

sudo chmod +x /etc/cron.daily/regenerate_dhparam

Execute the bash script for a first run as H2O won't start properly if it's not generated. This will take about a minute or two to generate on first run.

sudo /etc/cron.daily/regenerate_dhparam

In order to process PHP, the PHP-FPM 5.6 daemon must be installed and configured. In order to install a version of PHP-FPM newer than the default 5.4.x, the REMI repo must be installed which contains PHP versions 5.6.x, 7.0.x and 7.1.x. Type the following commands to install PHP version 5.6.x.

sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y
sudo yum install php56-php-fpm -y

Navigate to the /opt/remi/php56/root/etc/ directory.

cd /opt/remi/php56/root/etc/

Rename the default php-fpm.conf to php-fpm.conf.original.

sudo mv php-fpm.conf php-fpm.conf.original

Create a new php-fpm.conf file.

sudo nano php-fpm.conf

Copy and paste the following text into the php-fpm.conf file.

include=/opt/remi/php56/root/etc/php-fpm.d/*.conf
[global]
daemonize = yes
emergency_restart_threshold = 2
emergency_restart_interval = 1m
error_log = /var/log/php-fpm/php-fpm-5.6-error.log
pid = /var/run/php-fpm-5.6.pid
process_control_timeout = 10s

Rename the default www.conf file in the php-fpm.d directory.

sudo mv php-fpm.d/www.conf php-fpm.d/www.conf.original

Create a new www.conf file.

sudo nano php-fpm.d/www.conf

Copy and paste the text below into the www.conf file. Change your pm.max\_children to match the number of CPUs in accordance with your VPS instance.

[www]
group = h2o
listen = /var/run/php-fpm-5.6.sock
listen.backlog = 65536
listen.owner = h2o
listen.group = h2o
pm = static
pm.max_children = 2
pm.max_requests = 10240
user = h2o

Rename the default php.ini file.

sudo mv php.ini php.ini.original

Create a new php.ini file.

sudo nano php.ini

Copy and paste the text below into the new php.ini file. Change the memory\_limit, post\_max\_size, upload\_max\_filesize and date.timezone in accordance with your VPS instance.

[PHP]
allow_url_fopen = On
always_populate_raw_post_data = -1
display_errors = Off
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
expose_php = Off
log_errors = On
memory_limit = 256M
output_buffering = 4096
post_max_size = 64M
register_argc_argv = Off
request_order = "GP"
upload_max_filesize = 64M
variables_order = "GPCS"
[Date]
date.timezone = America/New_York
[Session]
session.cache_limiter =
session.gc_divisor = 1000
session.hash_bits_per_character = 5
session.save_handler = files
session.save_path = "/opt/remi/php56/root/var/lib/php/session/"
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"

Change the group ownership for the /opt/remi/php56/root/var/lib/php/session/ directory from the apache group to the h2o group.

sudo chown root.h2o /opt/remi/php56/root/var/lib/php/session/

Create a directory where the PHP-FPM server logs will reside.

sudo mkdir /var/log/php-fpm/

Enable and start the PHP-FPM server.

sudo systemctl enable php56-php-fpm 
sudo systemctl start php56-php-fpm

Enable and start the H2O server.

sudo systemctl enable h2o
sudo systemctl start h2o

Create a directory where the default index.php will reside listed by the directory option file.dir above in /var/www/example.com.

sudo mkdir /var/www/example.com

Create a default index.php using the phpinfo command to test PHP.

sudo nano /var/www/example.com/index.php

Copy and paste the text below in the new index.php file.

<?php
phpinfo();
?>

Now, open your browser and enter the server domain name (example.com or www.example.com) for your instance. Are you getting an Unable to connect or a This site can’t be reached message? CentOS's default firewall setting disallows incoming connections to the http port. Do the following to open it.

sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload

Refresh the page in your browser (F5) and you will get the standard PHP info page.


Redirect http://example.com, http://www.example.com, and https://example.com to https://www.example.com (Dynamic Page, PHP-FPM 5.6.x) Configuration

Navigate to the /etc/h2o/ directory.

cd /etc/h2o/

Rename the default h2o.conf to h2o.conf.original.

sudo mv h2o.conf h2o.conf.original

Create a new h2o.conf file.

sudo nano h2o.conf

Copy and paste the text below into the h2o.conf file.

access-log: /var/log/h2o/access.log
compress: ON
error-log: /var/log/h2o/error.log
expires: 1 day
file.index: [ 'index.php' ]
hosts:
  "example.com:80":
    listen:
      port: 80
    paths:
      "/":
        redirect:
          status: 301
          url: "https://example.com/"
  "www.example.com:80":
    listen:
      port: 80
    paths:
      "/":
        redirect:
          status: 301
          url: "https://www.example.com/"
  "example.com:443":
    listen:
      port: 443
      ssl:
        <<: !file /etc/h2o/conf.d/ssl.conf
        certificate-file: /location/of/certificate/file/fullchain.ext
        key-file: /location/of/private/key/file/privkey.ext
    paths:
      "/":
        header.add: "strict-transport-security: max-age=31536000; includeSubDomains; preload"
        redirect:
          status: 301
          url: "https://www.example.com/"
  "www.example.com:443":
    listen:
      port: 443
      ssl:
        <<: !file /etc/h2o/conf.d/ssl.conf
        certificate-file: /location/of/certificate/file/fullchain.ext
        key-file: /location/of/private/key/file/privkey.ext
    paths:
      "/":
        file.dir: /var/www/www.example.com
        header.add: "strict-transport-security: max-age=31536000; includeSubDomains; preload"
        redirect:
          internal: YES
          status: 307
          url: /index.php
file.custom-handler:
  extension: .php
  fastcgi.connect:
    port: /run/php-fpm-5.6.sock
    type: unix
pid-file: /var/run/h2o/h2o.pid
send-server-name: OFF
setenv:
  HTTP_PROXY: ""
user: h2o

Create a custom directory to store the default SSL options for all websites that use SSL.

sudo mkdir conf.d

Create a new ssl.conf file.

sudo nano conf.d/ssl.conf

Copy and paste the text below into the ssl.conf file.

cipher-preference: server
cipher-suite: ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256
dh-file: /etc/ssl/h2o/dhparam_2048.pem

Make a directory to store the dhparam_2048.pem file that will be regenerated daily via a cronjob.

sudo mkdir /etc/ssl/h2o/

Create a new regenerate_dhparam file.

sudo nano /etc/cron.daily/regenerate_dhparam

Copy and paste the following text inside of the regenerate_dhparam file.

#!/bin/bash
cd /etc/ssl/h2o
umask 022
for length in 2048
do
openssl dhparam -out dhparam_$length.tmp $length && mv dhparam_$length.tmp dhparam_$length.pem
chmod 444 dhparam_$length.pem
done

Make the bash file just created executable.

sudo chmod +x /etc/cron.daily/regenerate_dhparam

Execute the bash script for a first run as H2O won't start properly if it's not generated. This will take about a minute or two to generate on first run.

sudo /etc/cron.daily/regenerate_dhparam

In order to process PHP, the PHP-FPM 5.6 daemon must be installed and configured. In order to install a version of PHP-FPM newer than the default 5.4.x, the REMI repo must be installed which contains PHP versions 5.6.x, 7.0.x and 7.1.x. Type the following commands to install PHP version 5.6.x.

sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y
sudo yum install php56-php-fpm -y

Navigate to the /opt/remi/php56/root/etc/ directory.

cd /opt/remi/php56/root/etc/

Rename the default php-fpm.conf to php-fpm.conf.original.

sudo mv php-fpm.conf php-fpm.conf.original

Create a new php-fpm.conf file.

sudo nano php-fpm.conf

Copy and paste the text below into the php-fpm.conf file.

include=/opt/remi/php56/root/etc/php-fpm.d/*.conf
[global]
daemonize = yes
emergency_restart_threshold = 2
emergency_restart_interval = 1m
error_log = /var/log/php-fpm/php-fpm-5.6-error.log
pid = /var/run/php-fpm-5.6.pid
process_control_timeout = 10s

Rename the default www.conf file in the php-fpm.d directory.

sudo mv php-fpm.d/www.conf php-fpm.d/www.conf.original

Create a new www.conf file.

sudo nano php-fpm.d/www.conf

Copy and paste the text below into the www.conf file. Change your pm.max\_children to match the number of CPUs in accordance with your VPS instance.

[www]
group = h2o
listen = /var/run/php-fpm-5.6.sock
listen.backlog = 65536
listen.owner = h2o
listen.group = h2o
pm = static
pm.max_children = 2
pm.max_requests = 10240
user = h2o

Rename the default php.ini file.

sudo mv php.ini php.ini.original

Create a new php.ini file.

sudo nano php.ini

Copy and paste the following text into the new php.ini file. Change the memory\_limit, post\_max\_size, upload\_max\_filesize and date.timezone in accordance with your VPS instance.

[PHP]
allow_url_fopen = On
always_populate_raw_post_data = -1
display_errors = Off
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
expose_php = Off
log_errors = On
memory_limit = 256M
output_buffering = 4096
post_max_size = 64M
register_argc_argv = Off
request_order = "GP"
upload_max_filesize = 64M
variables_order = "GPCS"
[Date]
date.timezone = America/New_York
[Session]
session.cache_limiter =
session.gc_divisor = 1000
session.hash_bits_per_character = 5
session.save_handler = files
session.save_path = "/opt/remi/php56/root/var/lib/php/session/"
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"

Change the group ownership for the /opt/remi/php56/root/var/lib/php/session/ directory from the apache group to the h2o group.

sudo chown root.h2o /opt/remi/php56/root/var/lib/php/session/

Create a directory where the PHP-FPM server logs will reside.

sudo mkdir /var/log/php-fpm/

Enable and start the PHP-FPM server.

sudo systemctl enable php56-php-fpm 
sudo systemctl start php56-php-fpm

Enable and start the H2O server.

sudo systemctl enable h2o
sudo systemctl start h2o

Create a directory where the default index.php will reside listed by the directory option file.dir above in /var/www/www.example.com.

sudo mkdir /var/www/www.example.com

Create a default index.php using the phpinfo command to test PHP.

sudo nano /var/www/www.example.com/index.php

Copy and paste the text below in the new index.php file.

<?php
phpinfo();
?>

Now, open your browser and enter the server domain name (example.com or www.example.com) for your instance. Are you getting an Unable to connect or a This site can’t be reached message? CentOS's default firewall setting disallows incoming connections to the http port. Do the following to open it.

sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload

Refresh the page in your browser (F5) and you will get the standard PHP info page.


Redirect http://example.com, http://www.example.com, and https://www.example.com to https://example.com (Dynamic Page, PHP-FPM 7.1.x) Configuration

Navigate to the /etc/h2o/ directory.

cd /etc/h2o/

Rename the default h2o.conf to h2o.conf.original.

sudo mv h2o.conf h2o.conf.original

Create a new h2o.conf file.

sudo nano h2o.conf

Copy and paste the text below into the h2o.conf file.

access-log: /var/log/h2o/access.log
compress: ON
error-log: /var/log/h2o/error.log
expires: 1 day
file.index: [ 'index.php' ]
hosts:
  "example.com:80":
    listen:
      port: 80
    paths:
      "/":
        redirect:
          status: 301
          url: "https://example.com/"
  "www.example.com:80":
    listen:
      port: 80
    paths:
      "/":
        redirect:
          status: 301
          url: "https://www.example.com/"
  "example.com:443":
    listen:
      port: 443
      ssl:
        <<: !file /etc/h2o/conf.d/ssl.conf
        certificate-file: /location/of/certificate/file/fullchain.ext
        key-file: /location/of/private/key/file/privkey.ext
    paths:
      "/":
        file.dir: /var/www/example.com
        header.add: "strict-transport-security: max-age=31536000; includeSubDomains; preload"
        redirect:
          internal: YES
          status: 307
          url: /index.php
  "www.example.com:443":
    listen:
      port: 443
      ssl:
        <<: !file /etc/h2o/conf.d/ssl.conf
        certificate-file: /location/of/certificate/file/fullchain.ext
        key-file: /location/of/private/key/file/privkey.ext
    paths:
      "/":
        header.add: "strict-transport-security: max-age=31536000; includeSubDomains; preload"
        redirect:
          status: 301
          url: "https://example.com/"
file.custom-handler:
  extension: .php
  fastcgi.connect:
    port: /run/php-fpm-7.1.sock
    type: unix
pid-file: /var/run/h2o/h2o.pid
send-server-name: OFF
setenv:
  HTTP_PROXY: ""
user: h2o

Create a custom directory to store the default SSL options for all websites that use SSL.

sudo mkdir conf.d

Create a new ssl.conf file.

sudo nano conf.d/ssl.conf

Copy and paste the text below into the ssl.conf file.

cipher-preference: server
cipher-suite: ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256
dh-file: /etc/ssl/h2o/dhparam_2048.pem

Make a directory to store the dhparam_2048.pem file that will be regenerated daily via a cronjob.

sudo mkdir /etc/ssl/h2o/

Create a new regenerate_dhparam file.

sudo nano /etc/cron.daily/regenerate_dhparam

Copy and paste the following text inside of the regenerate_dhparam file.

#!/bin/bash
cd /etc/ssl/h2o
umask 022
for length in 2048
do
openssl dhparam -out dhparam_$length.tmp $length && mv dhparam_$length.tmp dhparam_$length.pem
chmod 444 dhparam_$length.pem
done

Make the bash file just created executable.

sudo chmod +x /etc/cron.daily/regenerate_dhparam

Execute the bash script for a first run as H2O won't start properly if it's not generated. This will take about a minute or two to generate on first run.

sudo /etc/cron.daily/regenerate_dhparam

In order to process PHP, the PHP-FPM 7.1 daemon must be installed and configured. In order to install a version of PHP-FPM newer than the default 5.4.x, the REMI repo must be installed which contains PHP versions 5.6.x, 7.0.x and 7.1.x. Type the following commands below to install PHP version 7.1.x.

sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y
sudo yum install php71-php-fpm -y

Navigate to the /etc/opt/remi/php71/ directory.

cd /etc/opt/remi/php71/

Rename the default php-fpm.conf to php-fpm.conf.original.

sudo mv php-fpm.conf php-fpm.conf.original

Create a new php-fpm.conf file.

sudo nano php-fpm.conf

Copy and paste the text below into the php-fpm.conf file.

include=/etc/opt/remi/php71/php-fpm.d/*.conf
[global]
daemonize = yes
emergency_restart_threshold = 2
emergency_restart_interval = 1m
error_log = /var/log/php-fpm/php-fpm-7.1-error.log
pid = /var/run/php-fpm-7.1.pid
process_control_timeout = 10s

Rename the default www.conf file in the php-fpm.d directory.

sudo mv php-fpm.d/www.conf php-fpm.d/www.conf.original

Create a new www.conf file.

sudo nano php-fpm.d/www.conf

Copy and paste the following text into the www.conf file. Change your pm.max\_children to match the number of CPUs in accordance with your VPS instance.

[www]
group = h2o
listen = /var/run/php-fpm-7.1.sock
listen.backlog = 65536
listen.owner = h2o
listen.group = h2o
pm = static
pm.max_children = 2
pm.max_requests = 10240
user = h2o

Rename the default php.ini file.

sudo mv php.ini php.ini.original

Create a new php.ini file.

sudo nano php.ini

Copy and paste the following text below into the new php.ini file. Change the memory\_limit, post\_max\_size, upload\_max\_filesize and date.timezone in accordance with your VPS instance.

[PHP]
allow_url_fopen = On
always_populate_raw_post_data = -1
display_errors = Off
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
expose_php = Off
log_errors = On
memory_limit = 256M
output_buffering = 4096
post_max_size = 64M
register_argc_argv = Off
request_order = "GP"
upload_max_filesize = 64M
variables_order = "GPCS"
[Date]
date.timezone = America/New_York
[Session]
session.cache_limiter =
session.gc_divisor = 1000
session.hash_bits_per_character = 5
session.save_handler = files
session.save_path = "/var/opt/remi/php71/lib/php/session/"
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"

Change the group ownership for the /var/opt/remi/php71/lib/php/session/ directory from the apache group to the h2o group.

sudo chown root.h2o /var/opt/remi/php71/lib/php/session/

Create a directory where the PHP-FPM server logs will reside.

sudo mkdir /var/log/php-fpm/

Enable and start the PHP-FPM server.

sudo systemctl enable php71-php-fpm 
sudo systemctl start php71-php-fpm

Enable and start the H2O server.

sudo systemctl enable h2o
sudo systemctl start h2o

Create a directory where the default index.php will reside listed by the directory option file.dir above in /var/www/example.com.

sudo mkdir /var/www/example.com

Create a default index.php using the phpinfo command to test PHP.

sudo nano /var/www/example.com/index.php

Copy and paste the text below in the new index.php file.

<?php
phpinfo();
?>

Now, open your browser and enter the server domain name (example.com or www.example.com) for your instance. Are you getting an Unable to connect or a This site can’t be reached message? CentOS's default firewall setting disallows incoming connections to the http port. Do the following to open it.

sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload

Refresh the page in your browser (F5) and you will get the standard PHP info page.


Redirect http://example.com, http://www.example.com, and https://example.com to https://www.example.com (Dynamic Page, PHP-FPM 7.1.x) Configuration

Navigate to the /etc/h2o/ directory.

cd /etc/h2o/

Rename the default h2o.conf to h2o.conf.original.

sudo mv h2o.conf h2o.conf.original

Create a new h2o.conf file.

sudo nano h2o.conf

Copy and paste the text below into the h2o.conf file.

access-log: /var/log/h2o/access.log
compress: ON
error-log: /var/log/h2o/error.log
expires: 1 day
file.index: [ 'index.php' ]
hosts:
  "example.com:80":
    listen:
      port: 80
    paths:
      "/":
        redirect:
          status: 301
          url: "https://example.com/"
  "www.example.com:80":
    listen:
      port: 80
    paths:
      "/":
        redirect:
          status: 301
          url: "https://www.example.com/"
  "example.com:443":
    listen:
      port: 443
      ssl:
        <<: !file /etc/h2o/conf.d/ssl.conf
        certificate-file: /location/of/certificate/file/fullchain.ext
        key-file: /location/of/private/key/file/privkey.ext
    paths:
      "/":
        header.add: "strict-transport-security: max-age=31536000; includeSubDomains; preload"
        redirect:
          status: 301
          url: "https://www.example.com/"
  "www.example.com:443":
    listen:
      port: 443
      ssl:
        <<: !file /etc/h2o/conf.d/ssl.conf
        certificate-file: /location/of/certificate/file/fullchain.ext
        key-file: /location/of/private/key/file/privkey.ext
    paths:
      "/":
        file.dir: /var/www/www.example.com
        header.add: "strict-transport-security: max-age=31536000; includeSubDomains; preload"
        redirect:
          internal: YES
          status: 307
          url: /index.php
file.custom-handler:
  extension: .php
  fastcgi.connect:
    port: /run/php-fpm-7.1.sock
    type: unix
pid-file: /var/run/h2o/h2o.pid
send-server-name: OFF
setenv:
  HTTP_PROXY: ""
user: h2o

Create a custom directory to store the default SSL options for all websites that use SSL.

sudo mkdir conf.d

Create a new ssl.conf file.

sudo nano conf.d/ssl.conf

Copy and paste the text below into the ssl.conf file.

cipher-preference: server
cipher-suite: ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256
dh-file: /etc/ssl/h2o/dhparam_2048.pem

Make a directory to store the dhparam_2048.pem file that will be regenerated daily via a cronjob.

sudo mkdir /etc/ssl/h2o/

Create a new regenerate_dhparam file.

sudo nano /etc/cron.daily/regenerate_dhparam

Copy and paste the following text inside of the regenerate_dhparam file.

#!/bin/bash
cd /etc/ssl/h2o
umask 022
for length in 2048
do
openssl dhparam -out dhparam_$length.tmp $length && mv dhparam_$length.tmp dhparam_$length.pem
chmod 444 dhparam_$length.pem
done

Make the bash file just created executable.

sudo chmod +x /etc/cron.daily/regenerate_dhparam

Execute the bash script for a first run as H2O won't start properly if it's not generated. This will take about a minute or two to generate on first run.

sudo /etc/cron.daily/regenerate_dhparam

For at behandle PHP skal PHP-FPM 7.1-dæmonen være installeret og konfigureret. For at installere en version af PHP-FPM nyere end standard 5.4.x, skal REMI repo være installeret, som indeholder PHP versioner 5.6.x, 7.0.x og 7.1.x. Indtast følgende kommandoer for at installere PHP version 7.1.x.

sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y
sudo yum install php71-php-fpm -y

Naviger til /etc/opt/remi/php71/biblioteket.

cd /etc/opt/remi/php71/

Omdøb standarden php-fpm.conftil php-fpm.conf.original.

sudo mv php-fpm.conf php-fpm.conf.original

Opret en ny php-fpm.conffil.

sudo nano php-fpm.conf

Kopier og indsæt følgende tekst i php-fpm.conffilen.

include=/etc/opt/remi/php71/php-fpm.d/*.conf
[global]
daemonize = yes
emergency_restart_threshold = 2
emergency_restart_interval = 1m
error_log = /var/log/php-fpm/php-fpm-7.1-error.log
pid = /var/run/php-fpm-7.1.pid
process_control_timeout = 10s

Omdøb standardfilen www.confi php-fpm.dmappen.

sudo mv php-fpm.d/www.conf php-fpm.d/www.conf.original

Opret en ny www.conffil.

sudo nano php-fpm.d/www.conf

Kopier og indsæt teksten nedenfor i www.conffilen. Skift din pm.max\_childrentil at matche antallet af CPU'er i overensstemmelse med din VPS-instans.

[www]
group = h2o
listen = /var/run/php-fpm-7.1.sock
listen.backlog = 65536
listen.owner = h2o
listen.group = h2o
pm = static
pm.max_children = 2
pm.max_requests = 10240
user = h2o

Omdøb standardfilen php.ini.

sudo mv php.ini php.ini.original

Opret en ny php.inifil.

sudo nano php.ini

Kopier og indsæt følgende tekst nedenfor i den nye php.ini file. Skift memory\_limit, post\_max\_size, upload\_max\_filesizeog date.timezonei overensstemmelse med din VPS-instans.

[PHP]
allow_url_fopen = On
always_populate_raw_post_data = -1
display_errors = Off
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
expose_php = Off
log_errors = On
memory_limit = 256M
output_buffering = 4096
post_max_size = 64M
register_argc_argv = Off
request_order = "GP"
upload_max_filesize = 64M
variables_order = "GPCS"
[Date]
date.timezone = America/New_York
[Session]
session.cache_limiter =
session.gc_divisor = 1000
session.hash_bits_per_character = 5
session.save_handler = files
session.save_path = "/var/opt/remi/php71/lib/php/session"
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"

Skift gruppeejerskab for /var/opt/remi/php71/lib/php/session/biblioteket fra apachegruppen til h2ogruppen.

sudo chown root.h2o /var/opt/remi/php71/lib/php/session/

Opret en mappe, hvor PHP-FPM-serverlogfilerne vil ligge.

sudo mkdir /var/log/php-fpm/

Aktiver og start PHP-FPM-serveren.

sudo systemctl enable php71-php-fpm 
sudo systemctl start php71-php-fpm

Aktiver og start H2O-serveren.

sudo systemctl enable h2o
sudo systemctl start h2o

Opret en mappe, hvor standarden index.phpvil være angivet af biblioteksindstillingen file.dirovenfor i /var/www/example.com.

sudo mkdir /var/www/www.example.com

Opret en standard index.phpved at bruge phpinfokommandoen til at teste PHP.

sudo nano /var/www/www.example.com/index.php

Kopier og indsæt teksten nedenfor i den nye index.phpfil.

<?php
phpinfo();
?>

Åbn nu din browser og indtast serverens domænenavn ( example.comeller www.example.com) for din forekomst. Får du en Unable to connecteller en This site can’t be reachedbesked? CentOS' standard firewall-indstilling tillader ikke indgående forbindelser til http-porten. Gør følgende for at åbne den.

sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload

Opdater siden i din browser ( F5), så får du standard PHP info-siden.


Dette afslutter min tutorial. Tak fordi du læste med.


Installer Plesk på CentOS 7

Installer Plesk på CentOS 7

Bruger du et andet system? Plesk er et proprietært webhost kontrolpanel, der giver brugerne mulighed for at administrere deres personlige og/eller klienters websteder, databaser

Sådan installeres Squid Proxy på CentOS

Sådan installeres Squid Proxy på CentOS

Squid er et populært, gratis Linux-program, der giver dig mulighed for at oprette en webproxy til videresendelse. I denne vejledning vil du se, hvordan du installerer Squid på CentOS for at gøre dig

Sådan installeres Lighttpd (LLMP Stack) på CentOS 6

Sådan installeres Lighttpd (LLMP Stack) på CentOS 6

Introduktion Lighttpd er en forgrening af Apache, der sigter mod at være meget mindre ressourcekrævende. Den er let, deraf navnet, og den er ret enkel at bruge. Installer

Konfiguration af statisk netværk og IPv6 på CentOS 7

Konfiguration af statisk netværk og IPv6 på CentOS 7

VULTR har for nylig foretaget ændringer i deres ende, og alt skulle nu fungere fint ud af boksen med NetworkManager aktiveret. Skulle du ønske at deaktivere

Ændring af Icinga2 til at bruge Master/Client Model på CentOS 6 eller CentOS 7

Ændring af Icinga2 til at bruge Master/Client Model på CentOS 6 eller CentOS 7

Icinga2 er et kraftfuldt overvågningssystem, og når det bruges i en master-klient-model, kan det erstatte behovet for NRPE-baserede overvågningstjek. Mester-klienten

Sådan installeres Apache Cassandra 3.11.x på CentOS 7

Sådan installeres Apache Cassandra 3.11.x på CentOS 7

Bruger du et andet system? Apache Cassandra er et gratis og open source NoSQL-databasestyringssystem, der er designet til at give skalerbarhed, høj

Sådan installeres Microweber på CentOS 7

Sådan installeres Microweber på CentOS 7

Bruger du et andet system? Microweber er en open source træk og slip CMS og online shop. Microweber-kildekoden er hostet på GitHub. Denne guide vil vise dig

Sådan installeres Mattermost 4.1 på CentOS 7

Sådan installeres Mattermost 4.1 på CentOS 7

Bruger du et andet system? Mattermost er et open source, selvhostet alternativ til Slack SAAS-meddelelsestjenesten. Med andre ord, med Mattermost er du ca

Oprettelse af et netværk af Minecraft-servere med BungeeCord på Debian 8, Debian 9 eller CentOS 7

Oprettelse af et netværk af Minecraft-servere med BungeeCord på Debian 8, Debian 9 eller CentOS 7

Hvad skal du bruge En Vultr VPS med mindst 1 GB RAM. SSH-adgang (med root/administrative rettigheder). Trin 1: Installation af BungeeCord Første ting først

Lad os kryptere på Plesk

Lad os kryptere på Plesk

Plesk-kontrolpanelet har en meget flot integration til Lets Encrypt. Lets Encrypt er en af ​​de eneste SSL-udbydere, der udleverer certifikater komplet

Lader kryptere på cPanel

Lader kryptere på cPanel

Lets Encrypt er en certifikatmyndighed dedikeret til at levere SSL-certifikater gratis. cPanel har bygget en pæn integration, så du og din klient

Sådan installeres Concrete5 på CentOS 7

Sådan installeres Concrete5 på CentOS 7

Bruger du et andet system? Concrete5 er et open source CMS, som tilbyder mange karakteristiske og nyttige funktioner til at hjælpe redaktører med at producere indhold nemt og

Sådan installeres Review Board på CentOS 7

Sådan installeres Review Board på CentOS 7

Bruger du et andet system? Review Board er et gratis og open source-værktøj til gennemgang af kildekode, dokumentation, billeder og mange flere. Det er webbaseret software

Konfigurer HTTP-godkendelse med Nginx på CentOS 7

Konfigurer HTTP-godkendelse med Nginx på CentOS 7

I denne vejledning lærer du, hvordan du opsætter HTTP-godkendelse for en Nginx-webserver, der kører på CentOS 7. Krav For at komme i gang skal du bruge

Sådan installeres YOURLS på CentOS 7

Sådan installeres YOURLS på CentOS 7

YOURLS (Your Own URL Shortener) er en open source URL-forkortelse og dataanalyseapplikation. I denne artikel vil vi dække installationsprocessen

Sådan installeres og konfigureres ArangoDB på CentOS 7

Sådan installeres og konfigureres ArangoDB på CentOS 7

Bruger du et andet system? Introduktion ArangoDB er en open source NoSQL-database med en fleksibel datamodel for dokumenter, grafer og nøgleværdier. det er

Brug af Etckeeper til versionskontrol af /etc

Brug af Etckeeper til versionskontrol af /etc

Introduktion /etc/-biblioteket spiller en afgørende rolle i den måde et Linux-system fungerer på. Årsagen til dette er, at næsten alle systemkonfigurationer

Hvorfor skal du bruge SSHFS? Sådan monteres et eksternt filsystem med SSHFS på CentOS 6

Hvorfor skal du bruge SSHFS? Sådan monteres et eksternt filsystem med SSHFS på CentOS 6

Mange systemadministratorer administrerer store mængder servere. Når filer skal tilgås på tværs af forskellige servere, logges ind på hver enkelt individuelt ca

Opsætning af en Half Life 2-server på CentOS 6

Opsætning af en Half Life 2-server på CentOS 6

Denne vejledning vil dække processen med at installere en Half Life 2-spilserver på CentOS 6 System. Trin 1: Installation af forudsætninger For at opsætte ou

Sådan installeres Laravel GitScrum på CentOS 7

Sådan installeres Laravel GitScrum på CentOS 7

Laravel GitScrum eller GitScrum er et open source-produktivitetsværktøj designet til at hjælpe udviklingsteams med at implementere Scrum-metoden på en måde, der ligner t.

The Rise of Machines: Real World Applications of AI

The Rise of Machines: Real World Applications of AI

Kunstig intelligens er ikke i fremtiden, det er her lige i nuet I denne blog Læs, hvordan kunstig intelligens-applikationer har påvirket forskellige sektorer.

DDOS-angreb: et kort overblik

DDOS-angreb: et kort overblik

Er du også et offer for DDOS-angreb og forvirret over forebyggelsesmetoderne? Læs denne artikel for at løse dine spørgsmål.

Har du nogensinde spekuleret på, hvordan tjener hackere penge?

Har du nogensinde spekuleret på, hvordan tjener hackere penge?

Du har måske hørt, at hackere tjener mange penge, men har du nogensinde spekuleret på, hvordan tjener de den slags penge? lad os diskutere.

Revolutionære opfindelser fra Google, der vil gøre dit liv lettere.

Revolutionære opfindelser fra Google, der vil gøre dit liv lettere.

Vil du se revolutionerende opfindelser fra Google, og hvordan disse opfindelser ændrede livet for ethvert menneske i dag? Læs derefter til bloggen for at se opfindelser fra Google.

Fredag ​​Essential: Hvad skete der med AI-drevne biler?

Fredag ​​Essential: Hvad skete der med AI-drevne biler?

Konceptet med selvkørende biler til at køre på vejene ved hjælp af kunstig intelligens er en drøm, vi har haft i et stykke tid nu. Men på trods af flere løfter er de ingen steder at se. Læs denne blog for at lære mere...

Teknologisk singularitet: En fjern fremtid for menneskelig civilisation?

Teknologisk singularitet: En fjern fremtid for menneskelig civilisation?

Efterhånden som videnskaben udvikler sig i et hurtigt tempo og overtager en stor del af vores indsats, stiger risikoen for at udsætte os selv for en uforklarlig Singularitet. Læs, hvad singularitet kunne betyde for os.

Udvikling af datalagring – Infografik

Udvikling af datalagring – Infografik

Opbevaringsmetoderne for dataene har været under udvikling, kan være siden fødslen af ​​dataene. Denne blog dækker udviklingen af ​​datalagring på basis af en infografik.

Funktioner af Big Data Reference Architecture Layers

Funktioner af Big Data Reference Architecture Layers

Læs bloggen for at kende forskellige lag i Big Data-arkitekturen og deres funktionaliteter på den enkleste måde.

6 fantastiske fordele ved at have smarte hjemmeenheder i vores liv

6 fantastiske fordele ved at have smarte hjemmeenheder i vores liv

I denne digitalt drevne verden er smarte hjemmeenheder blevet en afgørende del af livet. Her er et par fantastiske fordele ved smarte hjemmeenheder om, hvordan de gør vores liv værd at leve og enklere.

macOS Catalina 10.15.4-tillægsopdatering forårsager flere problemer end at løse

macOS Catalina 10.15.4-tillægsopdatering forårsager flere problemer end at løse

For nylig udgav Apple macOS Catalina 10.15.4 en supplerende opdatering for at løse problemer, men det ser ud til, at opdateringen forårsager flere problemer, hvilket fører til mursten af ​​mac-maskiner. Læs denne artikel for at lære mere