{"id":3533,"date":"2017-09-14T22:52:25","date_gmt":"2017-09-14T22:52:25","guid":{"rendered":"https:\/\/qbytes.cloud\/?p=3533"},"modified":"2017-09-14T22:52:25","modified_gmt":"2017-09-14T22:52:25","slug":"install-nginx-centos-7","status":"publish","type":"post","link":"https:\/\/www.qbytes.cloud\/index.php\/2017\/09\/14\/install-nginx-centos-7\/","title":{"rendered":"Install Nginx CentOS 7"},"content":{"rendered":"<p>Stop apache if running:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\"># systemctl stop httpd\n<\/pre>\n<p>Install epel if not installed:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\"># yum install epel-release\n<\/pre>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\"># yum install nginx\n<\/pre>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\"># systemctl enable nginx\n<\/pre>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\"># systemctl start nginx\n<\/pre>\n<p><!--more-->If you are running a firewall, run the following commands to allow HTTP and HTTPS traffic:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\"># firewall-cmd --permanent --zone=public --add-service=http \n# firewall-cmd --permanent --zone=public --add-service=https\n# firewall-cmd --reload\n\n<\/pre>\n<p>Open in a web browser:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nhttp:\/\/server_domain_name_or_IP\/\n\n<\/pre>\n<p>Configure gzip compression:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\"># nano \/etc\/nginx\/conf.d\/gzip.conf\n##\n# `gzip` Settings\n#\n#\ngzip on;\ngzip_disable &quot;msie6&quot;;\n\ngzip_vary on;\ngzip_proxied any;\ngzip_comp_level 6;\ngzip_http_version 1.1;\ngzip_min_length 256;\ngzip_types text\/plain text\/css application\/json application\/x-javascript text\/xml application\/xml application\/xml+rss text\/javascript application\/javascript application\/vnd.ms-fontobject application\/x-font-ttf font\/opentype image\/svg+xml image\/x-icon;\n<\/pre>\n<p>Restart:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\"># systemctl restart nginx\n<\/pre>\n<p>Configure default site block (replace domain with actual domain name):<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\"># nano \/etc\/nginx\/conf.d\/default.conf\nserver {\n    listen       80;\n    server_name  domain.com;\n\n    # note that these lines are originally from the &quot;location \/&quot; block\n    root   \/home\/domain\/public_html;\n    index index.php index.html index.htm;\n\n    location \/ {\n        try_files $uri $uri\/ \/index.php?q=$uri&amp;$args;\n    }\n    error_page 404 \/404.html;\n    error_page 500 502 503 504 \/50x.html;\n    location = \/50x.html {\n        root \/usr\/share\/nginx\/html;\n    }\n\n    location ~ \\.php$ {\n        try_files $uri =404;\n        fastcgi_pass unix:\/var\/run\/php-fpm\/php-fpm.sock;\n        fastcgi_index index.php;\n        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\n        include fastcgi_params;\n    }\n\n    location ~* \\.(js|css|png|jpg|jpeg|gif|ico)$ {\n        expires 30d;\n        add_header Cache-Control &quot;public, no-transform&quot;;\n   }\nlocation ~* \\.(jpg|jpeg|gif|png)$ {\nexpires 365d;\n}\n\nlocation ~* \\.(pdf|css|html|js|swf)$ {\nexpires 2d;\n}\n\n}\n\n<\/pre>\n<p>Change apache listening port and any other &#8220;.conf&#8221; files for virtual domains to listen on port 8080:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\"># nano \/etc\/httpd\/conf\/httpd.conf\nListen 8080\n<\/pre>\n<p>Restart apache:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">#systemctl restart httpd\n<\/pre>\n<p>Restart ngnix:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">#systemctl restart nginx\n<\/pre>\n<p>Test gzip:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">curl -H &quot;Accept-Encoding: gzip&quot; -I http:\/\/localhost\/test.html\nHTTP\/1.1 200 OK\nServer: nginx\/1.10.2\nDate: Fri, 15 Sep 2017 00:45:27 GMT\nContent-Type: html\nLast-Modified: Thu, 08 Jun 2017 16:46:42 GMT\nConnection: keep-alive\nVary: Accept-Encoding\nETag: W\/&quot;59397f72-4ddf&quot;\nContent-Encoding: gzip\n\n<\/pre>\n<p>Install php handler<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\"># yum install php php-mysql php-fpm\n<\/pre>\n<p>Configure the PHP Processor:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">nano \/etc\/php.ini\n<\/pre>\n<p>Uncomment and set from 1 to 0:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">cgi.fix_pathinfo=0\n<\/pre>\n<p>Next, open the php-fpm configuration file www.conf:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# nano \/etc\/php-fpm.d\/www.conf\n\n<\/pre>\n<p>Find the line that specifies the listen parameter, and change it so it looks like the following:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\/etc\/php-php.d\/www.conf \nlisten = \/var\/run\/php-fpm\/php-fpm.sock\n\n<\/pre>\n<p>Next, find the lines that set the listen.owner and listen.group and uncomment them. They should look like this:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\/etc\/php-php.d\/www.conf\nlisten.owner = nobody\nlisten.group = nobody\n\n<\/pre>\n<p>Lastly, find the lines that set the user and group and change their values from &#8220;apache&#8221; to &#8220;nginx&#8221;:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\/etc\/php-php.d\/www.conf\nuser = nginx\ngroup = nginx\nThen save and quit.\n\n<\/pre>\n<p>Now, we just need to start our PHP processor by typing:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# systemctl start php-fpm\n\n<\/pre>\n<p>This will implement the change that we made.<\/p>\n<p>Next, enable php-fpm to start on boot:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# systemctl enable php-fpm\n\n<\/pre>\n<p>Restart Nginx to make the necessary changes:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# systemctl restart nginx\n\n<\/pre>\n<p>Test PHP Processing on your Web Server<\/p>\n<p>Create an info php in the root directory:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\"># nano \/home\/domain\/public_html\/info.php\n<\/pre>\n<p>Open in a web browser:<br \/>\nhttp:\/\/domain.com\/info.php<br \/>\n<a href=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2017\/09\/Capture.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3549\" src=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2017\/09\/Capture.png\" alt=\"\" width=\"607\" height=\"27\" srcset=\"https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2017\/09\/Capture.png 607w, https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2017\/09\/Capture-300x13.png 300w\" sizes=\"auto, (max-width: 607px) 100vw, 607px\" \/><\/a><\/p>\n<p>This page basically gives you information about your server from the perspective of PHP. It is useful for debugging and to ensure that your settings are being applied correctly.<\/p>\n<p>If this was successful, then your PHP is working as expected.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Stop apache if running: # systemctl stop httpd Install epel if not installed: # yum install epel-release # yum install nginx # systemctl enable nginx # systemctl start nginx<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[74],"tags":[],"class_list":["post-3533","post","type-post","status-publish","format-standard","hentry","category-nginx"],"_links":{"self":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts\/3533","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/comments?post=3533"}],"version-history":[{"count":0,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts\/3533\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/media?parent=3533"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/categories?post=3533"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/tags?post=3533"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}