Installer H2O Web Server på CentOS 7

H2O er en ny generasjon HTTP-server som har en flott, fullt utstyrt HTTP/2-implementering av alle de gjeldende webserverne som er i bruk. Med H2O som din webserver kan du dra nytte av de nye funksjonene i HTTP/2-spesifikasjonen, som latensoptimalisering, server-push og serversideprioritering som kan dra nytte av moderne nettleserfunksjoner som det sjelden snakkes om.

I denne detaljerte opplæringen vil jeg vise deg trinn for trinn hvordan du får H2O til å kjøre på din CentOS 7 x64-forekomst.

Forutsetninger

  • En CentOS 7 x64-serverforekomst.
  • En sudo- bruker.
  • Et SSL-sertifikat (valgfritt)

Trinn 1: Oppdater systemet

Logg inn via SSH med legitimasjonen du finner under din instans og oppdater systemet som følger.

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

Trinn 2: Installer H2O

For å installere H2O på CentOS 7, må du legge til Bintray RPM-depotet for å installere de forhåndsbygde H2O-binærfilene. Bruk Nano-editoren til å lage en egendefinert repo.

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

Kopier og lim inn 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 deretter H2O.

sudo yum install h2o -y

Nå som H2O er installert, men før du aktiverer og starter tjenesten, kreves en riktig konfigurasjon, og vi må opprette en spesifikk bruker og gruppe som H2O kan kjøres under. Opprett en gruppe og bruker for H2O å kjøre under navngitt h2o.

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

Trinn 3: Konfigurering av H2O Web Server

De følgende trinnene vil gi eksempler på konfigurasjonsoppsett for ulike unencrypted, encrypted, staticog dynamicserveroppsett; samt en kombinasjon av alle fire.


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

Naviger til /etc/h2o/katalogen.

cd /etc/h2o/

Gi nytt navn til standarden h2o.conftil h2o.conf.original.

sudo mv h2o.conf h2o.conf.original

Opprett en ny h2o.conffil.

sudo nano h2o.conf

Kopier og lim inn 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

Opprett en standard index.htmlved å bruke malen i /var/www/htmlkatalogalternativet som er file.diroppført ovenfor i /var/www/example.com.

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

Åpne nå nettleseren og skriv inn serverdomenenavnet ( example.comeller www.example.com) for din forekomst. Får du en Unable to connecteller en This site can’t be reachedmelding? CentOSs standard brannmurinnstilling tillater ikke innkommende tilkoblinger til http-porten. Utfør følgende for å åpne den.

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

Oppdater siden i nettleseren din ( F5), så får du denne meldingen.


Welcome to H2O - an optimized HTTP server

It works!

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

Naviger til /etc/h2o/katalogen.

cd /etc/h2o/

Gi nytt navn til standarden h2o.conftil h2o.conf.original.

sudo mv h2o.conf h2o.conf.original

Opprett en ny h2o.conffil.

sudo nano h2o.conf

Kopier og lim inn 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

Opprett en standardfil index.htmlved å bruke malen i /var/www/htmlkatalogalternativet som er file.diroppført ovenfor i /var/www/www.example.com.

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

Åpne nå nettleseren og skriv inn serverdomenenavnet ( example.comeller www.example.com) for din forekomst. Får du en Unable to connecteller en This site can’t be reachedmelding? CentOSs standard brannmurinnstilling tillater ikke innkommende tilkoblinger til http-porten. Gjør følgende for å åpne den.

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

Oppdater siden i nettleseren din ( F5), så får du denne meldingen.


Welcome to H2O - an optimized HTTP server

It works!

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

Naviger til /etc/h2o/katalogen.

cd /etc/h2o/

Gi nytt navn til standarden h2o.conftil h2o.conf.original.

sudo mv h2o.conf h2o.conf.original

Opprett en ny h2o.conffil.

sudo nano h2o.conf

Kopier og lim inn 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

