尊龙凯时人生就是搏

½ÌÄãÔõÑùÔÚDockerÖпìËٴSymfonyÇéÐÎ

½ÌÄãÔõÑùÔÚDockerÖпìËٴSymfonyÇéÐÎ

Ëæ×ÅÔÆÅÌËãºÍÈÝÆ÷ÊÖÒյĿìËÙÉú³¤£¬DockerÒѾ­³ÉΪÁËÒ»¸öºÜÊÇÊ¢ÐкÍÓÐÓõŤ¾ß¡£ËüÌṩÁËÒ»ÖÖ¿ìËÙ¡¢¿É¿¿ºÍ±ã½ÝµÄ·½·¨À´´ò°ü¡¢·Ö·¢ºÍÔËÐÐÓ¦ÓóÌÐò¡£SymfonyÊÇÒ»¸öÓÅÒìµÄPHP¿ò¼Ü£¬ËüÄܹ»×ÊÖúÎÒÃÇ¿ìËÙ¹¹½¨¸ßÖÊÁ¿µÄWebÓ¦ÓóÌÐò¡£ÔÚ±¾ÎÄÖУ¬ÎÒ½«ÏòÄãչʾÔõÑùʹÓÃDocker¿ìËٴSymfonyÇéÐΡ£

°ì·¨1: ×°ÖÃDockerºÍDocker Compose

Ê×ÏÈ£¬ÄãÐèÒªÔÚÄãµÄÅÌËã»úÉÏ×°ÖÃDockerºÍDocker Compose¡£Äã¿ÉÒÔÔÚDocker¹Ù·½ÍøÕ¾ÉÏÕÒµ½ÊʺÏÄã²Ù×÷ϵͳµÄ×°Öðü£¬²¢Æ¾Ö¤¹Ù·½Îĵµ¾ÙÐÐ×°Öá£

°ì·¨2: ½¨ÉèDockerfile

ÔÚÄãµÄÏîÄ¿¸ùĿ¼Ï½¨ÉèÒ»¸öÃûΪDockerfileµÄÎļþ£¬²¢ÔÚÆäÖÐÌí¼ÓÒÔÏÂÄÚÈÝ£º

FROM php:7.4-apache

# ×°ÖÃSymfonyËùÐèµÄÀ©Õ¹
RUN docker-php-ext-install pdo pdo_mysql

# Ìí¼ÓApacheµÄÉèÖÃÎļþ
COPY apache.conf /etc/apache2/sites-available/000-default.conf

# ×°ÖÃComposer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

µÇ¼ºó¸´ÖÆ

ÉÏÊöDockerfileÎļþÖУ¬ÎÒÃÇʹÓÃÁ˹ٷ½ÌṩµÄphp:7.4-apache×÷Ϊ»ù´¡¾µÏñ¡£È»ºó£¬ÎÒÃÇ×°ÖÃÁËSymfonyËùÐèµÄPDOºÍpdo_mysqlÀ©Õ¹£¬²¢½«ApacheµÄÉèÖÃÎļþ´ÓÍâµØ¸´ÖƵ½ÈÝÆ÷ÄÚµÄ׼ȷλÖá£×îºó£¬ÎÒÃÇ×°ÖÃÁËComposer£¬ÒÔ±ãÎÒÃÇÄܹ»Ê¹ÓÃComposerÖÎÀíSymfonyÏîÄ¿µÄÒÀÀµ¡£

°ì·¨3: ½¨ÉèApacheÉèÖÃÎļþ

ÔÚÄãµÄÏîÄ¿¸ùĿ¼Ï½¨ÉèÒ»¸öÃûΪapache.confµÄÎļþ£¬²¢ÔÚÆäÖÐÌí¼ÓÒÔÏÂÄÚÈÝ£º

<VirtualHost *:80>
    DocumentRoot /var/www/html/public
    <Directory /var/www/html/public>
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

µÇ¼ºó¸´ÖÆ

ÉÏÊöapache.confÎļþÖУ¬ÎÒÃÇÖ¸¶¨ÁËSymfonyÏîÄ¿µÄpublicĿ¼×÷ΪDocumentRoot£¬²¢ÆôÓÃÁËËùÓеÄApacheÖØд¹æÔò¡£

°ì·¨4: ½¨Éèdocker-compose.ymlÎļþ

ÔÚÄãµÄÏîÄ¿¸ùĿ¼Ï½¨ÉèÒ»¸öÃûΪdocker-compose.ymlµÄÎļþ£¬²¢ÔÚÆäÖÐÌí¼ÓÒÔÏÂÄÚÈÝ£º

version: '3'
services:
  web:
    build: .
    ports:
      - "8000:80"
    volumes:
      - .:/var/www/html
    links:
      - db
  db:
    image: mysql:8.0
    ports:
      - "3306:3306"
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_DATABASE=symfony
    volumes:
      - ./database:/var/lib/mysql

µÇ¼ºó¸´ÖÆ

