Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build a development environment with PhpStorm and Docker

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

Today, I will talk to you about how to build a development environment using PhpStorm and Docker. Many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

Step 1: customize a PHP image using dockerfile

The best environment for taking over maintenance projects and writing maintenance code is to be consistent with the server, and docker can easily achieve this.

For example, to maintain a project developed in PHP5.6.4 and ThinkPHP5.0, you can install the extensions required by ThinkPHP5.0 based on the php5.6.4 image, and write the following dockerfile:

FROM php:5.6.4-fpmRUN apt-get update & & apt-get install libssl-dev-y\ & & pecl install redis-2.2.5 xdebug-2.5.5\ & & docker-php-ext-install pdo_mysql mbstring ftp

You can run the command to generate a custom image:

Docker build-t php564:v1. The second step is to combine multiple images using docker-compose

Docker-compose can orchestrate multiple containers, cooperate with each other to complete a task, and Nginx is needed to get the project running, so a new directory is created to write the docker-compose configuration:

PS E:\ docker\ workEnv > pwdPath-E:\ docker\ workEnv2.1 build directory structure

Create a file: docker-compose.yml

Two directories: nginx and php564 are used to store something related to the container

The directory structure is as follows:

PS E:\ docker\ workEnv > lsDirectory: e:\ docker\ workEnvMode LastWriteTime Length Name---- d-27ax 04 nginxd- 2021 13:20 nginxd- 18 * Php564-a---- 18 docker-compose.ymlPS 05 docker-compose.ymlPS 20 21 10:47 560 docker-compose.ymlPS E:\ docker\ workEnv > 2.2 Custom php dockerfile moved to the php564 directory

Other colleagues may also need to maintain this project and put dockerfile in this directory. If other colleagues also use docker, they can send him the current directory (I am workEnv here) directly, and he can compile directly through docker-compose.

Create two more directories in the php564 directory: conf.d and xdebug, which are used to map the configuration and record the xdebug log.

Docker-compose.yml will come in handy.

2.3 write the docker-compose.ymlversion: '3'services: web: image: nginx ports:-"80:80"-"443 web 443"-"1212 web 1212" depends_on:-php564 volumes: # nginx directory to map to the nginx container configuration directory -. / nginx:/etc/nginx/conf.d # Local project directory mapped to nginx container working directory-E:/www:/usr/share/nginx php564: build:. / php564 volumes: # Local project directory mapped to php container working directory-E:/www:/var/www # php configuration file -. / php564/conf.d/php.ini:/usr/local/etc/php/conf.d/php.ini # xdebug debug log -. / php564/xdebug:/xdebug ports:-"9000 php564/xdebug:/xdebug ports 9000" 2.4 write nginx configuration

Go to the nginx directory and create a configuration file for the project. I have created oldErp.conf here:

# oldERP.confserver {listen 1212; server_name location; error_page 500502 503 504 / 50x.html; location = / 50x.html {root / usr/share/nginx/html;} location / erp/ {alias / usr/share/nginx/olderp/; if (!-e $request_filename) {rewrite ^ / erp/index.php/ (. *) $/ index.php?s=/$1 last }} location / {try_files $uri $uri/ / index.php?$query_string;} location ~\ .php$ {# write php564 here, fastcgi_pass php564:9000; fastcgi_index index.php; # defined in docker-compose # here also specify the project path fastcgi_param SCRIPT_FILENAME / var/www/olderp$fastcgi_script_name in the php564 container Include fastcgi_params;}} 2.5 compile docker-compose.yml

To the workEnv directory, execute:

Docker-compose up-d

Then you can look at the container:

PS E:\ docker\ workEnv > docker-compose topworkenv_php564_1 UID PID PPID C STIME TTY TIME CMD -- root 12463 12442 0 03:03? 00:00:01 php-fpm: master process (/ usr/local/etc/php-fpm.conf) www-data 12518 12463 0 03:03? 00:00:02 php-fpm: pool wwwwww-data 12519 12463 0 03:03 ? 00:00:02 php-fpm: pool wwwroot 12529 12442 0 03:03? 00:00:00 bashworkenv_web_1 UID PID PPID C STIME TTY TIME CMD -root 12275 12254 0 02:50? 00:00:00 nginx: master process nginx-g daemon off Uuidd 12352 12275 0 02:50? 00:00:00 nginx: worker processPS E:\ docker\ workEnv > step 3, configure xdebug

You can write php code without xdebug, but when the program needs to be debugged, it may be breakpoint code like var_dump and die everywhere.

Using xdebug can avoid this embarrassment, it can be debugged step by step, you can monitor input parameters, you can change input parameters, so some companies put whether they will use xdebug into the skill rating for a reason.

To use xdebug, you probably need these two steps:

1. Configure php to support xdebug

two。 Configure phpstrom remote debugging xdebug

3.1 configure php to support xdebug

Customize the installed xdebug of the php image earlier, but you still need to configure some parameters. When you write the docker-compose.yml file, you do the configuration mapping:

# omit other # php configuration files -. / php564/conf.d/php.ini:/usr/local/etc/php/conf.d/php.ini# omit other

So let's go to the php564/conf.d directory and write php.ini:

Extension=redis.sozend_extension=xdebug.soxdebug.idekey=PHPSTORM # IED keyword xdebug.remote_autostart=onxdebug.remote_enable=onxdebug.remote_port=9100xdebug.remote_host=192.168.2.159 # Local IPxdebug.remote_log=/xdebug/debug.log # Xdebug logmemory_limit=1024M

To complete the above configuration, in the workEnv directory, execute docker-compose restart to restart docker:

PS E:\ docker\ workEnv > docker-compose restartRestarting workenv_web_1... DoneRestarting workenv_php564_1... DonePS E:\ docker\ workEnv > after reading the above, do you have any further understanding of how to build a development environment using PhpStorm and Docker? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report