{"id":51,"date":"2017-11-05T21:44:07","date_gmt":"2017-11-05T13:44:07","guid":{"rendered":"https:\/\/zoco.me\/?p=51"},"modified":"2017-11-05T21:44:07","modified_gmt":"2017-11-05T13:44:07","slug":"centos-7-config-lnmp-linux-nginx-mysql-php","status":"publish","type":"post","link":"https:\/\/cloudbool.com\/archive\/centos-7-config-lnmp-linux-nginx-mysql-php.html","title":{"rendered":"CentOS 7 \u7cfb\u7edf\u914d\u7f6eLNMP"},"content":{"rendered":"<p>\u5176\u5b9e\u6211\u662f\u66f4\u559c\u6b22Debian\u7684\uff0c\u5c24\u5176\u662f\u521a\u53d1\u5e03\u4e0d\u4e45\u7684Debian9\uff0c\u6bd5\u7adf\u548cCentOS\u76f8\u6bd4\uff0cDebian9\u5b98\u65b9\u6e90\u7684\u5305\u591a\u4e14\u65b0\uff0c\u6ee1\u8db3\u4e86\u6211\u5bf9Linux\u7cfb\u7edf\u7684\u6240\u6709\u9700\u6c42\u3002<\/p>\n<p>\u4f46\u662f\u7531\u4e8e\u5de5\u4f5c\u539f\u56e0\uff0c\u7528\u5f97\u66f4\u591a\u7684\u662fCentOS\uff0c\u5176\u4e2d\u6211\u65b0\u63a5\u624b\u7684\u9879\u76ee\u7528\u7684\u90fd\u662fCentOS7\uff0c\u6bd5\u7adfCentOS6\u76f8\u5bf9\u6765\u8bf4\u6709\u4e9b\u8fc7\u65f6\uff0c\u5f88\u591a\u5305\u7248\u672c\u90fd\u8fc7\u4f4e\uff0c\u5c24\u5176\u662f\u6211\u7684\u4e3b\u529b\u5f00\u53d1\u8bed\u8a00\uff0c\u8fd8\u662f5.3.x\u3002\u800c\u4e14CentOS7\u662f\u672a\u6765\uff0c\u5305\u542b\u4e86\u5f88\u591a\u65b0\u7279\u6027\uff0c\u7528\u65b0\u4e0d\u7528\u65e7\u561b\uff0c\u6240\u4ee5\u6211\u66f4\u591a\u7684\u662f\u9009\u62e9CentOS7\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u9996\u5148\u662f\u66f4\u65b0\u6574\u4e2a\u7cfb\u7edf\uff1a<\/p>\n<blockquote><p>\n  yum update -y\n<\/p><\/blockquote>\n<p>\u867d\u7136\u4e0d\u662f\u5fc5\u9700\uff0c\u4f46\u6211\u8fd8\u662f\u63a8\u8350\u5b89\u88c5EPEL\u6e90\uff0c\u80fd\u5f25\u8865\u7cfb\u7edf\u5b98\u65b9\u6e90\u7684\u5f88\u591a\u672a\u5305\u542b\u7684\u5305\uff1a<\/p>\n<blockquote><p>\n  yum install epel-release -y\n<\/p><\/blockquote>\n<h3>\u5b89\u88c5Nginx<\/h3>\n<p>\u63a5\u7740\u662f\u5b89\u88c5Nginx\uff0c\u867d\u7136\u5b89\u88c5EPEL\u4e4b\u540e\uff0c\u6e90\u91cc\u5c31\u81ea\u5e26\u4e86Nginx\uff0c\u4f46\u662f\uff0c\u51fa\u4e8e\u5404\u4e2a\u5e73\u53f0\u7684\u7edf\u4e00\u4ee5\u53ca\u7248\u672c\u7684\u8003\u8651\uff0c\u6211\u66f4\u503e\u5411\u5b89\u88c5Nginx\u5b98\u65b9\u6e90\u91cc\u7684\uff0c\u65b0\u5efa\u4e00\u4e2arepo\u6587\u4ef6\uff0c\u7136\u540e\u628a\u4e0b\u5217\u5185\u5bb9\u9ecf\u8d34\u8fdb\u53bb\uff1a<\/p>\n<pre><code>vim \/etc\/yum.repos.d\/nginx.repo\n\n[nginx]\nname=nginx repo\nbaseurl=http:\/\/nginx.org\/packages\/centos\/7\/$basearch\/\ngpgcheck=0\nenabled=1\n<\/code><\/pre>\n<p>\u8fd9\u6837\u5c31\u76f8\u5f53\u4e8e\u6dfb\u52a0\u4e86Nginx\u7684\u5b98\u65b9\u6e90\u3002\u5b98\u65b9\u76f8\u5173\u9875\u9762\u5728<a href=\"https:\/\/nginx.org\/en\/linux_packages.html#stable\">\u8fd9\u91cc<\/a>\u3002<\/p>\n<p>\u5b89\u88c5Nginx\uff1a<\/p>\n<blockquote><p>\n  yum install nginx -y\n<\/p><\/blockquote>\n<h3>\u6dfb\u52a0webtatic\u6e90\u53ca\u5b89\u88c5PHP 5.6<\/h3>\n<p>\u63a5\u4e0b\u6765\u662f\u5b89\u88c5PHP\u3002<\/p>\n<p>\u7531\u4e8eCentOS7\u5b98\u65b9\u6e90\u81ea\u5e26\u7684PHP\u7248\u672c\u592a\u4f4e\uff0c\u5f88\u591a\u60c5\u51b5\u4e0b\u4e0d\u80fd\u7b26\u5408\u6211\u4eec\u5bf9PHP\u7248\u672c\u7684\u9700\u6c42\uff0c\u6240\u4ee5\uff0c\u6211\u9009\u62e9\u7b2c\u4e09\u65b9\u6e90\u7684PHP\uff0c\u53ef\u4ee5\u81ea\u7531\u9009\u62e9PHP\u7684\u7248\u672c\u8fdb\u884c\u5b89\u88c5\uff0c\u540c\u6837\uff0c\u6dfb\u52a0\u6e90\uff1a<\/p>\n<blockquote><p>\n  rpm -Uvh https:\/\/mirror.webtatic.com\/yum\/el7\/webtatic-release.rpm\n<\/p><\/blockquote>\n<p>\u5982\u679c\u63d0\u793a\u5982\u4e0b\uff1a<\/p>\n<pre><code>[root@doams3 ~]# rpm -Uvh https:\/\/mirror.webtatic.com\/yum\/el7\/webtatic-release.rpm\nRetrieving https:\/\/mirror.webtatic.com\/yum\/el7\/webtatic-release.rpm\nwarning: \/var\/tmp\/rpm-tmp.eB1NCs: Header V4 RSA\/SHA1 Signature, key ID 62e74ca5: NOKEY\nerror: Failed dependencies:\n        epel-release &gt;= 7 is needed by webtatic-release-7-3.noarch\n<\/code><\/pre>\n<p>\u5219\u9700\u8981\u5148\u6dfb\u52a0EPEL\u6e90\uff1a<\/p>\n<blockquote><p>\n  yum install epel-release -y\n<\/p><\/blockquote>\n<p>\u518d\u6b21\u6267\u884c\u6dfb\u52a0webtatic\u6e90\u547d\u4ee4\u5c31\u597d\u4e86\u3002<\/p>\n<p>\u6267\u884c\u4e4b\u540e\uff0c\u5c31\u6dfb\u52a0\u4e86<strong><em>webtatic<\/em><\/strong>\u6e90\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\u662f\u9009\u62e9\u9700\u8981\u5b89\u88c5\u7684PHP\u7248\u672c\u3002<\/p>\n<p>\u7531\u4e8ewebtatic\u6e90\u652f\u6301\u5f88\u591a\u4e2a\u7248\u672c\uff0c\u5177\u4f53\u53ef\u4ee5\u901a\u8fc7\u641c\u7d22\u5305\u540d\u7684\u65b9\u5f0f\u67e5\u770b\uff0c\u6bd4\u5982\u8bf4\u6211\u60f3\u67e5\u8be2PHP 5.6\u7684\u60c5\u51b5\uff1a<\/p>\n<pre><code>[root@doams3 ~]# yum search php56w\nLoaded plugins: fastestmirror\nLoading mirror speeds from cached hostfile\n * base: centos.mirror.triple-it.nl\n * elrepo: ftp.nluug.nl\n * epel: ftp.nluug.nl\n * extras: centos.mirror.triple-it.nl\n * updates: centos.mirror.triple-it.nl\n * webtatic: uk.repo.webtatic.com\n========================================================== N\/S matched: php56w ==========================================================\nphp56w.x86_64 : PHP scripting language for creating dynamic web sites\nphp56w-bcmath.x86_64 : A module for PHP applications for using the bcmath library\nphp56w-cli.x86_64 : Command-line interface for PHP\nphp56w-common.x86_64 : Common files for PHP\nphp56w-fpm.x86_64 : PHP FastCGI Process Manager\nphp56w-gd.x86_64 : A module for PHP applications for using the gd graphics library\nphp56w-imap.x86_64 : A module for PHP applications that use IMAP\nphp56w-mbstring.x86_64 : A module for PHP applications which need multi-byte string handling\nphp56w-mcrypt.x86_64 : Standard PHP module provides mcrypt library support\nphp56w-mssql.x86_64 : MSSQL database module for PHP\nphp56w-mysql.x86_64 : A module for PHP applications that use MySQL databases\nphp56w-mysqlnd.x86_64 : A module for PHP applications that use MySQL databases\nphp56w-odbc.x86_64 : A module for PHP applications that use ODBC databases\nphp56w-opcache.x86_64 : An opcode cache Zend extension\nphp56w-pdo.x86_64 : A database access abstraction module for PHP applications\nphp56w-phpdbg.x86_64 : Interactive PHP debugger\nphp56w-process.x86_64 : Modules for PHP script using system process interfaces\nphp56w-pspell.x86_64 : A module for PHP applications for using pspell interfaces\nphp56w-recode.x86_64 : A module for PHP applications for using the recode library\nphp56w-snmp.x86_64 : A module for PHP applications that query SNMP-managed devices\nphp56w-soap.x86_64 : A module for PHP applications that use the SOAP protocol\nphp56w-tidy.x86_64 : Standard PHP module provides tidy library support\nphp56w-xml.x86_64 : A module for PHP applications which use XML\n<\/code><\/pre>\n<p>\u7ed3\u679c\u5c55\u793a\u4e86\u6211\u4eec\u80fd\u76f4\u63a5\u5b89\u88c5\u7684\u6240\u6709PHP5.6\u76f8\u5173\u5305\uff0c\u8f93\u5165\u5bf9\u5e94\u7684\u5305\u540d\u5373\u53ef\u5b89\u88c5\uff0c\u6bd4\u5982\uff1a<\/p>\n<blockquote><p>\n  yum install php56w-cli php56w-fpm php56w-mysql php56w-gd php56w-mbstring php56w-mcrypt php56w-opcache php56w-pdo php56w-xml\n<\/p><\/blockquote>\n<p>\u5982\u679c\u60f3\u8981\u5b89\u88c5PHP5.5\uff0c\u5219\u53ea\u9700\u5c06<strong><em>php56w<\/em><\/strong>\u6539\u6210<strong><em>php55w<\/em><\/strong>\u5373\u53ef\uff0cPHP 7.0\u548cPHP 7.1\u4e00\u6837\u7684\u3002<\/p>\n<h3>\u5b89\u88c5MariaDB<\/h3>\n<p>\u63a5\u4e0b\u6765\u662f\u5b89\u88c5LNMP\u4e2d\u7684MySQL\uff0c\u7531\u4e8eCentOS7\u5f00\u59cb\uff0cMySQL\u5728\u5b98\u65b9\u4ed3\u5e93\u88ab\u66ff\u6362\u6210\u4e86MariaDB\uff0c\u6211\u4eec\u76f4\u63a5MariaDB\uff1a<\/p>\n<blockquote><p>\n  yum install mariadb mariadb-server -y\n<\/p><\/blockquote>\n<p>\u5b89\u88c5\u5b8c\u4e86\u6240\u6709\u7ec4\u4ef6\u4e4b\u540e\uff0c\u6211\u4eec\u5f00\u59cb\u914d\u7f6e\u5404\u4e2a\u7ec4\u4ef6\u3002<\/p>\n<h3>\u914d\u7f6eNginx<\/h3>\n<p>\u901a\u8fc7\u6e90\u5b89\u88c5\u7684Nginx\uff0c\u9ed8\u8ba4\u914d\u7f6e\u6587\u4ef6\u76ee\u5f55\u5728<strong><em>\/etc\/nginx\/<\/em><\/strong>\uff0c\u4e3b\u914d\u7f6e\u6587\u4ef6\u662f<strong><em>\/etc\/nginx\/nginx.conf<\/em><\/strong>\uff0c\u6211\u4eec\u5c31\u4ece\u8fd9\u4e2a\u6587\u4ef6\u5f00\u59cb\u914d\u7f6e\u3002<\/p>\n<p>\u8fd9\u662fnginx.conf\u9ed8\u8ba4\u5185\u5bb9\uff1a<\/p>\n<pre><code><br \/>user  nginx;\nworker_processes  1;\n\nerror_log  \/var\/log\/nginx\/error.log warn;\npid        \/var\/run\/nginx.pid;\n\n\nevents {\n    worker_connections  1024;\n}\n\n\nhttp {\n    include       \/etc\/nginx\/mime.types;\n    default_type  application\/octet-stream;\n\n    log_format  main  '$remote_addr - $remote_user [$time_local] \"$request\" '\n                      '$status $body_bytes_sent \"$http_referer\" '\n                      '\"$http_user_agent\" \"$http_x_forwarded_for\"';\n\n    access_log  \/var\/log\/nginx\/access.log  main;\n\n    sendfile        on;\n    #tcp_nopush     on;\n\n    keepalive_timeout  65;\n\n    #gzip  on;\n\n    include \/etc\/nginx\/conf.d\/*.conf;\n}\n<\/code><\/pre>\n<p>\u6211\u4eec\u9700\u8981\u66f4\u6539\u4e00\u4e9b\u5185\u5bb9\u3002<\/p>\n<p>\u6dfb\u52a0\u4e00\u4e2a\u7528\u6765\u4e13\u95e8\u8fd0\u884cweb\u76f8\u5173\u4e14\u4e0d\u80fd\u767b\u9646\u7684\u7528\u6237<strong><em>www<\/em><\/strong>\uff1a<\/p>\n<blockquote><p>\n  useradd www -s \/sbin\/nologin\n<\/p><\/blockquote>\n<p>\u5c06nginx\u7684\u8fd0\u884c\u7528\u6237\u8bbe\u7f6e\u4e3a\u6211\u4eec\u521a\u6dfb\u52a0\u7684<strong><em>www<\/em><\/strong>\uff0c\u53ea\u9700\u5c06\u4e0a\u8ff0\u5185\u5bb9\u4e2d\u7684<strong><em>user<\/em><\/strong>\u540e\u9762\u7684nginx\u6539\u6210www\u5c31\u597d\u4e86\u3002<br \/>\n\u51fa\u4e8e\u6027\u80fd\u8003\u8651\uff0c\u6211\u4eec\u5e94\u8be5\u5145\u5206\u5229\u7528\u8d77\u670d\u52a1\u5668\u7684\u591a\u4e2a\u6838\u5fc3(\u5982\u679c\u6709\u7684\u8bdd)\uff0c\u5c06<strong><em>worker_processes<\/em><\/strong>\u540e\u9762\u7684\u6570\u5b57\u6539\u6210\u5bf9\u5e94CPU\u6838\u5fc3\u6570\u3002<br \/>\n\u518d\u8005\uff0c\u51fa\u4e8e\u9690\u85cfnginx\u7248\u672c\u53f7\u8003\u8651\uff0c\u6211\u4eec\u8fd8\u9700\u5728http\u533a\u57df\u5185\u6dfb\u52a0\u4e00\u884c\u914d\u7f6e\uff0c\u8ba9nginx\u9690\u85cf\u81ea\u8eab\u7248\u672c\u53f7\uff1a<\/p>\n<blockquote><p>\n  server_tokens  off;\n<\/p><\/blockquote>\n<p>\u6700\u7ec8\u7684nginx.conf\u6587\u4ef6\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<pre><code>user  www;\nworker_processes  1;\n\nerror_log  \/var\/log\/nginx\/error.log warn;\npid        \/var\/run\/nginx.pid;\n\nevents {\n    worker_connections  1024;\n}\n\nhttp {\n    include       \/etc\/nginx\/mime.types;\n    default_type  application\/octet-stream;\n\n    log_format  main  '$remote_addr - $remote_user [$time_local] \"$request\" '\n                      '$status $body_bytes_sent \"$http_referer\" '\n                      '\"$http_user_agent\" \"$http_x_forwarded_for\"';\n\n    access_log  \/var\/log\/nginx\/access.log  main;\n\n    sendfile        on;\n    #tcp_nopush     on;\n\n    keepalive_timeout  65;\n\n    gzip  on;\n\n    include \/etc\/nginx\/conf.d\/*.conf;\n\n    server_tokens  off;\n}\n<\/code><\/pre>\n<h3>\u914d\u7f6ePHP<\/h3>\n<p>\u56e0\u4e3a\u6211\u4eec\u662f\u5229\u7528Nginx\u642d\u914dPHP-FPM\u5de5\u4f5c\uff0c\u6240\u4ee5\uff0c\u8fd8\u9700\u8981\u5bf9PHP\u53caPHP-FPM\u8fdb\u884c\u76f8\u5e94\u914d\u7f6e\u3002PHP\u76f8\u5173\u914d\u7f6e\u6587\u4ef6\u90fd\u5728\/etc\u6216\u8005\/etc\/php&#42;\u76ee\u5f55\u4e0b\uff0c\u6211\u4eec\u9700\u8981\u5bf9\u8fd9\u4e9b\u6587\u4ef6\u8fdb\u884c\u4fee\u6539\u3002<\/p>\n<p>\u9996\u5148\u66f4\u6539<strong><em>\/etc\/php.ini<\/em><\/strong>\uff0c\u91cc\u9762\u6709\u4e00\u884c<strong><em>cgi.fix_pathinfo=1<\/em><\/strong>\uff0c\u6211\u4eec\u9700\u8981\u5c06\u5176\u627e\u5230\uff0c\u5e76\u5c06\u5176\u503c\u6539\u62100\uff0c\u5927\u6982\u5728774\u884c\uff0c\u627e\u5230\uff0c\u5c06\u5176\u4fee\u6539\uff1a<\/p>\n<blockquote><p>\n  cgi.fix_pathinfo=0\n<\/p><\/blockquote>\n<p>\u9690\u85cfPHP\u7248\u672c\u53f7\uff1a<\/p>\n<pre><code>expose_php = Off\n<\/code><\/pre>\n<p>\u4fee\u6539PHP-FPM\u914d\u7f6e\uff0c\u914d\u7f6ePHP-FPM\u4ee5nginx\u76f8\u540c\u7684\u7528\u6237\u8fd0\u884c\uff1a<\/p>\n<blockquote><p>\n  vim \/etc\/php-fpm.d\/www.conf\n<\/p><\/blockquote>\n<p>\u5c06\u8fd9\u4e00\u6bb5\u7684apache\u6539\u6210www\u4e5f\u5c31\u662f\u6211\u4eec\u521a\u521a\u6dfb\u52a0\u7684\u7528\u6237\uff1a<\/p>\n<pre><code>; Unix user\/group of processes\n; Note: The user is mandatory. If the group is not set, the default user's group\n;       will be used.\n; RPM: apache Choosed to be able to access some dir as httpd\nuser = www\n; RPM: Keep a group allowed to write in log dir.\ngroup = www\n<\/code><\/pre>\n<p>\u6ce8\u610f\uff0c\u8fd9\u4e2a\u914d\u7f6e\u6587\u4ef6\u4e2d\u6709\u4e00\u884c\uff0c\u51b3\u5b9a\u4e86PHP-FPM\u7684\u76d1\u542c\u65b9\u5f0f\uff1a<\/p>\n<blockquote><p>\n  listen = 127.0.0.1:9000\n<\/p><\/blockquote>\n<p>\u8fd9\u4e00\u9879\u914d\u7f6e\u6d89\u53ca\u5230\u540e\u9762Nginx\u7684\u914d\u7f6e\uff0cPHP-FPM\u662f\u76d1\u542c\u7aef\u53e3\u8fd8\u662f\u4ee5sockets\u65b9\u5f0f\u8fd0\u884c\u8fd9\u91cc\u4e0d\u505a\u8ba8\u8bba\uff0c\u6709\u9700\u6c42\u7684\u81ea\u884cGoogle\uff0c\u6211\u8fd9\u91cc\u7528\u9ed8\u8ba4\u7684\u7aef\u53e3\u5f62\u5f0f\u3002\u5982\u679c\u9700\u8981\u6539\u6210socket\u5f62\u5f0f\uff0c\u6ce8\u610f\u8def\u5f84\u53ca\u76f8\u5e94\u76ee\u5f55\u6743\u9650\u3002<\/p>\n<h3>\u914d\u7f6eMariaDB<\/h3>\n<p>\u5176\u5b9e\u4e5f\u5c31\u662fMariaDB\u7684\u521d\u59cb\u5316\uff0c\u4ee5\u53ca\u76f8\u5e94\u914d\u7f6e\u6587\u4ef6\u7684\u66f4\u6539\u3002<\/p>\n<p>\u9996\u5148\uff0c\u542f\u52a8MariaDB\uff1a<\/p>\n<blockquote><p>\n  systemctl start mariadb\n<\/p><\/blockquote>\n<p>\u521d\u59cb\u5316\u3001\u8bbe\u7f6e\u9ed8\u8ba4root\u5bc6\u7801\u3001\u7981\u6b62\u8fdc\u7a0b\u8fde\u63a5\u3001\u79fb\u9664\u6d4b\u8bd5\u6570\u636e\u5e93\u90fd\u5728\u8fd9\u4e00\u4e2a\u547d\u4ee4\u4e2d\u5b8c\u6210\uff1a<\/p>\n<blockquote><p>\n  mysql_secure_installation\n<\/p><\/blockquote>\n<p>\u56de\u8f66\u4e4b\u540e\uff0c\u6839\u636e\u63d0\u793a\u8fdb\u884c\u8bbe\u7f6e\u5c31\u597d\u4e86\uff0c\u5f88\u7b80\u5355\uff0c\u6211\u8fd9\u91cc\u4e0d\u8d34\u4e86\u3002<\/p>\n<p>\u7136\u540e\uff0c\u6839\u636e\u670d\u52a1\u5668\u7684\u914d\u7f6e\uff0c\u9009\u62e9\u4e00\u4e2a\u5408\u9002\u7684\u914d\u7f6e\u3002MariaDB\u9ed8\u8ba4\u81ea\u5e26\u4e86\u51e0\u4e2a\u914d\u7f6e\u6587\u4ef6\uff0c\u9002\u5408\u4e0d\u540c\u914d\u7f6e\u7684\u670d\u52a1\u5668\uff0c\u4ee5\u4e0b\u547d\u4ee4\u53ef\u67e5\u627e\u5230\uff1a<\/p>\n<pre><code>[root@doams3 ~]# find \/ -name my-*.cnf\n\/usr\/share\/mysql\/my-huge.cnf\n\/usr\/share\/mysql\/my-innodb-heavy-4G.cnf\n\/usr\/share\/mysql\/my-large.cnf\n\/usr\/share\/mysql\/my-medium.cnf\n\/usr\/share\/mysql\/my-small.cnf\n<\/code><\/pre>\n<p>\u6211\u9009\u62e9\u6700\u540e\u4e00\u4e2a\uff0csmall\u7684\uff0c\u8fd9\u914d\u7f6e\u9002\u5408\u6211\u5f53\u524d\u670d\u52a1\u5668\uff0c\u5148\u5907\u4efd\u5f53\u524d\u9ed8\u8ba4MariaDB\u914d\u7f6e\u518d\u7528\u5bf9\u5e94\u7684\u914d\u7f6e\u6587\u4ef6\u8986\u76d6\u9ed8\u8ba4\u7684\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<pre><code>[root@doams3 ~]# cp \/etc\/my.cnf{,.bak}\n[root@doams3 ~]# cp \/usr\/share\/mysql\/my-small.cnf \/etc\/my.cnf\ncp: overwrite \u2018\/etc\/my.cnf\u2019? y\n<\/code><\/pre>\n<p>\u4fee\u6539\u5b8c\u4e4b\u540e\uff0c\u91cd\u542fMariaDB\u751f\u6548\uff0c\u5982\u679c\u6709\u95ee\u9898\u6216\u8005\u65e0\u6cd5\u542f\u52a8\uff0c\u53ef\u4ee5\u8fd8\u539f\u9ed8\u8ba4\u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n<h3>\u6dfb\u52a0\u7f51\u7ad9<\/h3>\n<p>\u6dfb\u52a0\u7f51\u7ad9\uff0c\u6211\u4eec\u53ea\u9700\u8981\u65b0\u589eNginx\u7684\u914d\u7f6e\u6587\u4ef6\u5373\u53ef\u3002\u5728<strong><em>\/etc\/nginx\/conf.d\/<\/em><\/strong>\u65b0\u589e\u4e00\u4e2a\u914d\u7f6e\u6587\u4ef6\uff0c\u6bd4\u5982\u8bf4\uff0c\u8d77\u540dtest.conf :<\/p>\n<pre><code>vim \/etc\/nginx\/conf.d\/test.conf\n\nserver {\n    listen       80;\n    server_name test.zoco.me;\n\n\n    location \/ {\n        root   \/var\/www\/test;\n        index index.php index.html index.htm;\n    }\n\n    error_page  404              \/404.html;\n    location = \/404.html {\n        root   \/usr\/share\/nginx\/html;\n    }\n\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        root           \/var\/www\/test;\n        fastcgi_pass   127.0.0.1:9000;\n        fastcgi_index  index.php;\n        fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;\n        include        fastcgi_params;\n    }\n}\n<\/code><\/pre>\n<p>\u65b0\u5efaPHP\u6d4b\u8bd5\u6587\u4ef6\uff1a<\/p>\n<pre><code>vim \/var\/www\/test\/test.php\n\n&lt;?php\nphpinfo();\n?&gt;\n<\/code><\/pre>\n<p>\u8fd9\u91cc\uff0c\u6211\u914d\u7f6e\u57df\u540d\u4e3a<strong><em>test.zoco.me<\/em><\/strong>\uff0c\u9ed8\u8ba4\u7f51\u7ad9\u76ee\u5f55\u5728<strong><em>\/var\/www\/test<\/em><\/strong>\uff0c\u5982\u679c\u6ca1\u6709\uff0c\u65b0\u5efa\u5bf9\u5e94\u7684\u76ee\u5f55\u5373\u53ef\uff0c\u7136\u540e<strong><em>\u7ed9\u4e88\u76f8\u5e94\u7684\u6743\u9650<\/em><\/strong>\uff0c\u6ce8\u610f\u8fd9\u4e00\u6b65\u975e\u5e38\u91cd\u8981\uff0c\u5982\u679c\u4e0d\u7ed9\u4e88\u6743\u9650\uff0c\u53ef\u80fd\u540e\u9762\u8bbf\u95ee\u4f1a\u62a5\u9519\uff1a<\/p>\n<blockquote><p>\n  chown -R www:www \/var\/www\/test\n<\/p><\/blockquote>\n<p>\u7136\u540e\uff0c\u6d4b\u8bd5Nginx\u7684\u914d\u7f6e\u6587\u4ef6\u662f\u5426\u6b63\u786e\uff1a<\/p>\n<pre><code>[root@doams3 ~]# nginx -t\nnginx: the configuration file \/etc\/nginx\/nginx.conf syntax is ok\nnginx: configuration file \/etc\/nginx\/nginx.conf test is successful\n<\/code><\/pre>\n<p>\u5982\u679c\u50cf\u4e0a\u8ff0\u8f93\u51fa\u4e86successful\u5b57\u6837\uff0c\u5219\u8bf4\u660enginx\u914d\u7f6e\u65e0\u95ee\u9898\u3002<\/p>\n<p>\u91cd\u542fNginx\u3001PHP-FPM\u3001MariaDB\uff0c\u67e5\u770b\u6548\u679c\uff1a<\/p>\n<blockquote><p>\n  systemctl restart nginx<br \/>\n  systemctl restart php-fpm<br \/>\n  systemctl restart mariadb\n<\/p><\/blockquote>\n<p>\u7136\u540e\uff0c\u6253\u5f00\u4e0a\u8ff0\u5728nginx\u914d\u7f6e\u7684\u57df\u540d\uff0c\u67e5\u770b\u6548\u679c\uff1a<br \/>\n<img decoding=\"async\" src=\"https:\/\/cloudbool.com\/archive\/wp-content\/uploads\/2017\/11\/linux-nginx-php-fpm-mariadb.jpg\" alt=\"lnmp\u914d\u7f6e\u7ed3\u679c\" \/><\/p>\n<p>\u5982\u679c\u9875\u9762\u7a7a\u767d\u6216\u8005\u62a5\u9519\u6216\u8005\u63d0\u793a***No input file specified. ***\uff0c\u5219\u53ef\u80fd\u662fSELinux\u6ca1\u914d\u7f6e\u597d\u6216\u8005\u9632\u706b\u5899\u6ca1\u6709\u653e\u884c\uff0c\u4e34\u65f6\u5173\u95edSELinux\uff1a<\/p>\n<blockquote><p>\n  setenforce 0\n<\/p><\/blockquote>\n<p>\u9632\u706b\u5899\u653e\u884c80\u7aef\u53e3\u53ca443\u7aef\u53e3:<\/p>\n<blockquote><p>\n  firewall-cmd &#8211;permanent &#8211;add-port=80\/tcp<br \/>\n  firewall-cmd &#8211;permanent &#8211;add-port=443\/tcp<br \/>\n  firewall-cmd &#8211;reload\n<\/p><\/blockquote>\n<p>\u6216\u8005\u4e34\u65f6\u5173\u95ed\u9632\u706b\u5899\uff1a<\/p>\n<blockquote><p>\n  systemctl stop firewalld\n<\/p><\/blockquote>\n<h3>\u7ed3\u5c3e<\/h3>\n<p>\u5f00\u673a\u542f\u52a8Nginx\u3001PHP-FPM\u3001MariaDB\uff1a<\/p>\n<blockquote><p>\n  systemctl enable nginx<br \/>\n  systemctl enable php-fpm<br \/>\n  systemctl enable mariadb\n<\/p><\/blockquote>\n<p>\u542f\u7528HTTPS\uff0c\u5e76\u5f3a\u5236HTTP\u8df3\u5230HTTPS\u8fdb\u884cSSL\u4e3e\u4f8b\u914d\u7f6e\uff1a<\/p>\n<pre><code>server {\n    server_name www.zoco.me zoco.me;\n    listen   443 ssl http2 default;\n    ssl_protocols TLSv1.2 TLSv1.1 TLSv1; \n    ssl_certificate     \/var\/www\/zoco-ecc.crt;\n    ssl_certificate_key \/var\/www\/zoco-ecc.key;\n    root \/var\/www\/zoco;\n    index index.html index.php index.htm;\n    location \/ {\n        try_files $uri $uri\/ \/index.php?$args;\n    }\n    access_log \/var\/log\/nginx\/zoco.log;\n    error_log \/var\/log\/nginx\/error.zoco.log;\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    location ~ \\.php$ {\n        try_files $uri \/index.php =404;\n        fastcgi_split_path_info ^(.+\\.php)(\/.+)$;\n        fastcgi_pass unix:\/run\/php-fpm\/php71-fpm.sock;\n        fastcgi_index index.php;\n        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\n        include fastcgi_params;\n    }\n}\nserver {\n    listen 80;\n    server_name zoco.me www.zoco.me;\n    location \/ {\n        rewrite ^\/(.*)$ https:\/\/zoco.me\/$1 permanent;\n    }\n}\n<\/code><\/pre>\n<p>\u6587\u7ae0\u6765\u6e90\uff1ahttps:\/\/www.bwh123.com\/node\/centos-7-config-nginx-php-fpm-mariadb.html<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5176\u5b9e\u6211\u662f\u66f4\u559c\u6b22Debian\u7684\uff0c\u5c24\u5176\u662f\u521a\u53d1\u5e03\u4e0d\u4e45\u7684Debian9\uff0c\u6bd5\u7adf\u548cCentOS\u76f8\u6bd4\uff0cDebian9\u5b98\u65b9\u6e90\u7684 &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"https:\/\/cloudbool.com\/archive\/centos-7-config-lnmp-linux-nginx-mysql-php.html\"> <span class=\"screen-reader-text\">CentOS 7 \u7cfb\u7edf\u914d\u7f6eLNMP<\/span> \u67e5\u770b\u5168\u6587 &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"footnotes":""},"categories":[8],"tags":[17,69,76,79],"class_list":["post-51","post","type-post","status-publish","format-standard","hentry","category-tech","tag-centos","tag-mariadb","tag-nginx","tag-php"],"_links":{"self":[{"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/posts\/51","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/comments?post=51"}],"version-history":[{"count":0,"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/posts\/51\/revisions"}],"wp:attachment":[{"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/media?parent=51"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/categories?post=51"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/tags?post=51"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}