ÉÏÊödocker-compose.ymlÎļþÖУ¬ÎÒÃǽç˵ÁËÁ½¸öЧÀÍ: webºÍdb¡£webЧÀÍʹÓÃÁËÎÒÃÇÉÏÊö½¨ÉèµÄDockerfile¹¹½¨£¬²¢½«ÈÝÆ÷ÄÚµÄ80¶Ë¿ÚÓ³Éäµ½Ö÷»úµÄ8000¶Ë¿Ú¡£ÎÒÃÇ»¹½«Ä¿½ñĿ¼ӳÉäΪÈÝÆ÷ÄÚµÄ/var/www/htmlĿ¼£¬ÒÔ±ãÎÒÃÇÄܹ»ÔÚÈÝÆ÷ÄÚ»á¼ûÎÒÃǵÄSymfonyÏîÄ¿¡£dbЧÀÍʹÓÃÁ˹ٷ½ÌṩµÄmysql:8.0¾µÏñ£¬²¢½«ÈÝÆ÷ÄÚµÄ3306¶Ë¿ÚÓ³Éäµ½Ö÷»úµÄ3306¶Ë¿Ú¡£ÎÒÃÇ»¹Ö¸¶¨ÁËMySQLµÄ¸ùÃÜÂëºÍ½¨ÉèµÄÊý¾Ý¿â¡£

°ì·¨5: Æô¶¯SymfonyÈÝÆ÷

ÔÚÖÕ¶ËÖУ¬½øÈëÄãµÄÏîÄ¿¸ùĿ¼£¬²¢ÔËÐÐÒÔÏÂÏÂÁîÆô¶¯SymfonyÈÝÆ÷£º

docker-compose up -d

µÇ¼ºó¸´ÖÆ

¸ÃÏÂÁ»áÏÂÔØËùÐèµÄ¾µÏñ¡¢¹¹½¨ÈÝÆ÷²¢ÔËÐС£ÉÔµÈƬÉΣ¬Æô¶¯Àú³Ì¿ÉÄÜÐèҪһЩʱ¼ä¡£

°ì·¨6: ×°ÖÃSymfony

ÔÚSymfonyÈÝÆ÷Æô¶¯ºó£¬Äã¿ÉÒÔͨ¹ýÒÔÏÂÏÂÁî½øÈëÈÝÆ÷ÄÚ²¿£º

docker exec -it [CONTAINER_NAME] bash

µÇ¼ºó¸´ÖÆ

ÔÚ¸ÃÏÂÁîÖУ¬½«[CONTAINER_NAME]Ì滻ΪÄãSymfonyÈÝÆ÷µÄÃû³Æ¡£

ÔÚÈÝÆ÷ÄÚ²¿£¬Äã¿ÉÒÔʹÓÃComposer×°ÖÃSymfony¡£ÔÚÈÝÆ÷ÄÚÔËÐÐÒÔÏÂÏÂÁ

composer create-project symfony/website-skeleton .

µÇ¼ºó¸´ÖÆ

¸ÃÏÂÁî»áÔÚÄ¿½ñĿ¼Ï½¨ÉèÒ»¸öеÄSymfonyÏîÄ¿¡£

°ì·¨7: »á¼ûSymfonyÓ¦ÓóÌÐò

ÔÚ×°ÖÃÍê³Éºó£¬Äã¿ÉÒÔͨ¹ýÔÚä¯ÀÀÆ÷Öлá¼ûÒÔÏÂURLÀ´Éó²éSymfonyÓ¦ÓóÌÐò£º

http://localhost:8000

µÇ¼ºó¸´ÖÆ

¹§Ï²Ä㣡ÄãÏÖÔÚÒѾ­ÀֳɵØÔÚDockerÖпìËٴÁËSymfonyÇéÐΡ£ÄãÏÖÔÚ¿ÉÒÔ×îÏÈʹÓÃSymfony¹¹½¨ÄãµÄÓ¦ÓóÌÐò£¬²¢ÏíÊÜÈÝÆ÷»¯´øÀ´µÄ±ãµ±ºÍÎÞаÐÔ¡£

×ܽá

ͨ¹ýʹÓÃDockerºÍDocker Compose£¬ÎÒÃÇ¿ÉÒÔ¿ìËÙµØÔÚÍâµØ´î½¨Ò»¸öSymfonyÇéÐΡ£ÕâʹµÃ¿ª·¢Ö°Ô±¿ÉÒÔÔ½·¢×¨×¢ÓÚÓ¦ÓóÌÐòµÄ¿ª·¢£¬¶ø²»ÐèÒª²ÙÐĵØÉèÖúÍÖÎÀí¿ª·¢ÇéÐΡ£Ï£Íû±¾ÎÄÄܹ»¶ÔÄãÓÐËù×ÊÖú£¬×£Äã¹¹½¨³ö¸ü¶à¾«²ÊµÄSymfonyÓ¦ÓóÌÐò£¡

ÒÔÉϾÍÊǽÌÄãÔõÑùÔÚDockerÖпìËٴSymfonyÇéÐεÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í尊龙凯时人生就是搏ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ尊龙凯时人生就是搏ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是搏

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
sitemap¡¢ÍøÕ¾µØͼ