docker wordpress php,请问docker wordpress php.ini在哪?

环境部署一直是一个很大的问题,无论是开发环境还是生产环境,但是 Docker

将开发环境和生产环境以轻量级方式打包,提供了一致的环境。极大的提升了开发部署一致性。当然,实际情况并没有这么简单,因为生产环境和开发环境的配置是完全不同的,比如日志等的问题都需要单独配置,但是至少比以前更加简单方便了,这里以

PHP 开发作为例子讲解 Docker 如何布置开发环境。

一般来说,一个 PHP 项目会需要以下工具:

Web 服务器: Nginx/Tengine

Web 程序: PHP-FPM

数据库: MySQL/PostgreSQL

缓存服务: Redis/Memcache

这是最简单的架构方式,在 Docker 发展早期,Docker 被大量的滥用,比如,一个镜像内启动多服务,日志收集依旧是按照 Syslog

或者别的老方式,镜像容量非常庞大,基础镜像就能达到 80M,这和 Docker 当初提出的思想完全南辕北辙了,而 Alpine Linux

发行版作为一个轻量级 Linux 环境,就非常适合作为 Docker 基础镜像,Docker 官方也推荐使用 Alpine 而不是 Debian

作为基础镜像,未来大量的现有官方镜像也将会迁移到 Alpine 上。本文所有镜像都将以 Alpine 作为基础镜像。

Nginx/Tengine

这部分笔者已经在另一篇文章 Docker 容器的 Nginx 实践中讲解了 Tengine 的 Docker 实践,并且给出了

Dockerfile,由于比较偏好 Tengine,而且官方已经给出了 Nginx 的 alpine 镜像,所以这里就用

Tengine。笔者已经将镜像上传到官方 DockerHub,可以通过

docker pull chasontang/tengine:2.1.2_f

获取镜像,具体请看 Dockerfile。

PHP-FPM

Docker 官方已经提供了 PHP 的 7.0.7-fpm-alpine 镜像,Dockerfile 如下:

FROM alpine:3.4

# persistent / runtime deps

ENV PHPIZE_DEPS \

autoconf \

file \

g++ \

gcc \

libc-dev \

make \

pkgconf \

re2c

RUN apk add --no-cache --virtual .persistent-deps \

ca-certificates \

curl

# ensure www-data user exists

RUN set -x \

&& addgroup -g 82 -S www-data \

&& adduser -u 82 -D -S -G www-data www-data

# 82 is the standard uid/gid for "www-data" in Alpine

# http://git.alpinelinux.org/cgit/aports/tree/main/apache2/apache2.pre-install?h=v3.3.2

# http://git.alpinelinux.org/cgit/aports/tree/main/lighttpd/lighttpd.pre-install?h=v3.3.2

# http://git.alpinelinux.org/cgit/aports/tree/main/nginx-initscripts/nginx-initscripts.pre-install?h=v3.3.2

ENV PHP_INI_DIR /usr/local/etc/php

RUN mkdir -p $PHP_INI_DIR/conf.d

####

ENV PHP_EXTRA_CONFIGURE_ARGS --enable-fpm --with-fpm-user=www-data --with-fpm-group=www-data

####

ENV GPG_KEYS 1A4E8B7277C42E53DBA9C7B9BCAA30EA9C0D5763

ENV PHP_VERSION 7.0.7

ENV PHP_FILENAME php-7.0.7.tar.xz

ENV PHP_SHA256 9cc64a7459242c79c10e79d74feaf5bae3541f604966ceb600c3d2e8f5fe4794

RUN set -xe \

&& apk add --no-cache --virtual .build-deps \

$PHPIZE_DEPS \

curl-dev \

gnupg \

libedit-dev \

libxml2-dev \

openssl-dev \

sqlite-dev \

&& curl -fSL "http://php.net/get/$PHP_FILENAME/from/this/mirror" -o "$PHP_FILENAME" \

&& echo "$PHP_SHA256 *$PHP_FILENAME" | sha256sum -c - \

&& curl -fSL "http://php.net/get/$PHP_FILENAME.asc/from/this/mirror" -o "$PHP_FILENAME.asc" \

&& export GNUPGHOME="$(mktemp -d)" \

&& for key in $GPG_KEYS; do \

gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \

done \

&& gpg --batch --verify "$PHP_FILENAME.asc" "$PHP_FILENAME" \

&& rm -r "$GNUPGHOME" "$PHP_FILENAME.asc" \

&& mkdir -p /usr/src \

&& tar -Jxf "$PHP_FILENAME" -C /usr/src \

&& mv "/usr/src/php-$PHP_VERSION" /usr/src/php \

&& rm "$PHP_FILENAME" \

&& cd /usr/src/php \

&& ./configure \

--with-config-file-path="$PHP_INI_DIR" \

--with-config-file-scan-dir="$PHP_INI_DIR/conf.d" \

$PHP_EXTRA_CONFIGURE_ARGS \

--disable-cgi \

# --enable-mysqlnd is included here because it's harder to compile after the fact than extensions are (since it's a plugin for several extensions, not an extension in itself)

--enable-mysqlnd \