Kjør bash-skriptet for en første kjøring, da H2O ikke starter ordentlig hvis det ikke genereres. Dette vil ta omtrent et minutt eller to å generere ved første kjøring.

sudo /etc/cron.daily/regenerate_dhparam

For å behandle PHP må PHP-FPM 7.1-demonen være installert og konfigurert. For å installere en versjon av PHP-FPM nyere enn standard 5.4.x, må REMI repo være installert som inneholder PHP versjoner 5.6.x, 7.0.x og 7.1.x. Skriv inn følgende kommandoer for å installere PHP versjon 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/katalogen.

cd /etc/opt/remi/php71/

Gi nytt navn til standarden php-fpm.conftil php-fpm.conf.original.

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

Opprett en ny php-fpm.conffil.

sudo nano php-fpm.conf

Kopier og lim inn 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

Gi nytt navn til standardfilen www.confi php-fpm.dkatalogen.

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

Opprett en ny www.conffil.

sudo nano php-fpm.d/www.conf

Kopier og lim inn teksten nedenfor i www.conffilen. Endre din for pm.max\_childrenå matche antall CPUer i samsvar med din VPS-forekomst.

[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

Gi nytt navn til standardfilen php.ini.

sudo mv php.ini php.ini.original

Opprett en ny php.inifil.

sudo nano php.ini

Kopier og lim inn følgende tekst nedenfor i den nye php.ini file. Endre memory\_limit, post\_max\_size, upload\_max\_filesizeog date.timezonei samsvar med din VPS-forekomst.

[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"

Endre gruppeeierskap for /var/opt/remi/php71/lib/php/session/katalogen fra apachegruppen til h2ogruppen.

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

Opprett en katalog der PHP-FPM-serverloggene 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

Opprett en katalog der standarden index.phpvil ligge oppført av katalogalternativet file.dirovenfor i /var/www/example.com.

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

Opprett en standard index.phpved å bruke phpinfokommandoen for å teste PHP.

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

Kopier og lim inn teksten nedenfor i den nye index.phpfilen.

<?php
phpinfo();
?>

Åpne nå nettleseren og skriv inn serverdomenenavnet ( example.comeller www.example.com) for din forekomst. Får du en Unable to connecteller en This site can’t be reachedmelding? CentOSs standard brannmurinnstilling tillater ikke innkommende tilkoblinger til http-porten. Gjør følgende for å åpne den.

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

Oppdater siden i nettleseren din ( F5), så får du standard PHP-infoside.


Dette avslutter veiledningen min. Takk for at du leste.


Installer Plesk på CentOS 7

Installer Plesk på CentOS 7

Bruker du et annet system? Plesk er et proprietært kontrollpanel for webverten som lar brukere administrere sine personlige og/eller klienters nettsteder, databaser

Slik installerer du Squid Proxy på CentOS

Slik installerer du Squid Proxy på CentOS

Squid er et populært, gratis Linux-program som lar deg lage en webproxy for videresending. I denne veiledningen vil du se hvordan du installerer Squid på CentOS for å gjøre deg om

Slik installerer du Lighttpd (LLMP Stack) på CentOS 6

Slik installerer du Lighttpd (LLMP Stack) på CentOS 6

Introduksjon Lighttpd er en apachegaffel som har som mål å være mye mindre ressurskrevende. Den er lett, derav navnet, og er ganske enkel å bruke. Installer

Konfigurering av statisk nettverk og IPv6 på CentOS 7

Konfigurering av statisk nettverk og IPv6 på CentOS 7

VULTR har nylig gjort endringer på sin side, og alt skal nå fungere bra ut av boksen med NetworkManager aktivert. Skulle du ønske å deaktivere

Endring av Icinga2 for å bruke hoved-/klientmodell på CentOS 6 eller CentOS 7

Endring av Icinga2 for å bruke hoved-/klientmodell på CentOS 6 eller CentOS 7

Icinga2 er et kraftig overvåkingssystem, og når det brukes i en master-klient-modell, kan det erstatte behovet for NRPE-baserte overvåkingskontroller. Mester-klienten

Slik installerer du Apache Cassandra 3.11.x på CentOS 7

Slik installerer du Apache Cassandra 3.11.x på CentOS 7

Bruker du et annet system? Apache Cassandra er et gratis og åpen kildekode NoSQL-databasebehandlingssystem som er designet for å gi skalerbarhet, høy

Slik installerer du Microweber på CentOS 7

Slik installerer du Microweber på CentOS 7

Bruker du et annet system? Microweber er en åpen kildekode dra og slipp CMS og nettbutikk. Microweber-kildekoden er vert på GitHub. Denne guiden vil vise deg

Hvordan installere Vanilla Forum på CentOS 7

Hvordan installere Vanilla Forum på CentOS 7

Bruker du et annet system? Vanilla forum er en åpen kildekode-forumapplikasjon skrevet i PHP. Det er en fullt tilpassbar, enkel å bruke og støtter ekstern

Slik installerer du Mattermost 4.1 på CentOS 7

Slik installerer du Mattermost 4.1 på CentOS 7

Bruker du et annet system? Mattermost er et åpen kildekode, selvdrevet alternativ til Slack SAAS-meldingstjenesten. Med andre ord, med Mattermost kan du ca

Opprette et nettverk av Minecraft-servere med BungeeCord på Debian 8, Debian 9 eller CentOS 7

Opprette et nettverk av Minecraft-servere med BungeeCord på Debian 8, Debian 9 eller CentOS 7

Hva du trenger En Vultr VPS med minst 1 GB RAM. SSH-tilgang (med root/administratorrettigheter). Trinn 1: Installere BungeeCord Først

La oss kryptere på Plesk

La oss kryptere på Plesk

Plesk-kontrollpanelet har en veldig fin integrasjon for Lets Encrypt. Lets Encrypt er en av de eneste SSL-leverandørene som gir ut sertifikater komplett

La oss kryptere på cPanel

La oss kryptere på cPanel

Lets Encrypt er en sertifiseringsinstans dedikert til å tilby SSL-sertifikater gratis. cPanel har bygget en ryddig integrasjon slik at du og din klient

Hvordan installere Concrete5 på CentOS 7

Hvordan installere Concrete5 på CentOS 7

Bruker du et annet system? Concrete5 er et åpen kildekode CMS som tilbyr mange karakteristiske og nyttige funksjoner for å hjelpe redaktører med å produsere innhold enkelt og

Slik installerer du Review Board på CentOS 7

Slik installerer du Review Board på CentOS 7

Bruker du et annet system? Review Board er et gratis og åpen kildekodeverktøy for gjennomgang av kildekode, dokumentasjon, bilder og mye mer. Det er nettbasert programvare

Sett opp HTTP-autentisering med Nginx på CentOS 7

Sett opp HTTP-autentisering med Nginx på CentOS 7

I denne veiledningen lærer du hvordan du setter opp HTTP-autentisering for en Nginx-webserver som kjører på CentOS 7. Krav For å komme i gang trenger du

Slik installerer du GoAccess på CentOS 7

Slik installerer du GoAccess på CentOS 7

Bruker du et annet system? GoAccess er en åpen kildekode-nettlogganalysator. Du kan bruke den til analyse av logger på sanntidsbasis i enten terminalen eller

Hvordan installere YOURLS på CentOS 7

Hvordan installere YOURLS på CentOS 7

YOURLS (Your Own URL Shortener) er en åpen kildekode-applikasjon for URL-forkorting og dataanalyse. I denne artikkelen vil vi dekke installasjonsprosessen

Hvordan installere og konfigurere ArangoDB på CentOS 7

Hvordan installere og konfigurere ArangoDB på CentOS 7

Bruker du et annet system? Introduksjon ArangoDB er en åpen kildekode NoSQL-database med en fleksibel datamodell for dokumenter, grafer og nøkkelverdier. Det er

Bruke Etckeeper for versjonskontroll av /etc

Bruke Etckeeper for versjonskontroll av /etc

Innledning /etc/-katalogen spiller en kritisk rolle i måten et Linux-system fungerer på. Grunnen til dette er fordi nesten alle systemkonfigurasjoner

Hvorfor bør du bruke SSHFS? Hvordan montere et eksternt filsystem med SSHFS på CentOS 6

Hvorfor bør du bruke SSHFS? Hvordan montere et eksternt filsystem med SSHFS på CentOS 6

Mange systemadministratorer administrerer store mengder servere. Når filer må åpnes på tvers av forskjellige servere, logger du på hver enkelt individuelt ca

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 akkurat i nåtiden I denne bloggen Les hvordan kunstig intelligens-applikasjoner har påvirket ulike sektorer.

DDOS-angrep: en kort oversikt

DDOS-angrep: en kort oversikt

Er du også et offer for DDOS-angrep og forvirret over forebyggingsmetodene? Les denne artikkelen for å løse spørsmålene dine.

Har du noen gang lurt på hvordan hackere tjener penger?

Har du noen gang lurt på hvordan hackere tjener penger?

Du har kanskje hørt at hackere tjener mye penger, men har du noen gang lurt på hvordan tjener de den slags penger? la oss diskutere.

Revolusjonerende oppfinnelser fra Google som vil gjøre livet ditt enkelt.

Revolusjonerende oppfinnelser fra Google som vil gjøre livet ditt enkelt.

Vil du se revolusjonerende oppfinnelser fra Google og hvordan disse oppfinnelsene forandret livet til alle mennesker i dag? Les deretter til bloggen for å se oppfinnelser fra Google.

Fredag ​​Essential: Hva skjedde med AI-drevne biler?

Fredag ​​Essential: Hva skjedde med AI-drevne biler?

Konseptet med selvkjørende biler som skal ut på veiene ved hjelp av kunstig intelligens er en drøm vi har hatt en stund nå. Men til tross for flere løfter, er de ingen steder å se. Les denne bloggen for å lære mer...

Teknologisk singularitet: en fjern fremtid for menneskelig sivilisasjon?

Teknologisk singularitet: en fjern fremtid for menneskelig sivilisasjon?

Ettersom vitenskapen utvikler seg raskt og tar over mye av innsatsen vår, øker også risikoen for å utsette oss for en uforklarlig singularitet. Les hva singularitet kan bety for oss.

Evolusjon av datalagring – infografikk

Evolusjon av datalagring – infografikk

Lagringsmetodene for dataene har vært i utvikling kan være siden fødselen av dataene. Denne bloggen dekker utviklingen av datalagring på grunnlag av en infografikk.

Funksjonaliteter til Big Data Reference Architecture Layers

Funksjonaliteter til Big Data Reference Architecture Layers

Les bloggen for å kjenne ulike lag i Big Data Architecture og deres funksjoner på den enkleste måten.

6 fantastiske fordeler ved å ha smarte hjemmeenheter i livene våre

6 fantastiske fordeler ved å ha smarte hjemmeenheter i livene våre

I denne digitaldrevne verden har smarthusenheter blitt en avgjørende del av livet. Her er noen fantastiske fordeler med smarthusenheter om hvordan de gjør livet vårt verdt å leve og enklere.

macOS Catalina 10.15.4 tilleggsoppdatering forårsaker flere problemer enn å løse

macOS Catalina 10.15.4 tilleggsoppdatering forårsaker flere problemer enn å løse

Nylig lanserte Apple macOS Catalina 10.15.4 en tilleggsoppdatering for å fikse problemer, men det ser ut til at oppdateringen forårsaker flere problemer som fører til muring av mac-maskiner. Les denne artikkelen for å lære mer