{"id":2011,"date":"2021-04-24T23:50:06","date_gmt":"2021-04-24T15:50:06","guid":{"rendered":"https:\/\/www.yusian.com\/blog\/?p=2011"},"modified":"2021-04-26T10:28:42","modified_gmt":"2021-04-26T02:28:42","slug":"%e5%88%9b%e5%bb%banginxphp%e7%9a%84docker%e9%95%9c%e5%83%8f","status":"publish","type":"post","link":"https:\/\/www.yusian.com\/blog\/centos\/2021\/04\/24\/2350062011.html","title":{"rendered":"\u521b\u5efaNginx+PHP\u7684Docker\u955c\u50cf"},"content":{"rendered":"<h1>1\u3001\u76f8\u5173\u8bf4\u660e<\/h1>\n<ol>\n<li>\u8be5\u955c\u50cf\u57fa\u4e8eCentos8.3\uff1b<\/li>\n<li>Nginx\u4e0ePHP\u5747\u4e3a\u5b98\u7f51\u4e0b\u8f7d\u6e90\u7801\u7f16\u8bd1\u5b89\u88c5\uff1b<\/li>\n<li>Nginx\u914d\u7f6e\u76ee\u5f55\uff1a<code>\/usr\/local\/nginx\/conf<\/code> \u6587\u4ef6\u76ee\u5f55\uff1a<code>\/usr\/local\/nginx\/html<\/code><\/li>\n<li>PHP\u914d\u7f6e\u76ee\u5f55\uff1a<code>\/usr\/local\/etc\/<\/code><\/li>\n<li>\u5df2\u505a\u597d\u7684\u955c\u50cf\u5730\u5740\uff1a<a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/hub.docker.com\/r\/yusian\/nginx1.20-php7.4\">https:\/\/hub.docker.com\/r\/yusian\/nginx1.20-php7.4<\/a><\/li>\n<\/ol>\n<h1>2\u3001\u5b89\u88c5\u6b65\u9aa4<\/h1>\n<h2>2.0 \u57fa\u7840\u73af\u5883<\/h2>\n<p>docker\u955c\u50cf\u5e02\u573a\u641c\u7d22<code>cetnos<\/code>,\u9009\u62e9\u5b98\u65b9\u6700\u65b0\u7248\u672c<\/p>\n<pre><code class=\"language-shell line-numbers\">[root@centos ~]# docker search centos\n<\/code><\/pre>\n<p>\u542f\u52a8\u8be5\u955c\u50cf\u4e00\u4e2a\u5b9e\u4f8b<\/p>\n<pre><code class=\"language-shell line-numbers\">[root@centos ~]# docker run -itd centos\n<\/code><\/pre>\n<p>\u8fdb\u5165\u8be5\u5b9e\u4f8b<\/p>\n<pre><code class=\"language-shell line-numbers\">[root@centos ~]# docker exec -it 5f4263abbcb7 bash\n<\/code><\/pre>\n<h2>2.1\u3001Nginx\u5b89\u88c5<\/h2>\n<p>Nginx\u5b89\u88c5\u76f8\u5bf9\u6bd4\u8f83\u7b80\u5355<\/p>\n<ul>\n<li>\u4e0b\u8f7d\u6e90\u7801\uff1ahttps:\/\/nginx.org\/\n<pre><code class=\"language-shell line-numbers\">[root@5f4263abbcb7 src]# wget https:\/\/nginx.org\/download\/nginx-1.20.0.tar.gz\n<\/code><\/pre>\n<p>\u5982\u679c\u63d0\u793a\u6ca1\u6709wget\u547d\u4ee4\uff0c\u5219\u5148\u5b89\u88c5wget\uff0c\u540e\u9762\u4f1a\u591a\u6b21\u51fa\u73b0\u7c7b\u4f3c\u63d0\u793a\uff0c\u90fd\u4f7f\u7528yum\u5de5\u5177\u5b89\u88c5<\/p>\n<pre><code class=\"language-shell line-numbers\">[root@5f4263abbcb7 src]# yum install -y wget\n<\/code><\/pre>\n<\/li>\n<li>\u89e3\u538b\uff1a\n<pre><code class=\"language-shell line-numbers\">[root@5f4263abbcb7 src]# tar -zxf nginx-1.20.0.tar.gz\n<\/code><\/pre>\n<\/li>\n<li>\u5b89\u88c5gcc\u53camake\u5de5\u5177\n<pre><code class=\"language-shell line-numbers\">[root@5f4263abbcb7 src]# yum install -y gcc-c++ make\n<\/code><\/pre>\n<\/li>\n<li>\u8fdb\u5165\u6e90\u7801\u76ee\u5f55\uff0c\u914d\u7f6e\u6e90\u7801\uff0c\u52a0\u5e26ssl\u6a21\u5757\n<pre><code class=\"language-shell line-numbers\">[root@5f4263abbcb7 nginx-1.20.0]# .\/configure --with-http_stub_status_module --with-http_ssl_module \n<\/code><\/pre>\n<\/li>\n<li>\u4e0b\u8f7d\u4e0b\u5173\u4f9d\u8d56\n<p>\u5728configure\u8fc7\u7a0b\u5f53\u4e2d\u4f1a\u51fa\u73b0\u7c7b\u4f3c<code>checking for PCRE library ... not found<\/code>\u7684\u62a5\u9519\u4fe1\u606f\uff0c\u8bf4\u660e\u4fe1\u606f\u4e2d\u63d0\u5230\u7684\u4f9d\u8d56\u672c\u673a\u6ca1\u6709\u5b89\u88c5\uff0c\u4e0a\u9762\u6709\u63d0\u5230\u8fc7\uff0c\u7c7b\u4f3c\u8fd9\u79cd\u63d0\u793a\u90fd\u53ef\u4ee5\u901a\u8fc7<code>yum<\/code>\u5305\u7ba1\u7406\u5de5\u5177\u8fdb\u884c\u5b89\u88c5\u4fee\u590d\u3002\u8fd9\u91cc\u6709\u4e00\u4e2a\u6280\u5de7\uff0c\u6211\u4eec\u5b9e\u9645\u5b89\u88c5\u7684\u4f9d\u8d56\u9700\u8981\u5728\u63d0\u793a\u7684xxx\u5e93\u540e\u9762\u5e26<code>-devel<\/code>\u3002<\/p>\n<p>\u6bd4\u5982\u8bf4<code>checking for PCRE library ... not found<\/code>\uff0c\u8868\u660e\u6ca1\u6709PCRE\u5e93\uff0c\u90a3\u4e48\u5b89\u88c5\u65f6\u88c5\u7684\u662f<code>pcre-devel<\/code>\u5e93\uff1b\u8fd9\u662f\u4ed6\u5bf9\u5e94\u7684\u5f00\u53d1\u5e93\uff0c\u5176\u4ed6\u7684\u7c7b\u4f3c\u3002<\/p>\n<pre><code class=\"language-shell line-numbers\">[root@5f4263abbcb7 nginx-1.20.0]# yum install -y pcre-devel\n<\/code><\/pre>\n<p>\u5b89\u88c5\u5b8c\u6210\u540e\u518dconfigure\u4e00\u4e0b\uff0c\u8fd8\u4f1a\u6709\u62a5\u9519\uff0c\u5c31\u7ee7\u7eed\u5b8c\u5584\u5b89\u88c5\uff0c\u76f4\u5230\u6ca1\u6709\u62a5\u9519\u4e3a\u6b62\u3002<\/p>\n<p>\u6211\u8fd9\u91cc\u5b89\u88c5\u7684\u65f6\u5019\uff0c\u76f8\u5173\u7684\u4f9d\u8d56\u67092\u4e2a\uff0c\u53ef\u4ee5\u4e00\u6b21\u6027\u5148\u5b89\u88c5\u597d<\/p>\n<pre><code class=\"language-shell line-numbers\">[root@5f4263abbcb7 nginx-1.20.0]# yum install -y pcre-devel openssl-devel\n<\/code><\/pre>\n<\/li>\n<li>\u7f16\u8bd1\u5b89\u88c5\n<pre><code class=\"language-shell line-numbers\">[root@5f4263abbcb7 nginx-1.20.0]# make &amp;&amp; make install\n<\/code><\/pre>\n<\/li>\n<li>\u5b89\u88c5\u7ed3\u675f\n<p>\u9ed8\u8ba4\u7684\u5b89\u88c5\u76ee\u5f55\u4e3a<code>\/usr\/local\/nginx<\/code>\uff0c\u4e5f\u53ef\u4ee5\u5728configure\u7684\u65f6\u5019\u6307\u5b9a\uff0c\u4f46\u6211\u89c9\u5f97\u6ca1\u6709\u5fc5\u8981\uff0c\u53ef\u6267\u884c\u7a0b\u5e8f\u662fsbin\u76ee\u5f55\u4e0b\u7684nginx\u6587\u4ef6\uff0c\u53ef\u4ee5\u901a\u8fc7\u6dfb\u52a0\u4e00\u4e2a\u786c\u94fe\u63a5\u5230<code>\/usr\/bin<\/code>\u76ee\u5f55\u4e0b\u65b9\u4fbf\u5728\u4efb\u4f55\u5730\u65b9\u6267\u884cnginx\u547d\u4ee4\uff0c\u4e0d\u9700\u8981\u914d\u7f6e\u4ec0\u4e48\u73af\u5883\u53d8\u91cf<\/p>\n<pre><code class=\"language-shell line-numbers\">[root@5f4263abbcb7 nginx]# ln \/usr\/local\/nginx\/sbin\/nginx \/usr\/bin\/nginx\n<\/code><\/pre>\n<p>\u542f\u52a8<\/p>\n<pre><code class=\"language-shell line-numbers\">[root@5f4263abbcb7 nginx]# nginx\n<\/code><\/pre>\n<p>\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<pre><code class=\"language-shell line-numbers\">[root@5f4263abbcb7 nginx]# vi conf\/nginx.conf\n<\/code><\/pre>\n<\/li>\n<\/ul>\n<h2>2.2\u3001\u5b89\u88c5php<\/h2>\n<p>php\u5b89\u88c5\u7684\u65b9\u6cd5\u601d\u8def\u4e0eNginx\u5927\u81f4\u4e00\u6837\uff0c\u4e5f\u662f\u5b98\u7f51\u4e0b\u8f7d\u6e90\u7801\uff0c\u7136\u540e<code>configure<\/code>\u518d\u5c31\u662f<code>make<\/code>\u7f16\u8bd1<\/p>\n<ul>\n<li>\u5b98\u7f51\uff1ahttps:\/\/www.php.net \u76ee\u524d\u6700\u65b0\u7248\u672c\u662f8.0.3\uff0c\u4f46\u662fdiscuz\u4f3c\u4e4e\u76ee\u5f55\u8fd8\u4e0d\u652f\u63018.0\u7248\u672c\uff0c\u6240\u4ee5\u4e0a\u8ff0\u955c\u50cf\u5b89\u88c5\u7684\u662f7.4\u7248\u672c\uff1b<\/p>\n<\/li>\n<li>\n<p>discuz\u4e0ewordpress\u9700\u8981\u7684php\u6a21\u5757\u6bd4\u8f83\u591a\uff0c\u6211\u603b\u7ed3\u4e86\u4e00\u4e0b\uff0c\u4ee5\u4e0b\u51e0\u4e2a\u662f\u5fc5\u987b\u5b89\u88c5\u7684\uff0c\u4e0a\u8ff0\u955c\u50cf\u5b89\u88c5\u7684\u5c31\u662f\u8fd9\u4e9b\uff0c\u5982\u679c\u6709\u9700\u8981\u53ef\u4ee5\u518d\u6269\u5c55\uff0c\u6269\u5c55\u7684\u65b9\u6cd5\u5c31\u4e2d\u91cd\u65b0configure\u7136\u540emake\u7f16\u8bd1\u5b89\u88c5<\/p>\n<pre><code class=\"language-shell line-numbers\">[root@5f4263abbcb7 php-7.4.16]#.\/configure \\\n--enable-fpm \\\n--enable-mysqlnd \\\n--enable-mbstring \\\n--enable-gd \\\n--enable-exif \\\n--with-mysqli=mysqlnd \\\n--with-curl \\\n--with-zip \\\n--with-openssl\n<\/code><\/pre>\n<\/li>\n<li>\u540c\u6837\u7684\u9053\u7406\uff0c\u9047\u5230\u6709\u7f3a\u5931\u7684\u5e93\u5c31\u901a\u8fc7<code>yum<\/code>\u5305\u7ba1\u7406\u5de5\u5177\u8865\u5168\uff0c\u4f46\u6709\u4e00\u4e2a\u4f8b\u5916\uff1a<code>oniguruma<\/code>\uff0c<code>yum<\/code>\u5305\u7ba1\u7406\u5de5\u5177\u4e2d\u6709<code>oniguruma<\/code>\uff0c\u4f46\u6ca1\u6709\u5bf9\u5e94\u7684\u5f00\u53d1\u5e93<code>oniguruma-devel<\/code>\uff0c\u89e3\u51b3\u65b9\u6cd5\u53c2\u8003\uff1a<a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/www.yusian.com\/blog\/?p=2010\">https:\/\/www.yusian.com\/blog\/?p=2010<\/a><\/p>\n<\/li>\n<li>\n<p>PHP\u7f16\u8bd1\u65f6\u95f4\u4f1a\u6bd4\u8f83\u4e45\u4e00\u70b9\uff0c\u62112\u68384G\u7684\u670d\u52a1\u5668\u9700\u898110\uff5e20\u5206\u949f\u5de6\u53f3\uff0c\u5b89\u88c5\u5b8c\u6210\u540e\u9ed8\u8ba4\u7684\u914d\u7f6e\u76ee\u5f55\u4e3a<code>\/usr\/local\/etc\/<\/code><\/p>\n<\/li>\n<li>\n<p>\u521d\u59cb\u5316\u914d\u7f6e<\/p>\n<p>\u5728<code>\/usr\/local\/etc\/<\/code>\u76ee\u5f55\u4e0b\uff0c\u5c06\u9ed8\u8ba4\u7684<code>php-fpm.conf<\/code>\u6587\u4ef6\u62f7\u8d1d\u4e00\u4efd\u4f7f\u7528\u5373\u53ef<\/p>\n<pre><code class=\"language-shell line-numbers\">[root@5f4263abbcb7 etc]# cp php-fpm.conf.default php-fpm.conf\n<\/code><\/pre>\n<p>\u8be5\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684\u6700\u540e\u4e00\u884c\uff1a<code>include=NONE\/etc\/php-fpm.d\/*.conf<\/code>\uff0c\u5c06<code>NONE\/<\/code>\u53bb\u6389\uff0c\u5373\u6539\u6210<code>include=etc\/php-fpm.d\/*.conf<\/code><\/p>\n<p>\u518d\u8fdb\u5165<code>php-fpm.d<\/code>\u76ee\u5f55\u4e2d\u62f7\u8d1d<code>www.conf<\/code>\u6587\u4ef6<\/p>\n<pre><code class=\"language-shell line-numbers\">[root@5f4263abbcb7 php-fpm.d]# cp www.conf.default www.conf\n<\/code><\/pre>\n<p>\u8be5\u914d\u7f6e\u6587\u4ef6\u4e2d\u95f4\uff0c\u5927\u6982\u7b2c\u4e00\u9875\u7684\u6700\u540e\u4e00\u884c<code>listen = 127.0.0.1:9000<\/code>\uff0c\u8868\u660ephp\u53ea\u5bf9\u672c\u673a\u63d0\u4f9b\u670d\u52a1\uff0c\u5982\u679c\u5916\u90e8\u673a\u5668\u9700\u8981\u4f7f\u7528\uff0c\u5c06<code>127.0.0.1:9000<\/code>\u6539\u6210<code>0.0.0.0:9000<\/code><\/p>\n<\/li>\n<li>\n<p>\u542f\u52a8php<\/p>\n<pre><code class=\"language-shell line-numbers\">[root@5f4263abbcb7 etc]# php-fpm\n<\/code><\/pre>\n<\/li>\n<\/ul>\n<h2>3\u3001\u57fa\u672c\u4f7f\u7528<\/h2>\n<p>\u5982\u679c\u76f4\u63a5\u62c9\u53d6\u4e0a\u8ff0\u6211\u5df2\u7ecf\u505a\u597d\u7684\u955c\u50cf<code>docker pull yusian\/nginx1.20-php7.4<\/code>\uff0c\u53ef\u4ee5\u76f4\u63a5\u521b\u5efa\u5bb9\u5668\uff0c\u57fa\u672c\u6b65\u9aa4\u5982\u4e0b<\/p>\n<ol>\n<li>\u521b\u5efa\u5377\u5b97\uff1a\n<pre><code class=\"language-shell line-numbers\">[root@yusian ~]# docker volume create www\n<\/code><\/pre>\n<p>\u5377\u5b97\u5bf9\u5e94\u7684\u672c\u5730\u7269\u7406\u8def\u5f84\u4e3a\uff1a<code>\/var\/lib\/docker\/volumes\/www\/_data<\/code>\uff0c\u53ef\u5c06\u7f51\u7ad9\u7684\u6587\u4ef6\u62f7\u8d1d\u5230\u8be5\u76ee\u5f55\u4e0b\uff1b<\/p>\n<\/li>\n<li>\n<p>\u542f\u52a8\u5bb9\u5668\uff1a<\/p>\n<pre><code class=\"language-shell line-numbers\">[root@yusian ~]# docker run -itd -v www:\/usr\/local\/nginx\/html -p 443:443 -p 80:80 yusian\/nginx1.20-php7.4\n<\/code><\/pre>\n<p>\u5bb9\u5668\u542f\u52a8\u540e\uff0c\u5230\u5bf9\u5e94\u7684\u914d\u7f6e\u76ee\u5f55\u4e0b\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\uff0c\u4e3b\u8981\u662fNginx\u7684\u914d\u7f6e\u6587\u4ef6\uff0cphp\u57fa\u672c\u4e0a\u4e0d\u9700\u8981\u989d\u5916\u914d\u7f6e\uff1b<\/p>\n<\/li>\n<li>\n<p>\u542f\u52a8\u670d\u52a1<\/p>\n<\/li>\n<\/ol>\n<ul>\n<li>\u542f\u52a8Nginx\uff1anginx<\/li>\n<li>\u542f\u52a8PHP\uff1aphp-fpm<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>1\u3001\u76f8\u5173\u8bf4\u660e \u8be5\u955c\u50cf\u57fa\u4e8eCentos8.3\uff1b Nginx\u4e0ePHP\u5747\u4e3a\u5b98\u7f51\u4e0b\u8f7d\u6e90\u7801\u7f16\u8bd1\u5b89\u88c5\uff1b Nginx\u914d\u7f6e\u76ee\u5f55\uff1a\/usr\/local\/nginx\/conf \u6587\u4ef6\u76ee\u5f55\uff1a\/usr\/local\/nginx\/html PHP\u914d\u7f6e\u76ee\u5f55\uff1a\/usr\/local\/etc\/ \u5df2\u505a\u597d\u7684\u955c\u50cf\u5730\u5740\uff1ahttps:\/\/hub.docker.com\/r\/yusian\/nginx1.20-php7.4 2\u3001\u5b89\u88c5\u6b65\u9aa4 2.0 \u57fa\u7840\u73af\u5883 docker\u955c\u50cf\u5e02\u573a\u641c\u7d22cetnos,\u9009\u62e9\u5b98\u65b9\u6700\u65b0\u7248\u672c [root@centos ~]# docker search centos \u542f\u52a8\u8be5\u955c\u50cf\u4e00\u4e2a\u5b9e\u4f8b [root@centos ~]# docker run -itd centos \u8fdb\u5165\u8be5\u5b9e\u4f8b [root@centos ~]# docker exec -it 5f4263abbcb7 bash 2.1\u3001Nginx\u5b89\u88c5 Nginx\u5b89\u88c5\u76f8\u5bf9\u6bd4\u8f83\u7b80\u5355 \u4e0b\u8f7d\u6e90\u7801\uff1ahttps:\/\/nginx.org\/ [root@5f4263abbcb7 src]# wget https:\/\/nginx.org\/download\/nginx-1.20.0.tar.gz \u5982\u679c\u63d0\u793a\u6ca1\u6709wget\u547d\u4ee4\uff0c\u5219\u5148\u5b89\u88c5wget\uff0c\u540e\u9762\u4f1a\u591a\u6b21\u51fa\u73b0\u7c7b\u4f3c\u63d0\u793a\uff0c\u90fd\u4f7f\u7528yum\u5de5\u5177\u5b89\u88c5 [root@5f4263abbcb7 src]# yum install -y wget \u89e3\u538b\uff1a [root@5f4263abbcb7 src]# tar -zxf nginx-1.20.0.tar.gz \u5b89\u88c5gcc\u53camake\u5de5\u5177 [root@5f4263abbcb7 src]# yum [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[67,346,359,6],"class_list":["post-2011","post","type-post","status-publish","format-standard","hentry","category-centos","tag-centos","tag-docker","tag-nginx","tag-php"],"_links":{"self":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/2011","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/comments?post=2011"}],"version-history":[{"count":0,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/2011\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/media?parent=2011"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/categories?post=2011"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/tags?post=2011"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}