# --enable-mbstring is included here because otherwise there's no way to get pecl to use it properly (see https://github.com/docker-library/php/issues/195)

--enable-mbstring \

--with-curl \

--with-libedit \

--with-openssl \

--with-zlib \

&& make -j"$(getconf _NPROCESSORS_ONLN)" \

&& make install \

&& { find /usr/local/bin /usr/local/sbin -type f -perm +0111 -exec strip --strip-all '{}' + || true; } \

&& make clean \

&& runDeps="$( \

scanelf --needed --nobanner --recursive /usr/local \

| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \

| sort -u \

| xargs -r apk info --installed \

| sort -u \

)" \

&& apk add --no-cache --virtual .php-rundeps $runDeps \

&& apk del .build-deps

COPY docker-php-ext-* /usr/local/bin/

####

WORKDIR /var/www/html

RUN set -ex \

&& cd /usr/local/etc \

&& if [ -d php-fpm.d ]; then \

# for some reason, upstream's php-fpm.conf.default has "include=NONE/etc/php-fpm.d/*.conf"

sed 's!=NONE/!=!g' php-fpm.conf.default | tee php-fpm.conf > /dev/null; \

cp php-fpm.d/www.conf.default php-fpm.d/www.conf; \

else \

# PHP 5.x don't use "include=" by default, so we'll create our own simple config that mimics PHP 7+ for consistency

mkdir php-fpm.d; \

cp php-fpm.conf.default php-fpm.d/www.conf; \

{ \

echo '[global]'; \

echo 'include=etc/php-fpm.d/*.conf'; \

} | tee php-fpm.conf; \

fi \

&& { \

echo '[global]'; \

echo 'error_log = /proc/self/fd/2'; \

echo; \

echo '[www]'; \

echo '; if we send this to /proc/self/fd/1, it never appears'; \

echo 'access.log = /proc/self/fd/2'; \

echo; \

echo 'clear_env = no'; \

echo; \

echo '; Ensure worker stdout and stderr are sent to the main error log.'; \

echo 'catch_workers_output = yes'; \

} | tee php-fpm.d/docker.conf \

&& { \

echo '[global]'; \

echo 'daemonize = no'; \

echo; \

echo '[www]'; \

echo 'listen = [::]:9000'; \

} | tee php-fpm.d/zz-docker.conf

EXPOSE 9000

CMD ["php-fpm"]

