InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

Docker tutorials

  • Docker quick start guide on Mac
  • Docker quick start guide on Ubuntu
  • Docker how to add a user to group docker on Linux
  • Docker container - handy commands
  • How to get docker container IP
  • Run nginx in docker container
  • Ubuntu docker - storage driver aufs not supported error
  • How to find docker host ip on Mac
  • Docker - how to rerun a container with different flags
  • Docker managing images - command line cheat sheet
  • Install nginx and php in docker ubuntu container
 
  • Home
  • > Tutorials
  • > Docker

Install nginx and php in docker ubuntu container

on Feb 13, 2016

Docker can be used to install nginx and php5 (php-mpm) in a ubuntu container. We’ll cover docker running on Mac and Ubuntu Linux for the purpose of this tutorial. The steps are mostly same for both environments.

  1. Download ubuntu image and run it. We’ll use -p 8081:80 when running docker container to make its port 80 available on host port 8081.

    $ docker pull ubuntu
    $ docker run -it -p 8081:80 --name nginxphp1 ubuntu /bin/bash
    docker
    
  2. Install nginx and php5-fpm (in docker)

    $ apt-get update
    $ apt-get upgrade
    $ apt-get install nginx
    $ apt-get install php5-fpm
    $ service nginx start
    $ service php5-fpm start 
    
  3. Extra step for Mac. Find docker host IP for mac as it is not localhost for Mac.

    $ docker-machine ip default
    192.168.99.100
    

    Note that for Mac, instead of localhost, we’ll use this ip.

  4. Check if ngnix is working by visiting localhost:8081 (or docker_host_ip:8081 for Mac) in browser and you should be able to see nginx default page.
    nginx-default-page
  5. Edit default site settings in /etc/nginx/sites-available/default and uncomment php settings. It should look like this.
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            #
            location ~ \.php$ {
                    fastcgi_split_path_info ^(.+\.php)(/.+)$;
                    # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
            
                    # With php5-cgi alone:
                    # fastcgi_pass 127.0.0.1:9000;
                    # With php5-fpm:
                    fastcgi_pass unix:/var/run/php5-fpm.sock;
                    fastcgi_index index.php;
                    include fastcgi_params;
            }

    Note that we have kept fastcgi_pass commented out.

    Now restart nginx

    $ service nginx restart
    
  6. Now edit /etc/php5/fpm/php.ini and
    add cgi.fix_pathinfo = 0 in relevant section. Then restart php5-fpm

    $ service php5-fpm restart
     * Restarting PHP5 FastCGI Process Manager php5-fpm
    
  7. Start service nginx and php5-fpm

    service nginx start
    service php5-fpm start
  8. Create file info.php in directory /usr/share/nginx/html/ with the following content:
    <?php
      phpinfo();
    ?>

    Now visit localhost:8081/info.php (or docker_host_ip:8081/info.php for Mac) and you should be able to see php info page.
    docker-ubuntu-nginx-php5-fpm-phpinfo-page

Suggested posts:

  1. Docker container – handy commands
  2. LXC (Linux Containers) – quick start tutorial on Ubuntu
  3. Docker how to add a user to group docker on Linux
  4. How to use wildcard in robots.txt
  5. Ubuntu – how to auto start services on boot using update-rc.d (sysv init)
  6. Javascript arrow function examples
  7. How to find docker host ip on Mac
  8. PHP apc – setup and performance benchmarks on Ubuntu Linux
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged Docker, Tutorials
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress