{"id":2121,"date":"2018-05-23T15:13:19","date_gmt":"2018-05-23T13:13:19","guid":{"rendered":"http:\/\/miroslaw.borodziuk.eu\/?p=2121"},"modified":"2018-05-23T17:13:50","modified_gmt":"2018-05-23T15:13:50","slug":"instalacja-nginx-php-7-2-na-centos-7-rhel-7","status":"publish","type":"post","link":"http:\/\/miro.borodziuk.eu\/index.php\/2018\/05\/23\/instalacja-nginx-php-7-2-na-centos-7-rhel-7\/","title":{"rendered":"Instalacja Nginx + PHP 7.2 na CentOS 7 \/ RHEL 7"},"content":{"rendered":"<p>PHP to akronim od s\u0142\u00f3w PHP: Hypertext Preprocessor, jest mechanizmem dzia\u0142aj\u0105cym po stronie\u00a0 serwera. W PHP mo\u017cna tworzy\u0107 strony internetowe generowane dynamicznie lub osadza\u0107 skrypty PHP\u00a0 bezpo\u015brednio w kodzie\u00a0 HTML. PHP mo\u017cna zintegrowa\u0107 z komercyjnymi i nie komercyjnymi systemami zarz\u0105dzania bazami danych. Domy\u015blnie CentOS 7\/RHEL 7 dostarcza PHP tylko w wersji 5.4. Artyku\u0142 wyja\u015bnia jak zainstalowa\u0107 PHP 7.2 w systemach CentOS 7 l RHEL 7.<\/p>\n<p><!--more--><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #3366ff;\">Instalacja PHP w wersji 7.2<\/span><\/p>\n<p>W\u0142\u0105czamy repozytorium EPEL:<\/p>\n<pre class=\"lang:sh decode:true\">$ sudo yum -y install epel-release<\/pre>\n<p>W\u0142\u0105czamy repozytorium Remi remi-php72:<\/p>\n<pre class=\"lang:sh decode:true\">$ sudo yum-config-manager --enable remi-php72<\/pre>\n<p>Od\u015bwie\u017cenie repozytorium:<\/p>\n<pre class=\"lang:sh decode:true\">$ sudo yum update\r\n<\/pre>\n<p>Instalacja PHP w wersji 7.2:<\/p>\n<pre class=\"lang:sh decode:true \">$ sudo yum install php<\/pre>\n<p>Instalacja repozytorium Remi:<\/p>\n<pre class=\"lang:sh decode:true\">$ sudo yum -y install http:\/\/rpms.remirepo.net\/enterprise\/remi-release-7.rpm<\/pre>\n<p>Instalacja pakietu yum-utils:<\/p>\n<pre class=\"lang:sh decode:true \">$ sudo yum -y install yum-utils<\/pre>\n<p>W\u0142\u0105czenie repozytorium remi repo:<\/p>\n<pre class=\"lang:sh decode:true\">$ sudo yum-config-manager --enable remi-php72\r\n$ sudo yum update<\/pre>\n<p>Sprawdzamy czy w repozytorium s\u0105 dost\u0119pne pakiety zwi\u0105zane z PHP 7.2:<\/p>\n<pre class=\"lang:sh decode:true \">$ sudo yum search php72 | more\r\n$ sudo yum search php72 | egrep 'fpm|gd|mysql|memcache'<\/pre>\n<p>&nbsp;<\/p>\n<p>Finalnie instalujemy PHP 7.2:<\/p>\n<pre class=\"lang:sh decode:true\">$ sudo yum -y install php72<\/pre>\n<p>A dodatkowo:<\/p>\n<pre class=\"lang:sh decode:true\">$ sudo yum -y install php72-php-fpm php72-php-gd php72-php-json php72-php-mbstring php72-php-mysqlnd php72-php-xml php72-php-xmlrpc php72-php-opcache<\/pre>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #3366ff;\">Instalacja PHP 7.2 w RHEL 7<\/span><\/p>\n<pre class=\"lang:sh decode:true\">$ sudo yum install https:\/\/dl.fedoraproject.org\/pub\/epel\/epel-release-latest-7.noarch.rpm\r\n$ sudo yum install http:\/\/rpms.remirepo.net\/enterprise\/remi-release-7.rpm\r\n$ sudo yum install yum-utils\r\n$ sudo subscription-manager repos --enable=rhel-7-server-optional-rpms\r\n$ sudo yum-config-manager --enable remi-php72\r\n$ sudo yum update\r\n$ sudo yum search php72 | more\r\n$ sudo yum install php72 php72-php-fpm php72-php-gd php72-php-json php72-php-mbstring php72-php-mysqlnd php72-php-xml php72-php-xmlrpc php72-php-opcache<\/pre>\n<p>Sprawdzenie wersji PHP:<\/p>\n<pre class=\"lang:sh decode:true\">$ php --version<\/pre>\n<p>Wylistowanie zainstalowanych modu\u0142\u00f3w:<\/p>\n<pre class=\"lang:sh decode:true \">$ php72 --modules<\/pre>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #3366ff;\">W\u0142\u0105czenie us\u0142ugi PHP fpm dla NGINX<\/span><\/p>\n<p>W\u0142\u0105czamy autostart php72-php-fpm :<\/p>\n<pre class=\"lang:sh decode:true \">$ sudo systemctl enable php72-php-fpm.service<\/pre>\n<p>W\u0142\u0105czamy us\u0142ug\u0119 php72-php-fpm :<\/p>\n<pre class=\"lang:sh decode:true \">$ sudo systemctl start php72-php-fpm.service<\/pre>\n<p>Instalacja NGINX:<\/p>\n<pre class=\"lang:sh decode:true \">$ sudo yum -y install nginx<\/pre>\n<p>Sprawdzenie jakiego u\u017cytkownika i grupy u\u017cywa NGINX:<\/p>\n<pre class=\"lang:sh decode:true \">$ egrep '^(user|group)' \/etc\/nginx\/nginx.conf\r\nuser nginx;<\/pre>\n<p>Edycja pliku<code> \/etc\/opt\/remi\/php72\/php-fpm.d\/www.conf<\/code>:<\/p>\n<pre class=\"lang:sh decode:true\">$ sudo vim \/etc\/opt\/remi\/php72\/php-fpm.d\/www.conf<\/pre>\n<p>Ustawienie u\u017cytkownika i grupy\u00a0 na nginx:<br \/>\n<code>user = nginx<\/code><br \/>\n<code>group = nginx<\/code><\/p>\n<p>Restart us\u0142ugi php-fpm:<\/p>\n<pre class=\"lang:sh decode:true \">$ sudo systemctl restart php72-php-fpm.service<\/pre>\n<p>Edycja konfigu NGINX:<\/p>\n<pre class=\"lang:sh decode:true\">$ sudo vim \/etc\/nginx\/nginx.conf<\/pre>\n<p>Po linii:<\/p>\n<pre class=\"lang:sh decode:true \">include \/etc\/nginx\/conf.d\/*.conf;<\/pre>\n<p>dodajemy:<\/p>\n<pre class=\"lang:sh decode:true\">include \/etc\/nginx\/sites-enabled\/*;<\/pre>\n<p>Komentujemy lub usuwamy linie:<\/p>\n<pre class=\"lang:sh decode:true \"># server {\r\n# listen 80 default_server;\r\n# listen [::]:80 default_server;\r\n# server_name _;\r\n# root \/usr\/share\/nginx\/html;\r\n#\r\n# # Load configuration files for the default server block.\r\n# include \/etc\/nginx\/default.d\/*.conf;\r\n#\r\n# location \/ {\r\n# }\r\n#\r\n# error_page 404 \/404.html;\r\n# location = \/40x.html {\r\n# }\r\n#\r\n# error_page 500 502 503 504 \/50x.html;\r\n# location = \/50x.html {\r\n# }\r\n# }<\/pre>\n<p>Zak\u0142adamy katalog na logi wirtualnego serwera domain.com:<\/p>\n<pre class=\"lang:sh decode:true \">$ sudo mkdir \/var\/log\/nginx\/domain.com\/<\/pre>\n<p>W katalogu \/etc\/nginx zak\u0142adamy katalogi sites-available i sites-enabled:<\/p>\n<pre class=\"lang:sh decode:true\">$ sudo mkdir \/etc\/nginx\/sites-available\r\n$ sudo mkdir \/etc\/nginx\/sites-enabled<\/pre>\n<p>Przyk\u0142ad konfigu<code> \/etc\/nginx\/sites-available\/domain.com.vhost<\/code> serwera wirtualnego:<\/p>\n<pre class=\"lang:sh decode:true\">server {\r\nlisten *:80;\r\nserver_name domain.com www.domain.com name.domain.com;\r\n\r\nroot \/home\/domain.com\/public_html;\r\nindex index.html index.htm index.php index.cgi index.pl index.xhtml;\r\n\r\nerror_log \/var\/log\/nginx\/domain.com\/error.log;\r\naccess_log \/var\/log\/nginx\/domain.com\/access.log combined;\r\n\r\n# in root location\r\nlocation \/ {\r\n# look for index.php\/index.html\/index.htm as \"index file\"\r\nindex index.php index.html index.htm;\r\n\r\n# this is specifically for wordpress\r\n# makes it possible to have url rewrites\r\ntry_files $uri $uri\/ \/index.php?$args;\r\n}\r\n\r\n# default error pages\r\n# note that wp already catches most\r\nerror_page 404 \/404.html;\r\nerror_page 500 502 503 504 \/50x.html;\r\nlocation = \/50x.html {\r\nroot \/usr\/share\/nginx\/html;\r\n}\r\n# here we have to let nginx know what to do with these php files\r\n# as html files are just send directly to the client\r\nlocation ~ \\.php$ {\r\n# if the file is not there show a error : mynonexistingpage.php -&gt; 404\r\ntry_files $uri =404;\r\n\r\n# pass to the php-fpm server\r\nfastcgi_pass 127.0.0.1:9000;\r\n# also for fastcgi try index.php\r\nfastcgi_index index.php;\r\n# some tweaking\r\nfastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\r\nfastcgi_param SCRIPT_NAME $fastcgi_script_name;\r\nfastcgi_buffer_size 128k;\r\nfastcgi_buffers 256 16k;\r\nfastcgi_busy_buffers_size 256k;\r\nfastcgi_temp_file_write_size 256k;\r\ninclude fastcgi_params;\r\n}\r\n}<\/pre>\n<p>Po dodaniu pliku konfiguracyjnego dodajemy link symboliczny do konfigu serwera wirtualnego domain.com:<\/p>\n<pre class=\"lang:sh decode:true\">$ sudo ln -s \/etc\/nginx\/sites-available\/domain.com.vhost \/etc\/nginx\/sites-enabled\/domain.com.vhost<\/pre>\n<p>Dodajmy jeszcze domy\u015blny serwer wirtualny\u00a0<code>\/etc\/nginx\/sites-available\/default.vhost<\/code>:<\/p>\n<pre class=\"lang:sh decode:true \"># Default server configuration\r\n#\r\nserver {\r\nlisten 80 default_server;\r\nlisten [::]:80 default_server;\r\n\r\n\r\nroot \/var\/www\/html;\r\n\r\n# Add index.php to the list if you are using PHP\r\nindex index.html index.htm index.nginx-debian.html;\r\n\r\nserver_name _;\r\n\r\n# in root location\r\nlocation \/ {\r\n# look for index.php\/index.html\/index.htm as \"index file\"\r\nindex index.php index.html index.htm;\r\n# this is specifically for wordpress\r\n# makes it possible to have url rewrites\r\ntry_files $uri $uri\/ \/index.php?$args;\r\n}\r\n\r\n# default error pages\r\n# note that wp already catches most\r\nerror_page 404 \/404.html;\r\nerror_page 500 502 503 504 \/50x.html;\r\nlocation = \/50x.html {\r\nroot \/usr\/share\/nginx\/html;\r\n}\r\n# here we have to let nginx know what to do with these php files\r\n# as html files are just send directly to the client\r\nlocation ~ \\.php$ {\r\n# if the file is not there show a error : mynonexistingpage.php -&gt; 404\r\ntry_files $uri =404;\r\n\r\n# pass to the php-fpm server\r\nfastcgi_pass 127.0.0.1:9000;\r\n# also for fastcgi try index.php\r\nfastcgi_index index.php;\r\n# some tweaking\r\nfastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\r\nfastcgi_param SCRIPT_NAME $fastcgi_script_name;\r\nfastcgi_buffer_size 128k;\r\nfastcgi_buffers 256 16k;\r\nfastcgi_busy_buffers_size 256k;\r\nfastcgi_temp_file_write_size 256k;\r\ninclude fastcgi_params;\r\n}\r\n\r\n}<\/pre>\n<p>Link symboliczny:<\/p>\n<pre class=\"lang:sh decode:true\">$ sudo ln -s \/etc\/nginx\/sites-available\/default.vhost \/etc\/nginx\/sites-enabled\/default.vhost<\/pre>\n<p>Restart NGINX-a:<\/p>\n<pre class=\"lang:sh decode:true \">$ sudo systemctl restart nginx<\/pre>\n<p>Mo\u017cemy utworzy\u0107 skrypt testowy foo.php:<\/p>\n<pre class=\"lang:sh decode:true\">$ sudo vim \/var\/www\/html\/foo.php<\/pre>\n<p>O zawarto\u015bci:<\/p>\n<pre class=\"lang:sh decode:true\">&lt;?php\r\nphpinfo();\r\n?&gt;<\/pre>\n<p>Zapisujemy i zamykamy plik. W przegl\u0105darce wpisujemy adres URL:<br \/>\nhttp:\/\/your-domain-name\/foo.php<br \/>\nhttp:\/\/10.21.136.134\/foo.php<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP to akronim od s\u0142\u00f3w PHP: Hypertext Preprocessor, jest mechanizmem dzia\u0142aj\u0105cym po stronie\u00a0 serwera. W PHP mo\u017cna tworzy\u0107 strony internetowe generowane dynamicznie lub osadza\u0107 skrypty PHP\u00a0 bezpo\u015brednio w kodzie\u00a0 HTML. PHP mo\u017cna zintegrowa\u0107 z komercyjnymi i nie komercyjnymi systemami zarz\u0105dzania bazami danych. Domy\u015blnie CentOS 7\/RHEL 7 dostarcza PHP tylko w wersji 5.4. Artyku\u0142 wyja\u015bnia jak &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/miro.borodziuk.eu\/index.php\/2018\/05\/23\/instalacja-nginx-php-7-2-na-centos-7-rhel-7\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Instalacja Nginx + PHP 7.2 na CentOS 7 \/ RHEL 7&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":2122,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[48],"tags":[],"_links":{"self":[{"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/posts\/2121"}],"collection":[{"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/comments?post=2121"}],"version-history":[{"count":10,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/posts\/2121\/revisions"}],"predecessor-version":[{"id":2132,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/posts\/2121\/revisions\/2132"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/media\/2122"}],"wp:attachment":[{"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/media?parent=2121"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/categories?post=2121"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/tags?post=2121"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}