####

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Table of Contents Preface 1 Chapter 1: Preparing for WordPress Development 7 WordPress background 7 Extending WordPress 8 Understanding WordPress architecture 8 Templating 9 Introducing plugins 9 Summarizing architecture 10 Tools for web development 11 WordPress 11 Mac 12 Windows 12 Text editor 12 Using an IDE 13 FTP client 14 MySQL client 14 Coding best practices 15 Basic organization 15 Isolate tasks into functions 16 Use classes 16 Use descriptive variable names 16 Use descriptive function names 17 Separate logic and display layers 17 Go modular, to a point 18 Avoid short tags 18 Planning ahead / starting development 18 Interfaces 19 Localization 19 Table of Contents [ ii ] Documentation for the developer 19 Version control 20 Environment 20 Tests 20 Security 21 Printing user-supplied data to a page 21 Using user-supplied data to construct database queries 22 Debugging 22 Clearing your browser cache 23 Updating your php.ini file 23 Configuring your wp-config.php file 23 Checking your syntax 24 Checking values 24 Exercise 25 Summary 26 Chapter 2: Anatomy of a Plugin 29 Deconstructing an existing plugin: "Hello Dolly" 29 Activating the plugin 29 Examining the hello.php file 30 Information header 30 Exercise—breaking the header 30 Location, name, and format 31 Understanding the Includes 32 Exercise – parse errors 32 Bonus for the curious 33 User-defined functions 34 Exercise—an evil functionless plugin 34 What just happened 36 Omitting the closing "?>" PHP tag 38 A better example: Adding functions 38 Referencing hooks via add_action() and add_filter() 39 Actions versus Filters 40 Exercise—actions and filters 40 Exercise—filters 41 Reading more 43 Summary 44 Chapter 3: Social Bookmarking 45 The overall plan 46 Proof of concept 46 Avoiding conflicting function names 47 Table of Contents [ iii ] The master plugin outline 48 The plugin information header 50 In your browser—information header 51 Adding a link to the post content 51 Documenting our functions 52 In your browser—linking to the post content 52 Adding JavaScript to the head 52 Making our link dynamic 55 Adding a button template 57 Getting the post URL 58 In your browser—getting the post URL 60 Getting the post title 60 Getting the description 60 Getting the media type 62 Getting the post topic 62 In your browser—title, description, and topic 64 Checking WordPress versions 64 Summary 66 Chapter 4: Ajax Search 67 What is Ajax? 67 The overall plan 70 The proof of concept mock up 71 Hooking up jQuery 74 Test that jQuery has loaded 74 What happened? 75 Using the FireBug console directly 75 Writing HTML dynamically to a target div 76 Multi-line strings 77 Viewing the generated page 78 Anonymous functions 79 Adding a div on the fly 79 Create a listener 80 Fetching data from another page 81 Creating our plugin 83 Creating index.php and activating the plugin 84 Creating our first PHP class 85 Updating index.php 86 Testing your version of PHP 87 Testing for searchable pages 89 Adding your own CSS files 90 Adding your search handler 92 Adding your own JavaScript 92 Handling Ajax search requests 96 Table of Contents [ iv ] Formatting your search results 99 Summary 102 Chapter 5: Content Rotator 105 The plan 105 Widget overview 106 Preparation 106 Activating your plugin 110 Activating the widget 110 Having problems? 111 Parents and children: extending classes 112 Objects vs. libraries: when to use static functions 114 Add custom text 115 Adding widget options 116 Generating random content 121 Expiration dates: adding options to our widget 125 Expiration dates: enforcing the shelf life 126 Explaining the $instance 127 Adding a custom manager page 129 Adding options to the custom manager page 131 Randomizing content from the database 134 Review of PHP functions used 135 Summary 135 Chapter 6: Standardized Custom Content 137 What WordPress does for you: custom fields 138 What WordPress doesn't do for you 138 Standardizing a post's custom fields 139 Creating a new plugin 139 Removing the default WordPress form for custom fields 140 Creating our own custom meta box 143 Defining custom fields 145 Generating custom form elements 149 Saving custom content 155 Having trouble saving data? 157 Displaying custom data in your Templates 158 Copying a theme 158 Modifying the theme 159 Granular display of custom fields 161 Bonus for the MySQL curious 163 Known limitations 164 Summary 165 Table of Contents [ v ] Chapter 7: Custom Post Types 167 Background: What's in a name? 168 Understanding register_post_type() 169 Customizing our post type 175 Using shortcodes 177 Testing our shortcode 180 Customizing our plugin 181 Creating a settings shortcut link 186 Cleaning up when uninstalling 188 Summary 190 Chapter 8: Versioning Your Code with Subversion (SVN) 191 Why Subversion? 192 Understanding the terminology and concepts 192 Checking out a local working copy 193 SVN folder structure 194 Checkout, revisited 196 Setting up an SVN repository 197 Checking out a local working copy of our repo 198 Adding files 199 Committing changes to the repository 200 Overcoming errors 201 Verifying the new state of your repository 202 Adding more files to your repository 203 Removing files from the repository 204 Updating your working copy 204 Tagging a version 205 Reverting an entire project 206 Reverting a single file 207 Moving files 208 Exporting your working copy 208 Quick reference 209 Summary 211 Chapter 9: Preparing Your Plugin for Distribution 213 Public enemy number one: PHP notices 213 PHP short tags 215 Conflicting names 215 Modifying loader.php 220 Testing WordPress version 222 Testing PHP version 222 Testing MySQL version 223 Download from Wow! eBook <www.wowebook.com> Table of Contents [ vi ] Testing PHP modules 223 Testing WordPress installed plugins 224 Custom tests 226 Unit tests 226 WordPress limitations 227 Health check page 227 Storing test results in the database 229 Death to clippy: Use sensible configurations 229 Double check your interface 230 Documentation 230 Identify the purpose 230 Learning to drive: Keeping it relevant 231 Phrasebooks vs. dictionaries: Give examples 232 Analogy: The three bears 232 Analogy: PC load letter 232 The decalog of documentation 233 Summary 235 Chapter 10: Publishing Your Plugin 237 Internationalization and localization 237 Processing each message 238 Choosing a textdomain 240 Best practices 240 Working with formatting 241 More advanced messages 242 Plural vs. singular 242 More complex messages 243 Notes to translators 244 Language files 245 Creating a POT file 246 Creating translations: .po files 248 Loading a textdomain 250 Updating a translation 251 Format for the readme.txt file 252 Section – installation 253 Section – Frequently Asked Questions 253 Section – screenshots 253 New addition – videos 254 Section – summary 254 Requesting and using SVN access 255 Publicity and promotion 257 Summary 258 Table of Contents [ vii ] Appendix A: Recommended Resources 259 PHP reference 259 Function reference 259 The WordPress forums 259 WebDev Studios 260 Viper007Bond 260 Kovshenin 260 SLTaylor 260 XPlus3 260 WP Engineer 261 Other plugins 261 Appendix B: WordPress API Reference 263 PHP functions 263 dirname 263 file_get_contents 263 preg_match 264 preg_replace 264 print_r 264 sprintf 265 strtolower 265 substr 265 WordPress Functions 266 __ 266 _e 266 add_action 266 add_filter 267 add_meta_box 267 add_options_page 267 check_admin_referer 267 esc_html 268 get_option 268 get_post_meta 268 get_the_ID 268 register_post_type 269 remove_meta_box 269 screen_icon 269 the_content 269 the_meta 269 update_post_meta 270 wp_count_posts 270 Table of Contents [ viii ] wp_die 270 wp_nonce_field 270 Actions 270 admin_init 270 admin_menu 270 do_meta_boxes 271 init 271 save_post 271 widgets_init 271 wp_head 272 Filters 272 the_content 272 Index 273

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值