{"id":3553,"date":"2014-09-11T17:18:42","date_gmt":"2014-09-11T09:18:42","guid":{"rendered":"http:\/\/rmohan.com\/?p=3553"},"modified":"2014-09-11T17:33:16","modified_gmt":"2014-09-11T09:33:16","slug":"centos-7-lnmp%ef%bc%88nginxphpmysql%ef%bc%89","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=3553","title":{"rendered":"CENTOS 7 LNMP  (Nginx -PHP -MySQL)"},"content":{"rendered":"<p>rpm -Uvh http:\/\/nginx.org\/packages\/centos\/7\/noarch\/RPMS\/nginx-release-centos-7-0.el7.ngx.noarch.rpm<\/p>\n<p>systemctl start nginx.service<\/p>\n<p>systemctl stop httpd.service<br \/>\nyum remove httpd<br \/>\nsystemctl disable httpd.service<br \/>\nroot@centos71 ~]# systemctl start nginx.service<br \/>\n[root@centos71 ~]# systemctl restart nginx.service<br \/>\n[root@centos71 ~]# systemctl status nginx.service<br \/>\nnginx.service &#8211; nginx &#8211; high performance web server<br \/>\nLoaded: loaded (\/usr\/lib\/systemd\/system\/nginx.service; disabled)<br \/>\nActive: active (running) since Thu 2014-09-11 14:32:02 SGT; 8s ago<br \/>\nDocs: http:\/\/nginx.org\/en\/docs\/<br \/>\nProcess: 38314 ExecStop=\/bin\/kill -s QUIT $MAINPID (code=exited, status=0\/SUCCESS)<br \/>\nProcess: 38319 ExecStart=\/usr\/sbin\/nginx -c \/etc\/nginx\/nginx.conf (code=exited, status=0\/SUCCESS)<br \/>\nProcess: 38318 ExecStartPre=\/usr\/sbin\/nginx -t -c \/etc\/nginx\/nginx.conf (code=exited, status=0\/SUCCESS)<br \/>\nMain PID: 38322 (nginx)<br \/>\nCGroup: \/system.slice\/nginx.service<br \/>\n??38322 nginx: master process \/usr\/sbin\/nginx -c \/etc\/nginx\/nginx.conf<br \/>\n??38323 nginx: worker process<\/p>\n<p>Sep 11 14:32:02 centos71.rmohan.com systemd[1]: Starting nginx &#8211; high performance web server&#8230;<br \/>\nSep 11 14:32:02 centos71.rmohan.com nginx[38318]: nginx: the configuration file \/etc\/nginx\/nginx.conf syntax is ok<br \/>\nSep 11 14:32:02 centos71.rmohan.com nginx[38318]: nginx: configuration file \/etc\/nginx\/nginx.conf test is successful<br \/>\nSep 11 14:32:02 centos71.rmohan.com systemd[1]: Failed to read PID from file \/run\/nginx.pid: Invalid argument<br \/>\nSep 11 14:32:02 centos71.rmohan.com systemd[1]: Started nginx &#8211; high performance web server.<\/p>\n<p>Enable Firewall Rule<\/p>\n<p>[root@centos71 ~]# firewall-cmd &#8211;permanent &#8211;zone=public &#8211;add-service=http<br \/>\nsuccess<\/p>\n<p>[root@centos71 ~]# firewall-cmd &#8211;permanent &#8211;zone=public &#8211;add-service=https<br \/>\nsuccess<\/p>\n<p>[root@centos71 ~]# firewall-cmd &#8211;reload<br \/>\nsuccess<br \/>\nhttp:\/\/192.168.1.9\/<br \/>\nWelcome to nginx!<\/p>\n<p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.<\/p>\n<p>For online documentation and support please refer to nginx.org.<br \/>\nCommercial support is available at nginx.com.<\/p>\n<p>Thank you for using nginx.<br \/>\n[root@centos71 ~]# ip addr show eno16777736 | grep inet | awk &#8216;{ print $2; }&#8217; | sed &#8216;s\/\\\/.*$\/\/&#8217;<br \/>\n192.168.1.9<br \/>\nfe80::20c:29ff:fe7c:a85a<\/p>\n<p>Setting the root password ensures that nobody can log into the MariaDB<br \/>\nroot user without the proper authorisation.<\/p>\n<p>Set root password? [Y\/n]<br \/>\nNew password:<br \/>\nRe-enter new password:<br \/>\nSorry, passwords do not match.<\/p>\n<p>New password:<br \/>\nRe-enter new password:<br \/>\nPassword updated successfully!<br \/>\nReloading privilege tables..<br \/>\n&#8230; Success!<br \/>\nBy default, a MariaDB installation has an anonymous user, allowing anyone<br \/>\nto log into MariaDB without having to have a user account created for<br \/>\nthem. This is intended only for testing, and to make the installation<br \/>\ngo a bit smoother. You should remove them before moving into a<br \/>\nproduction environment.<\/p>\n<p>Remove anonymous users? [Y\/n] Y<br \/>\n&#8230; Success!<\/p>\n<p>Normally, root should only be allowed to connect from &#8216;localhost&#8217;. This<br \/>\nensures that someone cannot guess at the root password from the network.<\/p>\n<p>Disallow root login remotely? [Y\/n] Y<br \/>\n&#8230; Success!<\/p>\n<p>By default, MariaDB comes with a database named &#8216;test&#8217; that anyone can<br \/>\naccess. This is also intended only for testing, and should be removed<br \/>\nbefore moving into a production environment.<\/p>\n<p>Remove test database and access to it? [Y\/n] Y<br \/>\n&#8211; Dropping test database&#8230;<br \/>\n&#8230; Success!<br \/>\n&#8211; Removing privileges on test database&#8230;<br \/>\n&#8230; Success!<\/p>\n<p>Reloading the privilege tables will ensure that all changes made so far<br \/>\nwill take effect immediately.<\/p>\n<p>Reload privilege tables now? [Y\/n] Y<br \/>\n&#8230; Success!<\/p>\n<p>Cleaning up&#8230;<\/p>\n<p>All done! If you&#8217;ve completed all of the above steps, your MariaDB<br \/>\ninstallation should now be secure.<\/p>\n<p>Thanks for using MariaDB!<\/p>\n<p>[root@centos71 ~]# systemctl enable mariadb.service<br \/>\nln -s &#8216;\/usr\/lib\/systemd\/system\/mariadb.service&#8217; &#8216;\/etc\/systemd\/system\/multi-user.target.wants\/mariadb.service&#8217;<br \/>\n[root@centos71 ~]# systemctl restart mariadb.service<br \/>\n[root@centos71 ~]# systemctl status mariadb.service<br \/>\nmariadb.service &#8211; MariaDB database server<br \/>\nLoaded: loaded (\/usr\/lib\/systemd\/system\/mariadb.service; enabled)<br \/>\nActive: active (running) since Thu 2014-09-11 14:57:59 SGT; 6s ago<br \/>\nProcess: 39423 ExecStartPost=\/usr\/libexec\/mariadb-wait-ready $MAINPID (code=exited, status=0\/SUCCESS)<br \/>\nProcess: 39395 ExecStartPre=\/usr\/libexec\/mariadb-prepare-db-dir %n (code=exited, status=0\/SUCCESS)<br \/>\nMain PID: 39422 (mysqld_safe)<br \/>\nCGroup: \/system.slice\/mariadb.service<br \/>\n??39422 \/bin\/sh \/usr\/bin\/mysqld_safe &#8211;basedir=\/usr<br \/>\n??39580 \/usr\/libexec\/mysqld &#8211;basedir=\/usr &#8211;datadir=\/var\/lib\/mysql &#8211;plugin-dir=\/usr\/lib64\/mysql\/plugin &#8211;log-error=\/var\/log\/mariadb\/mariadb.log &#8211;pid-file=\/var\/&#8230;<\/p>\n<p>Sep 11 14:57:57 centos71.rmohan.com mysqld_safe[39422]: 140911 14:57:57 mysqld_safe Logging to &#8216;\/var\/log\/mariadb\/mariadb.log&#8217;.<br \/>\nSep 11 14:57:57 centos71.rmohan.com mysqld_safe[39422]: 140911 14:57:57 mysqld_safe Starting mysqld daemon with databases from \/var\/lib\/mysql<br \/>\nSep 11 14:57:59 centos71.rmohan.com systemd[1]: Started MariaDB database server.<br \/>\n[root@centos71 ~]#<br \/>\n[root@centos71 ~]# yum install php php-mysql php-fpm<br \/>\nLoaded plugins: fastestmirror, langpacks<br \/>\nLoading mirror speeds from cached hostfile<br \/>\n* base: buaya.klas.or.id<br \/>\n* extras: repo.apiknet.co.id<br \/>\n* updates: kartolo.sby.datautama.net.id<br \/>\nResolving Dependencies<br \/>\n&#8211;&gt; Running transaction check<br \/>\n&#8212;&gt; Package php.x86_64 0:5.4.16-23.el7_0 will be installed<br \/>\n&#8211;&gt; Processing Dependency: php-common(x86-64) = 5.4.16-23.el7_0 for package: php-5.4.16-23.el7_0.x86_64<br \/>\n&#8211;&gt; Processing Dependency: php-cli(x86-64) = 5.4.16-23.el7_0 for package: php-5.4.16-23.el7_0.x86_64<br \/>\n&#8211;&gt; Processing Dependency: httpd-mmn = 20120211&#215;8664 for package: php-5.4.16-23.el7_0.x86_64<br \/>\n&#8211;&gt; Processing Dependency: httpd for package: php-5.4.16-23.el7_0.x86_64<br \/>\n&#8212;&gt; Package php-fpm.x86_64 0:5.4.16-23.el7_0 will be installed<br \/>\n&#8212;&gt; Package php-mysql.x86_64 0:5.4.16-23.el7_0 will be installed<br \/>\n&#8211;&gt; Processing Dependency: php-pdo(x86-64) = 5.4.16-23.el7_0 for package: php-mysql-5.4.16-23.el7_0.x86_64<br \/>\n&#8211;&gt; Running transaction check<br \/>\n&#8212;&gt; Package httpd.x86_64 0:2.4.6-18.el7.centos will be installed<br \/>\n&#8211;&gt; Processing Dependency: httpd-tools = 2.4.6-18.el7.centos for package: httpd-2.4.6-18.el7.centos.x86_64<br \/>\n&#8211;&gt; Processing Dependency: \/etc\/mime.types for package: httpd-2.4.6-18.el7.centos.x86_64<br \/>\n&#8211;&gt; Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-18.el7.centos.x86_64<br \/>\n&#8211;&gt; Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-18.el7.centos.x86_64<br \/>\n&#8212;&gt; Package php-cli.x86_64 0:5.4.16-23.el7_0 will be installed<br \/>\n&#8212;&gt; Package php-common.x86_64 0:5.4.16-23.el7_0 will be installed<br \/>\n&#8211;&gt; Processing Dependency: libzip.so.2()(64bit) for package: php-common-5.4.16-23.el7_0.x86_64<br \/>\n&#8212;&gt; Package php-pdo.x86_64 0:5.4.16-23.el7_0 will be installed<br \/>\n&#8211;&gt; Running transaction check<br \/>\n&#8212;&gt; Package apr.x86_64 0:1.4.8-3.el7 will be installed<br \/>\n&#8212;&gt; Package apr-util.x86_64 0:1.5.2-6.el7 will be installed<br \/>\n&#8212;&gt; Package httpd-tools.x86_64 0:2.4.6-18.el7.centos will be installed<br \/>\n&#8212;&gt; Package libzip.x86_64 0:0.10.1-8.el7 will be installed<br \/>\n&#8212;&gt; Package mailcap.noarch 0:2.1.41-2.el7 will be installed<br \/>\n&#8211;&gt; Finished Dependency Resolution<\/p>\n<p>Dependencies Resolved<\/p>\n<p>================================================================================================================================================================================<br \/>\nPackage Arch Version Repository Size<br \/>\n================================================================================================================================================================================<br \/>\nInstalling:<br \/>\nphp x86_64 5.4.16-23.el7_0 updates 1.3 M<br \/>\nphp-fpm x86_64 5.4.16-23.el7_0 updates 1.4 M<br \/>\nphp-mysql x86_64 5.4.16-23.el7_0 updates 96 k<br \/>\nInstalling for dependencies:<br \/>\napr x86_64 1.4.8-3.el7 base 103 k<br \/>\napr-util x86_64 1.5.2-6.el7 base 92 k<br \/>\nhttpd x86_64 2.4.6-18.el7.centos updates 2.7 M<br \/>\nhttpd-tools x86_64 2.4.6-18.el7.centos updates 77 k<br \/>\nlibzip x86_64 0.10.1-8.el7 base 48 k<br \/>\nmailcap noarch 2.1.41-2.el7 base 31 k<br \/>\nphp-cli x86_64 5.4.16-23.el7_0 updates 2.7 M<br \/>\nphp-common x86_64 5.4.16-23.el7_0 updates 560 k<br \/>\nphp-pdo x86_64 5.4.16-23.el7_0 updates 94 k<\/p>\n<p>Transaction Summary<br \/>\n================================================================================================================================================================================<br \/>\nInstall 3 Packages (+9 Dependent packages)<\/p>\n<p>Total download size: 9.3 M<br \/>\nInstalled size: 32 M<br \/>\nIs this ok [y\/d\/N]: y<br \/>\nDownloading packages:<br \/>\n(1\/12): apr-util-1.5.2-6.el7.x86_64.rpm | 92 kB 00:00:00<br \/>\n(2\/12): httpd-tools-2.4.6-18.el7.centos.x86_64.rpm | 77 kB 00:00:00<br \/>\n(3\/12): libzip-0.10.1-8.el7.x86_64.rpm | 48 kB 00:00:00<br \/>\n(4\/12): mailcap-2.1.41-2.el7.noarch.rpm | 31 kB 00:00:00<br \/>\n(5\/12): apr-1.4.8-3.el7.x86_64.rpm | 103 kB 00:00:01<br \/>\n(6\/12): php-5.4.16-23.el7_0.x86_64.rpm | 1.3 MB 00:00:01<br \/>\n(7\/12): php-common-5.4.16-23.el7_0.x86_64.rpm | 560 kB 00:00:02<br \/>\n(8\/12): php-mysql-5.4.16-23.el7_0.x86_64.rpm | 96 kB 00:00:05<br \/>\n(9\/12): php-pdo-5.4.16-23.el7_0.x86_64.rpm | 94 kB 00:00:04<br \/>\n(10\/12): php-fpm-5.4.16-23.el7_0.x86_64.rpm | 1.4 MB 00:00:15<br \/>\n(11\/12): php-cli-5.4.16-23.el7_0.x86_64.rpm | 2.7 MB 00:00:18<br \/>\n(12\/12): httpd-2.4.6-18.el7.centos.x86_64.rpm | 2.7 MB 00:00:24<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nTotal 392 kB\/s | 9.3 MB 00:00:24<br \/>\nRunning transaction check<br \/>\nRunning transaction test<br \/>\nTransaction test succeeded<br \/>\nRunning transaction<br \/>\nInstalling : apr-1.4.8-3.el7.x86_64 1\/12<br \/>\nInstalling : apr-util-1.5.2-6.el7.x86_64 2\/12<br \/>\nInstalling : httpd-tools-2.4.6-18.el7.centos.x86_64 3\/12<br \/>\nInstalling : libzip-0.10.1-8.el7.x86_64 4\/12<br \/>\nInstalling : php-common-5.4.16-23.el7_0.x86_64 5\/12<br \/>\nInstalling : php-cli-5.4.16-23.el7_0.x86_64 6\/12<br \/>\nInstalling : php-pdo-5.4.16-23.el7_0.x86_64 7\/12<br \/>\nInstalling : mailcap-2.1.41-2.el7.noarch 8\/12<br \/>\nInstalling : httpd-2.4.6-18.el7.centos.x86_64 9\/12<br \/>\nInstalling : php-5.4.16-23.el7_0.x86_64 10\/12<br \/>\nInstalling : php-mysql-5.4.16-23.el7_0.x86_64 11\/12<br \/>\nInstalling : php-fpm-5.4.16-23.el7_0.x86_64 12\/12<br \/>\nVerifying : php-common-5.4.16-23.el7_0.x86_64 1\/12<br \/>\nVerifying : php-mysql-5.4.16-23.el7_0.x86_64 2\/12<br \/>\nVerifying : apr-1.4.8-3.el7.x86_64 3\/12<br \/>\nVerifying : mailcap-2.1.41-2.el7.noarch 4\/12<br \/>\nVerifying : php-cli-5.4.16-23.el7_0.x86_64 5\/12<br \/>\nVerifying : apr-util-1.5.2-6.el7.x86_64 6\/12<br \/>\nVerifying : php-5.4.16-23.el7_0.x86_64 7\/12<br \/>\nVerifying : libzip-0.10.1-8.el7.x86_64 8\/12<br \/>\nVerifying : php-pdo-5.4.16-23.el7_0.x86_64 9\/12<br \/>\nVerifying : httpd-tools-2.4.6-18.el7.centos.x86_64 10\/12<br \/>\nVerifying : php-fpm-5.4.16-23.el7_0.x86_64 11\/12<br \/>\nVerifying : httpd-2.4.6-18.el7.centos.x86_64 12\/12<\/p>\n<p>Installed:<br \/>\nphp.x86_64 0:5.4.16-23.el7_0 php-fpm.x86_64 0:5.4.16-23.el7_0 php-mysql.x86_64 0:5.4.16-23.el7_0<\/p>\n<p>Dependency Installed:<br \/>\napr.x86_64 0:1.4.8-3.el7 apr-util.x86_64 0:1.5.2-6.el7 httpd.x86_64 0:2.4.6-18.el7.centos httpd-tools.x86_64 0:2.4.6-18.el7.centos libzip.x86_64 0:0.10.1-8.el7<br \/>\nmailcap.noarch 0:2.1.41-2.el7 php-cli.x86_64 0:5.4.16-23.el7_0 php-common.x86_64 0:5.4.16-23.el7_0 php-pdo.x86_64 0:5.4.16-23.el7_0<\/p>\n<p>Complete!<\/p>\n<p>vim \/etc\/php.ini<br \/>\nby uncommenting the line and setting it to &#8220;0&#8221; like this:<\/p>\n<p>cgi.fix_pathinfo=0<\/p>\n<p>vi \/etc\/php-fpm.d\/www.conf<br \/>\nFind the line that specifies the listen parameter, and change it so it looks like the following:<\/p>\n<p>listen = \/var\/run\/php-fpm\/php-fpm.sock<br \/>\nsystemctl start php-fpm<br \/>\nsystemctl restart php-fpm<br \/>\nsystemctl status php-fpm<br \/>\nsystemctl enable php-fpm.service<br \/>\ncp \/etc\/nginx\/conf.d\/default.conf \/etc\/nginx\/conf.d\/default.conf.org<br \/>\nserver {<br \/>\nlisten 80;<br \/>\nserver_name 192.168.1.9;<\/p>\n<p>root \/usr\/share\/nginx\/html;<br \/>\nindex index.php index.html index.htm;<\/p>\n<p>location \/ {<br \/>\ntry_files $uri $uri\/ =404;<br \/>\n}<br \/>\nerror_page 404 \/404.html;<br \/>\nerror_page 500 502 503 504 \/50x.html;<br \/>\nlocation = \/50x.html {<br \/>\nroot \/usr\/share\/nginx\/html;<br \/>\n}<\/p>\n<p>location ~ \\.php$ {<br \/>\ntry_files $uri =404;<br \/>\nfastcgi_pass unix:\/var\/run\/php-fpm\/php-fpm.sock;<br \/>\nfastcgi_index index.php;<br \/>\nfastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;<br \/>\ninclude fastcgi_params;<br \/>\n}<br \/>\n}<br \/>\nWe will call this script info.php. In order for Apache to find the file and serve it correctly, it must be saved to a very specific directory, which is called the &#8220;web root&#8221;.<\/p>\n<p>In CentOS 7, this directory is located at \/usr\/share\/nginx\/html\/.<br \/>\nWe can create the file at that location by typing:<br \/>\nsudo vi \/usr\/share\/nginx\/html\/info.php<\/p>\n","protected":false},"excerpt":{"rendered":"<p>rpm -Uvh http:\/\/nginx.org\/packages\/centos\/7\/noarch\/RPMS\/nginx-release-centos-7-0.el7.ngx.noarch.rpm<\/p>\n<p>systemctl start nginx.service<\/p>\n<p>systemctl stop httpd.service yum remove httpd systemctl disable httpd.service root@centos71 ~]# systemctl start nginx.service [root@centos71 ~]# systemctl restart nginx.service [root@centos71 ~]# systemctl status nginx.service nginx.service &#8211; nginx &#8211; high performance web server Loaded: loaded (\/usr\/lib\/systemd\/system\/nginx.service; disabled) Active: active (running) since Thu 2014-09-11 14:32:02 SGT; 8s ago Docs: http:\/\/nginx.org\/en\/docs\/ Process: [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/3553"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3553"}],"version-history":[{"count":2,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/3553\/revisions"}],"predecessor-version":[{"id":3555,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/3553\/revisions\/3555"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3553"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3553"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}