[{"data":1,"prerenderedAt":1431},["Reactive",2],{"content-query-ejKH7JVRHH":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"head":10,"layout":12,"body":13,"_type":1426,"_id":1427,"_source":1428,"_file":1429,"_extension":1430},"/docs/customizing-the-image/installing-additional-php-extensions","customizing-the-image",false,"","How to install additional PHP extensions","Learn how to add any PHP extension that you need for your application.",{"title":11},"Installing additional PHP extensions - Docker PHP - Server Side Up","docs",{"type":14,"children":15,"toc":1418},"root",[16,24,46,68,98,226,238,243,252,259,286,369,471,570,619,624,676,681,694,715,722,761,766,803,809,814,1351,1357,1362,1368,1379,1384,1394,1400,1412],{"type":17,"tag":18,"props":19,"children":21},"element","h1",{"id":20},"how-to-install-additional-php-extensions",[22],{"type":23,"value":8},"text",{"type":17,"tag":25,"props":26,"children":27},"p",{},[28,30,44],{"type":23,"value":29},"We provide a number of PHP packages by default, but there will be times where you'll need to add additional PHP extensions in order to support a certain PHP library in your application. By default, we've included a popular tool called ",{"type":17,"tag":31,"props":32,"children":36},"a",{"href":33,"rel":34},"https://github.com/mlocati/docker-php-extension-installer",[35],"nofollow",[37],{"type":17,"tag":38,"props":39,"children":41},"code",{"className":40},[],[42],{"type":23,"value":43},"install-php-extensions",{"type":23,"value":45}," that allows you to install almost any PHP module that you'll need.",{"type":17,"tag":25,"props":47,"children":48},{},[49,51,58,60,66],{"type":23,"value":50},"Installing extensions is easy. All you need to do is find the extension you'd like to install on the ",{"type":17,"tag":31,"props":52,"children":55},{"href":53,"rel":54},"https://github.com/mlocati/docker-php-extension-installer#supported-php-extensions",[35],[56],{"type":23,"value":57},"docker-php-extension installer README",{"type":23,"value":59},". Once you have the name of the extensions, you'll need to add it to the ",{"type":17,"tag":38,"props":61,"children":63},{"className":62},[],[64],{"type":23,"value":65},"Dockerfile",{"type":23,"value":67}," in your project.",{"type":17,"tag":69,"props":70,"children":71},"note",{},[72],{"type":17,"tag":25,"props":73,"children":74},{},[75,81,83,88,90,96],{"type":17,"tag":76,"props":77,"children":78},"strong",{},[79],{"type":23,"value":80},"Our images are unprivileged by default.",{"type":23,"value":82}," This means you'll need to switch to ",{"type":17,"tag":38,"props":84,"children":86},{"className":85},[],[87],{"type":23,"value":14},{"type":23,"value":89}," to do \"root things\", then switch back to the ",{"type":17,"tag":38,"props":91,"children":93},{"className":92},[],[94],{"type":23,"value":95},"www-data",{"type":23,"value":97}," user. This ensures your container image is hardened against security vulnerabilities.",{"type":17,"tag":99,"props":100,"children":102},"code-panel",{"label":101},"Example: Installing the \"intl\" extension",[103],{"type":17,"tag":104,"props":105,"children":109},"pre",{"className":106,"code":107,"language":108,"meta":7,"style":7},"language-dockerfile shiki shiki-themes github-dark github-dark monokai","FROM serversideup/php:8.2.12-fpm-nginx-bookworm\n\n# Switch to root so we can do root things\nUSER root\n\n# Install the intl extension with root permissions\nRUN install-php-extensions intl\n\n# Drop back to our unprivileged user\nUSER www-data\n","dockerfile",[110],{"type":17,"tag":38,"props":111,"children":112},{"__ignoreMap":7},[113,131,141,151,165,173,182,196,204,213],{"type":17,"tag":114,"props":115,"children":118},"span",{"class":116,"line":117},"line",1,[119,125],{"type":17,"tag":114,"props":120,"children":122},{"style":121},"--shiki-default:#F97583;--shiki-dark:#F97583;--shiki-sepia:#F92672",[123],{"type":23,"value":124},"FROM",{"type":17,"tag":114,"props":126,"children":128},{"style":127},"--shiki-default:#E1E4E8;--shiki-dark:#E1E4E8;--shiki-sepia:#F8F8F2",[129],{"type":23,"value":130}," serversideup/php:8.2.12-fpm-nginx-bookworm\n",{"type":17,"tag":114,"props":132,"children":134},{"class":116,"line":133},2,[135],{"type":17,"tag":114,"props":136,"children":138},{"emptyLinePlaceholder":137},true,[139],{"type":23,"value":140},"\n",{"type":17,"tag":114,"props":142,"children":144},{"class":116,"line":143},3,[145],{"type":17,"tag":114,"props":146,"children":148},{"style":147},"--shiki-default:#6A737D;--shiki-dark:#6A737D;--shiki-sepia:#88846F",[149],{"type":23,"value":150},"# Switch to root so we can do root things\n",{"type":17,"tag":114,"props":152,"children":154},{"class":116,"line":153},4,[155,160],{"type":17,"tag":114,"props":156,"children":157},{"style":121},[158],{"type":23,"value":159},"USER",{"type":17,"tag":114,"props":161,"children":162},{"style":127},[163],{"type":23,"value":164}," root\n",{"type":17,"tag":114,"props":166,"children":168},{"class":116,"line":167},5,[169],{"type":17,"tag":114,"props":170,"children":171},{"emptyLinePlaceholder":137},[172],{"type":23,"value":140},{"type":17,"tag":114,"props":174,"children":176},{"class":116,"line":175},6,[177],{"type":17,"tag":114,"props":178,"children":179},{"style":147},[180],{"type":23,"value":181},"# Install the intl extension with root permissions\n",{"type":17,"tag":114,"props":183,"children":185},{"class":116,"line":184},7,[186,191],{"type":17,"tag":114,"props":187,"children":188},{"style":121},[189],{"type":23,"value":190},"RUN",{"type":17,"tag":114,"props":192,"children":193},{"style":127},[194],{"type":23,"value":195}," install-php-extensions intl\n",{"type":17,"tag":114,"props":197,"children":199},{"class":116,"line":198},8,[200],{"type":17,"tag":114,"props":201,"children":202},{"emptyLinePlaceholder":137},[203],{"type":23,"value":140},{"type":17,"tag":114,"props":205,"children":207},{"class":116,"line":206},9,[208],{"type":17,"tag":114,"props":209,"children":210},{"style":147},[211],{"type":23,"value":212},"# Drop back to our unprivileged user\n",{"type":17,"tag":114,"props":214,"children":216},{"class":116,"line":215},10,[217,221],{"type":17,"tag":114,"props":218,"children":219},{"style":121},[220],{"type":23,"value":159},{"type":17,"tag":114,"props":222,"children":223},{"style":127},[224],{"type":23,"value":225}," www-data\n",{"type":17,"tag":25,"props":227,"children":228},{},[229,231,236],{"type":23,"value":230},"It's really that simple. The ",{"type":17,"tag":38,"props":232,"children":234},{"className":233},[],[235],{"type":23,"value":43},{"type":23,"value":237}," tool will automatically install the operating system packages that are required for the PHP extension to work and add the extension to PHP.",{"type":17,"tag":25,"props":239,"children":240},{},[241],{"type":23,"value":242},"For more details on this script, we encourage you to check out the GitHub repository for this project.",{"type":17,"tag":25,"props":244,"children":245},{},[246],{"type":17,"tag":31,"props":247,"children":249},{"href":33,"rel":248},[35],[250],{"type":23,"value":251},"View the \"docker-php-extension-installer\" Project on GitHub →",{"type":17,"tag":253,"props":254,"children":256},"h2",{"id":255},"docker-compose",[257],{"type":23,"value":258},"Docker Compose",{"type":17,"tag":25,"props":260,"children":261},{},[262,264,270,272,278,280,285],{"type":23,"value":263},"If you're using Docker Compose, you'll want to make sure that you're not calling our image directly with the ",{"type":17,"tag":38,"props":265,"children":267},{"className":266},[],[268],{"type":23,"value":269},"image:",{"type":23,"value":271}," key. Instead, you'll want to use the ",{"type":17,"tag":38,"props":273,"children":275},{"className":274},[],[276],{"type":23,"value":277},"build:",{"type":23,"value":279}," key and point to a ",{"type":17,"tag":38,"props":281,"children":283},{"className":282},[],[284],{"type":23,"value":65},{"type":23,"value":67},{"type":17,"tag":99,"props":287,"children":289},{"label":288},"Original docker-compose.yml file",[290],{"type":17,"tag":104,"props":291,"children":295},{"className":292,"code":293,"language":294,"meta":7,"style":7},"language-yaml shiki shiki-themes github-dark github-dark monokai","services:\n  php:\n    image: serversideup/php:8.2.12-fpm-nginx-bookworm\n    volumes:\n      - .:/var/www/html/:cached\n","yaml",[296],{"type":17,"tag":38,"props":297,"children":298},{"__ignoreMap":7},[299,313,325,344,356],{"type":17,"tag":114,"props":300,"children":301},{"class":116,"line":117},[302,308],{"type":17,"tag":114,"props":303,"children":305},{"style":304},"--shiki-default:#85E89D;--shiki-dark:#85E89D;--shiki-sepia:#F92672",[306],{"type":23,"value":307},"services",{"type":17,"tag":114,"props":309,"children":310},{"style":127},[311],{"type":23,"value":312},":\n",{"type":17,"tag":114,"props":314,"children":315},{"class":116,"line":133},[316,321],{"type":17,"tag":114,"props":317,"children":318},{"style":304},[319],{"type":23,"value":320},"  php",{"type":17,"tag":114,"props":322,"children":323},{"style":127},[324],{"type":23,"value":312},{"type":17,"tag":114,"props":326,"children":327},{"class":116,"line":143},[328,333,338],{"type":17,"tag":114,"props":329,"children":330},{"style":304},[331],{"type":23,"value":332},"    image",{"type":17,"tag":114,"props":334,"children":335},{"style":127},[336],{"type":23,"value":337},": ",{"type":17,"tag":114,"props":339,"children":341},{"style":340},"--shiki-default:#9ECBFF;--shiki-dark:#9ECBFF;--shiki-sepia:#E6DB74",[342],{"type":23,"value":343},"serversideup/php:8.2.12-fpm-nginx-bookworm\n",{"type":17,"tag":114,"props":345,"children":346},{"class":116,"line":153},[347,352],{"type":17,"tag":114,"props":348,"children":349},{"style":304},[350],{"type":23,"value":351},"    volumes",{"type":17,"tag":114,"props":353,"children":354},{"style":127},[355],{"type":23,"value":312},{"type":17,"tag":114,"props":357,"children":358},{"class":116,"line":167},[359,364],{"type":17,"tag":114,"props":360,"children":361},{"style":127},[362],{"type":23,"value":363},"      - ",{"type":17,"tag":114,"props":365,"children":366},{"style":340},[367],{"type":23,"value":368},".:/var/www/html/:cached\n",{"type":17,"tag":99,"props":370,"children":372},{"label":371},"Updated docker-compose.yml",[373],{"type":17,"tag":104,"props":374,"children":376},{"className":292,"code":375,"language":294,"meta":7,"style":7},"services:\n  php:\n    build:\n      context: .\n      dockerfile: Dockerfile\n    volumes:\n      - .:/var/www/html/:cached\n",[377],{"type":17,"tag":38,"props":378,"children":379},{"__ignoreMap":7},[380,391,402,414,432,449,460],{"type":17,"tag":114,"props":381,"children":382},{"class":116,"line":117},[383,387],{"type":17,"tag":114,"props":384,"children":385},{"style":304},[386],{"type":23,"value":307},{"type":17,"tag":114,"props":388,"children":389},{"style":127},[390],{"type":23,"value":312},{"type":17,"tag":114,"props":392,"children":393},{"class":116,"line":133},[394,398],{"type":17,"tag":114,"props":395,"children":396},{"style":304},[397],{"type":23,"value":320},{"type":17,"tag":114,"props":399,"children":400},{"style":127},[401],{"type":23,"value":312},{"type":17,"tag":114,"props":403,"children":404},{"class":116,"line":143},[405,410],{"type":17,"tag":114,"props":406,"children":407},{"style":304},[408],{"type":23,"value":409},"    build",{"type":17,"tag":114,"props":411,"children":412},{"style":127},[413],{"type":23,"value":312},{"type":17,"tag":114,"props":415,"children":416},{"class":116,"line":153},[417,422,426],{"type":17,"tag":114,"props":418,"children":419},{"style":304},[420],{"type":23,"value":421},"      context",{"type":17,"tag":114,"props":423,"children":424},{"style":127},[425],{"type":23,"value":337},{"type":17,"tag":114,"props":427,"children":429},{"style":428},"--shiki-default:#79B8FF;--shiki-dark:#79B8FF;--shiki-sepia:#AE81FF",[430],{"type":23,"value":431},".\n",{"type":17,"tag":114,"props":433,"children":434},{"class":116,"line":167},[435,440,444],{"type":17,"tag":114,"props":436,"children":437},{"style":304},[438],{"type":23,"value":439},"      dockerfile",{"type":17,"tag":114,"props":441,"children":442},{"style":127},[443],{"type":23,"value":337},{"type":17,"tag":114,"props":445,"children":446},{"style":340},[447],{"type":23,"value":448},"Dockerfile\n",{"type":17,"tag":114,"props":450,"children":451},{"class":116,"line":175},[452,456],{"type":17,"tag":114,"props":453,"children":454},{"style":304},[455],{"type":23,"value":351},{"type":17,"tag":114,"props":457,"children":458},{"style":127},[459],{"type":23,"value":312},{"type":17,"tag":114,"props":461,"children":462},{"class":116,"line":184},[463,467],{"type":17,"tag":114,"props":464,"children":465},{"style":127},[466],{"type":23,"value":363},{"type":17,"tag":114,"props":468,"children":469},{"style":340},[470],{"type":23,"value":368},{"type":17,"tag":99,"props":472,"children":474},{"label":473},"New File: Dockerfile",[475],{"type":17,"tag":104,"props":476,"children":478},{"className":106,"code":477,"language":108,"meta":7,"style":7},"FROM serversideup/php:8.2.12-fpm-nginx-bookworm\n\n# Switch to root so we can do root things\nUSER root\n\n# Install the imagick extension with root permissions\nRUN install-php-extensions imagick\n\n# Drop back to our unprivileged user\nUSER www-data\n",[479],{"type":17,"tag":38,"props":480,"children":481},{"__ignoreMap":7},[482,493,500,507,518,525,533,545,552,559],{"type":17,"tag":114,"props":483,"children":484},{"class":116,"line":117},[485,489],{"type":17,"tag":114,"props":486,"children":487},{"style":121},[488],{"type":23,"value":124},{"type":17,"tag":114,"props":490,"children":491},{"style":127},[492],{"type":23,"value":130},{"type":17,"tag":114,"props":494,"children":495},{"class":116,"line":133},[496],{"type":17,"tag":114,"props":497,"children":498},{"emptyLinePlaceholder":137},[499],{"type":23,"value":140},{"type":17,"tag":114,"props":501,"children":502},{"class":116,"line":143},[503],{"type":17,"tag":114,"props":504,"children":505},{"style":147},[506],{"type":23,"value":150},{"type":17,"tag":114,"props":508,"children":509},{"class":116,"line":153},[510,514],{"type":17,"tag":114,"props":511,"children":512},{"style":121},[513],{"type":23,"value":159},{"type":17,"tag":114,"props":515,"children":516},{"style":127},[517],{"type":23,"value":164},{"type":17,"tag":114,"props":519,"children":520},{"class":116,"line":167},[521],{"type":17,"tag":114,"props":522,"children":523},{"emptyLinePlaceholder":137},[524],{"type":23,"value":140},{"type":17,"tag":114,"props":526,"children":527},{"class":116,"line":175},[528],{"type":17,"tag":114,"props":529,"children":530},{"style":147},[531],{"type":23,"value":532},"# Install the imagick extension with root permissions\n",{"type":17,"tag":114,"props":534,"children":535},{"class":116,"line":184},[536,540],{"type":17,"tag":114,"props":537,"children":538},{"style":121},[539],{"type":23,"value":190},{"type":17,"tag":114,"props":541,"children":542},{"style":127},[543],{"type":23,"value":544}," install-php-extensions imagick\n",{"type":17,"tag":114,"props":546,"children":547},{"class":116,"line":198},[548],{"type":17,"tag":114,"props":549,"children":550},{"emptyLinePlaceholder":137},[551],{"type":23,"value":140},{"type":17,"tag":114,"props":553,"children":554},{"class":116,"line":206},[555],{"type":17,"tag":114,"props":556,"children":557},{"style":147},[558],{"type":23,"value":212},{"type":17,"tag":114,"props":560,"children":561},{"class":116,"line":215},[562,566],{"type":17,"tag":114,"props":563,"children":564},{"style":121},[565],{"type":23,"value":159},{"type":17,"tag":114,"props":567,"children":568},{"style":127},[569],{"type":23,"value":225},{"type":17,"tag":25,"props":571,"children":572},{},[573,575,581,583,589,591,596,598,604,606,617],{"type":23,"value":574},"Notice the ",{"type":17,"tag":38,"props":576,"children":578},{"className":577},[],[579],{"type":23,"value":580},"services.php.build",{"type":23,"value":582}," options. We set a ",{"type":17,"tag":38,"props":584,"children":586},{"className":585},[],[587],{"type":23,"value":588},".",{"type":23,"value":590}," to look for a dockerfile called ",{"type":17,"tag":38,"props":592,"children":594},{"className":593},[],[595],{"type":23,"value":65},{"type":23,"value":597}," within the same directory as our ",{"type":17,"tag":38,"props":599,"children":601},{"className":600},[],[602],{"type":23,"value":603},"docker-compose.yml",{"type":23,"value":605}," file. If your project is large, you may also want to include ",{"type":17,"tag":31,"props":607,"children":610},{"href":608,"rel":609},"https://docs.docker.com/engine/reference/builder/#dockerignore-file",[35],[611],{"type":17,"tag":38,"props":612,"children":614},{"className":613},[],[615],{"type":23,"value":616},".dockerignore",{"type":23,"value":618}," to ignore files that you do not want to include in your image.",{"type":17,"tag":25,"props":620,"children":621},{},[622],{"type":23,"value":623},"For extra clarity, my project directory would look like this:",{"type":17,"tag":99,"props":625,"children":627},{"label":626},"Project File Structure",[628],{"type":17,"tag":104,"props":629,"children":633},{"className":630,"code":631,"language":632,"meta":7,"style":7},"language-txt shiki shiki-themes github-dark github-dark monokai",".\n├── Dockerfile\n├── docker-compose.yml\n└── public\n    └── index.php\n","txt",[634],{"type":17,"tag":38,"props":635,"children":636},{"__ignoreMap":7},[637,644,652,660,668],{"type":17,"tag":114,"props":638,"children":639},{"class":116,"line":117},[640],{"type":17,"tag":114,"props":641,"children":642},{},[643],{"type":23,"value":431},{"type":17,"tag":114,"props":645,"children":646},{"class":116,"line":133},[647],{"type":17,"tag":114,"props":648,"children":649},{},[650],{"type":23,"value":651},"├── Dockerfile\n",{"type":17,"tag":114,"props":653,"children":654},{"class":116,"line":143},[655],{"type":17,"tag":114,"props":656,"children":657},{},[658],{"type":23,"value":659},"├── docker-compose.yml\n",{"type":17,"tag":114,"props":661,"children":662},{"class":116,"line":153},[663],{"type":17,"tag":114,"props":664,"children":665},{},[666],{"type":23,"value":667},"└── public\n",{"type":17,"tag":114,"props":669,"children":670},{"class":116,"line":167},[671],{"type":17,"tag":114,"props":672,"children":673},{},[674],{"type":23,"value":675},"    └── index.php\n",{"type":17,"tag":25,"props":677,"children":678},{},[679],{"type":23,"value":680},"The Dockerfile is where all the magic will happen. This is where we pull the Server Side Up image as a dependency, then run standard shell commands to add the extension that we need.",{"type":17,"tag":25,"props":682,"children":683},{},[684,686,692],{"type":23,"value":685},"The next time you run ",{"type":17,"tag":38,"props":687,"children":689},{"className":688},[],[690],{"type":23,"value":691},"docker compose up",{"type":23,"value":693},", Docker will build and cache the image for you automatically.",{"type":17,"tag":25,"props":695,"children":696},{},[697,699,705,707,713],{"type":23,"value":698},"You can verify the CLI option installed correctly by using ",{"type":17,"tag":38,"props":700,"children":702},{"className":701},[],[703],{"type":23,"value":704},"php -i",{"type":23,"value":706}," in CLI or ",{"type":17,"tag":38,"props":708,"children":710},{"className":709},[],[711],{"type":23,"value":712},"phpinfo()",{"type":23,"value":714}," in a PHP file.",{"type":17,"tag":716,"props":717,"children":719},"h4",{"id":718},"️-important-note-about-caching",[720],{"type":23,"value":721},"⚠️ Important note about caching",{"type":17,"tag":723,"props":724,"children":725},"ul",{},[726,732],{"type":17,"tag":727,"props":728,"children":729},"li",{},[730],{"type":23,"value":731},"You'll notice Docker likes to cache image builds (which is great for most functions)",{"type":17,"tag":727,"props":733,"children":734},{},[735,737,742,744,750,752,759],{"type":23,"value":736},"If you make changes to your ",{"type":17,"tag":738,"props":739,"children":740},"em",{},[741],{"type":23,"value":65},{"type":23,"value":743},", you may need to include ",{"type":17,"tag":38,"props":745,"children":747},{"className":746},[],[748],{"type":23,"value":749},"--build",{"type":23,"value":751}," with your Docker compose command (",{"type":17,"tag":31,"props":753,"children":756},{"href":754,"rel":755},"https://docs.docker.com/compose/reference/up/",[35],[757],{"type":23,"value":758},"read more here",{"type":23,"value":760},")",{"type":17,"tag":25,"props":762,"children":763},{},[764],{"type":23,"value":765},"If you want to rebuild, then you would run this:",{"type":17,"tag":99,"props":767,"children":769},{"label":768},"Rebuild on Docker Compose Initialization",[770],{"type":17,"tag":104,"props":771,"children":775},{"className":772,"code":773,"language":774,"meta":7,"style":7},"language-sh shiki shiki-themes github-dark github-dark monokai","docker compose up --build\n","sh",[776],{"type":17,"tag":38,"props":777,"children":778},{"__ignoreMap":7},[779],{"type":17,"tag":114,"props":780,"children":781},{"class":116,"line":117},[782,788,793,798],{"type":17,"tag":114,"props":783,"children":785},{"style":784},"--shiki-default:#B392F0;--shiki-dark:#B392F0;--shiki-sepia:#A6E22E",[786],{"type":23,"value":787},"docker",{"type":17,"tag":114,"props":789,"children":790},{"style":340},[791],{"type":23,"value":792}," compose",{"type":17,"tag":114,"props":794,"children":795},{"style":340},[796],{"type":23,"value":797}," up",{"type":17,"tag":114,"props":799,"children":800},{"style":428},[801],{"type":23,"value":802}," --build\n",{"type":17,"tag":253,"props":804,"children":806},{"id":805},"real-life-example-showing-development-to-production",[807],{"type":23,"value":808},"Real-life example showing development to production",{"type":17,"tag":25,"props":810,"children":811},{},[812],{"type":23,"value":813},"Here's an example showing a single Dockerfile with \"multi-stage builds\" so you can call certain targets as appropriate. This file is structured to centralize the PHP extension management in a single location.",{"type":17,"tag":99,"props":815,"children":816},{"label":65},[817],{"type":17,"tag":104,"props":818,"children":820},{"className":106,"code":819,"language":108,"meta":7,"style":7},"############################################\n# Base Image\n############################################\n\n# Learn more about the Server Side Up PHP Docker Images at:\n# https://serversideup.net/open-source/docker-php/\nFROM serversideup/php:8.3-fpm-nginx AS base\n\n# Switch to root before installing our PHP extensions\nUSER root\nRUN install-php-extensions bcmath gd\n\n############################################\n# Development Image\n############################################\nFROM base AS development\n\n# We can pass USER_ID and GROUP_ID as build arguments\n# to ensure the www-data user has the same UID and GID\n# as the user running Docker.\nARG USER_ID\nARG GROUP_ID\n\n# Switch to root so we can set the user ID and group ID\nUSER root\nRUN docker-php-serversideup-set-id www-data $USER_ID:$GROUP_ID  && \\\n    docker-php-serversideup-set-file-permissions --owner $USER_ID:$GROUP_ID --service nginx\n\n# Switch back to the unprivileged www-data user\nUSER www-data\n\n############################################\n# CI image\n############################################\nFROM base AS ci\n\n# Sometimes CI images need to run as root\n# so we set the ROOT user and configure\n# the PHP-FPM pool to run as www-data\nUSER root\nRUN echo \"user = www-data\" >> /usr/local/etc/php-fpm.d/docker-php-serversideup-pool.conf && \\\n    echo \"group = www-data\" >> /usr/local/etc/php-fpm.d/docker-php-serversideup-pool.conf\n\n############################################\n# Production Image\n############################################\nFROM base AS deploy\nCOPY --chown=www-data:www-data . /var/www/html\nUSER www-data\n",[821],{"type":17,"tag":38,"props":822,"children":823},{"__ignoreMap":7},[824,832,840,847,854,862,870,892,899,907,918,931,939,947,956,964,986,994,1003,1012,1021,1035,1048,1056,1065,1077,1090,1099,1107,1116,1128,1136,1144,1153,1161,1182,1190,1199,1208,1217,1229,1252,1271,1279,1287,1296,1304,1325,1339],{"type":17,"tag":114,"props":825,"children":826},{"class":116,"line":117},[827],{"type":17,"tag":114,"props":828,"children":829},{"style":147},[830],{"type":23,"value":831},"############################################\n",{"type":17,"tag":114,"props":833,"children":834},{"class":116,"line":133},[835],{"type":17,"tag":114,"props":836,"children":837},{"style":147},[838],{"type":23,"value":839},"# Base Image\n",{"type":17,"tag":114,"props":841,"children":842},{"class":116,"line":143},[843],{"type":17,"tag":114,"props":844,"children":845},{"style":147},[846],{"type":23,"value":831},{"type":17,"tag":114,"props":848,"children":849},{"class":116,"line":153},[850],{"type":17,"tag":114,"props":851,"children":852},{"emptyLinePlaceholder":137},[853],{"type":23,"value":140},{"type":17,"tag":114,"props":855,"children":856},{"class":116,"line":167},[857],{"type":17,"tag":114,"props":858,"children":859},{"style":147},[860],{"type":23,"value":861},"# Learn more about the Server Side Up PHP Docker Images at:\n",{"type":17,"tag":114,"props":863,"children":864},{"class":116,"line":175},[865],{"type":17,"tag":114,"props":866,"children":867},{"style":147},[868],{"type":23,"value":869},"# https://serversideup.net/open-source/docker-php/\n",{"type":17,"tag":114,"props":871,"children":872},{"class":116,"line":184},[873,877,882,887],{"type":17,"tag":114,"props":874,"children":875},{"style":121},[876],{"type":23,"value":124},{"type":17,"tag":114,"props":878,"children":879},{"style":127},[880],{"type":23,"value":881}," serversideup/php:8.3-fpm-nginx ",{"type":17,"tag":114,"props":883,"children":884},{"style":121},[885],{"type":23,"value":886},"AS",{"type":17,"tag":114,"props":888,"children":889},{"style":127},[890],{"type":23,"value":891}," base\n",{"type":17,"tag":114,"props":893,"children":894},{"class":116,"line":198},[895],{"type":17,"tag":114,"props":896,"children":897},{"emptyLinePlaceholder":137},[898],{"type":23,"value":140},{"type":17,"tag":114,"props":900,"children":901},{"class":116,"line":206},[902],{"type":17,"tag":114,"props":903,"children":904},{"style":147},[905],{"type":23,"value":906},"# Switch to root before installing our PHP extensions\n",{"type":17,"tag":114,"props":908,"children":909},{"class":116,"line":215},[910,914],{"type":17,"tag":114,"props":911,"children":912},{"style":121},[913],{"type":23,"value":159},{"type":17,"tag":114,"props":915,"children":916},{"style":127},[917],{"type":23,"value":164},{"type":17,"tag":114,"props":919,"children":921},{"class":116,"line":920},11,[922,926],{"type":17,"tag":114,"props":923,"children":924},{"style":121},[925],{"type":23,"value":190},{"type":17,"tag":114,"props":927,"children":928},{"style":127},[929],{"type":23,"value":930}," install-php-extensions bcmath gd\n",{"type":17,"tag":114,"props":932,"children":934},{"class":116,"line":933},12,[935],{"type":17,"tag":114,"props":936,"children":937},{"emptyLinePlaceholder":137},[938],{"type":23,"value":140},{"type":17,"tag":114,"props":940,"children":942},{"class":116,"line":941},13,[943],{"type":17,"tag":114,"props":944,"children":945},{"style":147},[946],{"type":23,"value":831},{"type":17,"tag":114,"props":948,"children":950},{"class":116,"line":949},14,[951],{"type":17,"tag":114,"props":952,"children":953},{"style":147},[954],{"type":23,"value":955},"# Development Image\n",{"type":17,"tag":114,"props":957,"children":959},{"class":116,"line":958},15,[960],{"type":17,"tag":114,"props":961,"children":962},{"style":147},[963],{"type":23,"value":831},{"type":17,"tag":114,"props":965,"children":967},{"class":116,"line":966},16,[968,972,977,981],{"type":17,"tag":114,"props":969,"children":970},{"style":121},[971],{"type":23,"value":124},{"type":17,"tag":114,"props":973,"children":974},{"style":127},[975],{"type":23,"value":976}," base ",{"type":17,"tag":114,"props":978,"children":979},{"style":121},[980],{"type":23,"value":886},{"type":17,"tag":114,"props":982,"children":983},{"style":127},[984],{"type":23,"value":985}," development\n",{"type":17,"tag":114,"props":987,"children":989},{"class":116,"line":988},17,[990],{"type":17,"tag":114,"props":991,"children":992},{"emptyLinePlaceholder":137},[993],{"type":23,"value":140},{"type":17,"tag":114,"props":995,"children":997},{"class":116,"line":996},18,[998],{"type":17,"tag":114,"props":999,"children":1000},{"style":147},[1001],{"type":23,"value":1002},"# We can pass USER_ID and GROUP_ID as build arguments\n",{"type":17,"tag":114,"props":1004,"children":1006},{"class":116,"line":1005},19,[1007],{"type":17,"tag":114,"props":1008,"children":1009},{"style":147},[1010],{"type":23,"value":1011},"# to ensure the www-data user has the same UID and GID\n",{"type":17,"tag":114,"props":1013,"children":1015},{"class":116,"line":1014},20,[1016],{"type":17,"tag":114,"props":1017,"children":1018},{"style":147},[1019],{"type":23,"value":1020},"# as the user running Docker.\n",{"type":17,"tag":114,"props":1022,"children":1024},{"class":116,"line":1023},21,[1025,1030],{"type":17,"tag":114,"props":1026,"children":1027},{"style":121},[1028],{"type":23,"value":1029},"ARG",{"type":17,"tag":114,"props":1031,"children":1032},{"style":127},[1033],{"type":23,"value":1034}," USER_ID\n",{"type":17,"tag":114,"props":1036,"children":1038},{"class":116,"line":1037},22,[1039,1043],{"type":17,"tag":114,"props":1040,"children":1041},{"style":121},[1042],{"type":23,"value":1029},{"type":17,"tag":114,"props":1044,"children":1045},{"style":127},[1046],{"type":23,"value":1047}," GROUP_ID\n",{"type":17,"tag":114,"props":1049,"children":1051},{"class":116,"line":1050},23,[1052],{"type":17,"tag":114,"props":1053,"children":1054},{"emptyLinePlaceholder":137},[1055],{"type":23,"value":140},{"type":17,"tag":114,"props":1057,"children":1059},{"class":116,"line":1058},24,[1060],{"type":17,"tag":114,"props":1061,"children":1062},{"style":147},[1063],{"type":23,"value":1064},"# Switch to root so we can set the user ID and group ID\n",{"type":17,"tag":114,"props":1066,"children":1068},{"class":116,"line":1067},25,[1069,1073],{"type":17,"tag":114,"props":1070,"children":1071},{"style":121},[1072],{"type":23,"value":159},{"type":17,"tag":114,"props":1074,"children":1075},{"style":127},[1076],{"type":23,"value":164},{"type":17,"tag":114,"props":1078,"children":1080},{"class":116,"line":1079},26,[1081,1085],{"type":17,"tag":114,"props":1082,"children":1083},{"style":121},[1084],{"type":23,"value":190},{"type":17,"tag":114,"props":1086,"children":1087},{"style":127},[1088],{"type":23,"value":1089}," docker-php-serversideup-set-id www-data $USER_ID:$GROUP_ID  && \\\n",{"type":17,"tag":114,"props":1091,"children":1093},{"class":116,"line":1092},27,[1094],{"type":17,"tag":114,"props":1095,"children":1096},{"style":127},[1097],{"type":23,"value":1098},"    docker-php-serversideup-set-file-permissions --owner $USER_ID:$GROUP_ID --service nginx\n",{"type":17,"tag":114,"props":1100,"children":1102},{"class":116,"line":1101},28,[1103],{"type":17,"tag":114,"props":1104,"children":1105},{"emptyLinePlaceholder":137},[1106],{"type":23,"value":140},{"type":17,"tag":114,"props":1108,"children":1110},{"class":116,"line":1109},29,[1111],{"type":17,"tag":114,"props":1112,"children":1113},{"style":147},[1114],{"type":23,"value":1115},"# Switch back to the unprivileged www-data user\n",{"type":17,"tag":114,"props":1117,"children":1119},{"class":116,"line":1118},30,[1120,1124],{"type":17,"tag":114,"props":1121,"children":1122},{"style":121},[1123],{"type":23,"value":159},{"type":17,"tag":114,"props":1125,"children":1126},{"style":127},[1127],{"type":23,"value":225},{"type":17,"tag":114,"props":1129,"children":1131},{"class":116,"line":1130},31,[1132],{"type":17,"tag":114,"props":1133,"children":1134},{"emptyLinePlaceholder":137},[1135],{"type":23,"value":140},{"type":17,"tag":114,"props":1137,"children":1139},{"class":116,"line":1138},32,[1140],{"type":17,"tag":114,"props":1141,"children":1142},{"style":147},[1143],{"type":23,"value":831},{"type":17,"tag":114,"props":1145,"children":1147},{"class":116,"line":1146},33,[1148],{"type":17,"tag":114,"props":1149,"children":1150},{"style":147},[1151],{"type":23,"value":1152},"# CI image\n",{"type":17,"tag":114,"props":1154,"children":1156},{"class":116,"line":1155},34,[1157],{"type":17,"tag":114,"props":1158,"children":1159},{"style":147},[1160],{"type":23,"value":831},{"type":17,"tag":114,"props":1162,"children":1164},{"class":116,"line":1163},35,[1165,1169,1173,1177],{"type":17,"tag":114,"props":1166,"children":1167},{"style":121},[1168],{"type":23,"value":124},{"type":17,"tag":114,"props":1170,"children":1171},{"style":127},[1172],{"type":23,"value":976},{"type":17,"tag":114,"props":1174,"children":1175},{"style":121},[1176],{"type":23,"value":886},{"type":17,"tag":114,"props":1178,"children":1179},{"style":127},[1180],{"type":23,"value":1181}," ci\n",{"type":17,"tag":114,"props":1183,"children":1185},{"class":116,"line":1184},36,[1186],{"type":17,"tag":114,"props":1187,"children":1188},{"emptyLinePlaceholder":137},[1189],{"type":23,"value":140},{"type":17,"tag":114,"props":1191,"children":1193},{"class":116,"line":1192},37,[1194],{"type":17,"tag":114,"props":1195,"children":1196},{"style":147},[1197],{"type":23,"value":1198},"# Sometimes CI images need to run as root\n",{"type":17,"tag":114,"props":1200,"children":1202},{"class":116,"line":1201},38,[1203],{"type":17,"tag":114,"props":1204,"children":1205},{"style":147},[1206],{"type":23,"value":1207},"# so we set the ROOT user and configure\n",{"type":17,"tag":114,"props":1209,"children":1211},{"class":116,"line":1210},39,[1212],{"type":17,"tag":114,"props":1213,"children":1214},{"style":147},[1215],{"type":23,"value":1216},"# the PHP-FPM pool to run as www-data\n",{"type":17,"tag":114,"props":1218,"children":1220},{"class":116,"line":1219},40,[1221,1225],{"type":17,"tag":114,"props":1222,"children":1223},{"style":121},[1224],{"type":23,"value":159},{"type":17,"tag":114,"props":1226,"children":1227},{"style":127},[1228],{"type":23,"value":164},{"type":17,"tag":114,"props":1230,"children":1232},{"class":116,"line":1231},41,[1233,1237,1242,1247],{"type":17,"tag":114,"props":1234,"children":1235},{"style":121},[1236],{"type":23,"value":190},{"type":17,"tag":114,"props":1238,"children":1239},{"style":127},[1240],{"type":23,"value":1241}," echo ",{"type":17,"tag":114,"props":1243,"children":1244},{"style":340},[1245],{"type":23,"value":1246},"\"user = www-data\"",{"type":17,"tag":114,"props":1248,"children":1249},{"style":127},[1250],{"type":23,"value":1251}," >> /usr/local/etc/php-fpm.d/docker-php-serversideup-pool.conf && \\\n",{"type":17,"tag":114,"props":1253,"children":1255},{"class":116,"line":1254},42,[1256,1261,1266],{"type":17,"tag":114,"props":1257,"children":1258},{"style":127},[1259],{"type":23,"value":1260},"    echo ",{"type":17,"tag":114,"props":1262,"children":1263},{"style":340},[1264],{"type":23,"value":1265},"\"group = www-data\"",{"type":17,"tag":114,"props":1267,"children":1268},{"style":127},[1269],{"type":23,"value":1270}," >> /usr/local/etc/php-fpm.d/docker-php-serversideup-pool.conf\n",{"type":17,"tag":114,"props":1272,"children":1274},{"class":116,"line":1273},43,[1275],{"type":17,"tag":114,"props":1276,"children":1277},{"emptyLinePlaceholder":137},[1278],{"type":23,"value":140},{"type":17,"tag":114,"props":1280,"children":1282},{"class":116,"line":1281},44,[1283],{"type":17,"tag":114,"props":1284,"children":1285},{"style":147},[1286],{"type":23,"value":831},{"type":17,"tag":114,"props":1288,"children":1290},{"class":116,"line":1289},45,[1291],{"type":17,"tag":114,"props":1292,"children":1293},{"style":147},[1294],{"type":23,"value":1295},"# Production Image\n",{"type":17,"tag":114,"props":1297,"children":1299},{"class":116,"line":1298},46,[1300],{"type":17,"tag":114,"props":1301,"children":1302},{"style":147},[1303],{"type":23,"value":831},{"type":17,"tag":114,"props":1305,"children":1307},{"class":116,"line":1306},47,[1308,1312,1316,1320],{"type":17,"tag":114,"props":1309,"children":1310},{"style":121},[1311],{"type":23,"value":124},{"type":17,"tag":114,"props":1313,"children":1314},{"style":127},[1315],{"type":23,"value":976},{"type":17,"tag":114,"props":1317,"children":1318},{"style":121},[1319],{"type":23,"value":886},{"type":17,"tag":114,"props":1321,"children":1322},{"style":127},[1323],{"type":23,"value":1324}," deploy\n",{"type":17,"tag":114,"props":1326,"children":1328},{"class":116,"line":1327},48,[1329,1334],{"type":17,"tag":114,"props":1330,"children":1331},{"style":121},[1332],{"type":23,"value":1333},"COPY",{"type":17,"tag":114,"props":1335,"children":1336},{"style":127},[1337],{"type":23,"value":1338}," --chown=www-data:www-data . /var/www/html\n",{"type":17,"tag":114,"props":1340,"children":1342},{"class":116,"line":1341},49,[1343,1347],{"type":17,"tag":114,"props":1344,"children":1345},{"style":121},[1346],{"type":23,"value":159},{"type":17,"tag":114,"props":1348,"children":1349},{"style":127},[1350],{"type":23,"value":225},{"type":17,"tag":253,"props":1352,"children":1354},{"id":1353},"common-php-extensions-that-you-might-need",[1355],{"type":23,"value":1356},"Common PHP extensions that you might need",{"type":17,"tag":25,"props":1358,"children":1359},{},[1360],{"type":23,"value":1361},"We compiled a list of extensions for you to reference.",{"type":17,"tag":1363,"props":1364,"children":1366},"h3",{"id":1365},"intl",[1367],{"type":23,"value":1365},{"type":17,"tag":25,"props":1369,"children":1370},{},[1371,1377],{"type":17,"tag":31,"props":1372,"children":1375},{"href":1373,"rel":1374},"https://www.php.net/manual/en/intro.intl.php",[35],[1376],{"type":23,"value":1365},{"type":23,"value":1378}," is a PHP module that provides internationalization functions. You may want to install this module if you're using Laravel, specifically if you are validating emails with \"DNS\" or \"spoof\" validation.",{"type":17,"tag":25,"props":1380,"children":1381},{},[1382],{"type":23,"value":1383},"Our tests showed this module will add about 40 MB of space to the Docker image, so we decided to not include it by default.",{"type":17,"tag":25,"props":1385,"children":1386},{},[1387],{"type":17,"tag":31,"props":1388,"children":1391},{"href":1389,"rel":1390},"https://laravel.com/docs/10.x/validation#rule-email",[35],[1392],{"type":23,"value":1393},"Learn more about the \"intl\" requirement for Laravel →",{"type":17,"tag":1363,"props":1395,"children":1397},{"id":1396},"dont-see-the-extension-you-need",[1398],{"type":23,"value":1399},"Don't see the extension you need?",{"type":17,"tag":25,"props":1401,"children":1402},{},[1403,1405],{"type":23,"value":1404},"If you're having trouble, ",{"type":17,"tag":31,"props":1406,"children":1409},{"href":1407,"rel":1408},"https://github.com/serversideup/docker-php/discussions/new?category=q-a",[35],[1410],{"type":23,"value":1411},"open a discussion on GitHub →",{"type":17,"tag":1413,"props":1414,"children":1415},"style",{},[1416],{"type":23,"value":1417},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html .sepia .shiki span {color: var(--shiki-sepia);background: var(--shiki-sepia-bg);font-style: var(--shiki-sepia-font-style);font-weight: var(--shiki-sepia-font-weight);text-decoration: var(--shiki-sepia-text-decoration);}html.sepia .shiki span {color: var(--shiki-sepia);background: var(--shiki-sepia-bg);font-style: var(--shiki-sepia-font-style);font-weight: var(--shiki-sepia-font-weight);text-decoration: var(--shiki-sepia-text-decoration);}",{"title":7,"searchDepth":133,"depth":133,"links":1419},[1420,1421,1422],{"id":255,"depth":133,"text":258},{"id":805,"depth":133,"text":808},{"id":1353,"depth":133,"text":1356,"children":1423},[1424,1425],{"id":1365,"depth":143,"text":1365},{"id":1396,"depth":143,"text":1399},"markdown","content:docs:5.customizing-the-image:2.installing-additional-php-extensions.md","content","docs/5.customizing-the-image/2.installing-additional-php-extensions.md","md",1727367946692]