--- title: 'Install nginx in Docker' disqus: hackmd --- Install Nginx And PHP in Ubuntu Use Docker === ## Step 1 - Install Ubuntu **CMD** - DownLoad Ubuntu ```gherkin= 1.docker pull phusion/baseimage 2.docker run -dit -p 80:80 phusion/baseimage ``` ## Step 2 - Install Nginx **CMD** - Into Bash ```gherkin= 1.docker exec -it CONTAINER_ID bash ``` **Bash** ```gherkin= apt-get update apt-get install nginx ``` ## Step 3 - Install PHP **Bash** - Install ```gherkin= apt-add-repository ppa:ondrej/php apt-get update apt-get install php7.1 php7.1-fpm ``` - Create PHP Directory ```gherkin= mkdir -p /run/php ``` ## Step 4 - Edit Configuration - Path - /etc/nginx/sites-available ```gherkin= vim etc/nginx/site-available/default ``` - Modify content ```gherkin= location ~ \.php$ { include snippets/fastcgi-php.conf; # With php7.0-cgi alone: # fastcgi_pass 127.0.0.1:9000; # With php7.0-fpm: fastcgi_pass unix:/run/php/php7.1-fpm.sock; } # Add index.php to the list if you are using PHP index index.php index.html index.htm index.nginx-debian.html; ``` - Path - /etc/php/7.1/fpm/pool.d/www.conf ```gherkin= listen = /run/php/php7.1-fpm.sock ``` ## Step 5 - Create test file - Remove default html and add new index file **Bash** ```gherkin= rm -rf /var/www/html/* touch /var/www/html/index.php ``` - Into index.html to edit content ```gherkin= vim /var/www/html/index.php ``` - Insert php info into file ```gherkin= <?php phpinfo(); ``` ## Step 6 - Reload **Bash** ```gherkin= php-fpm7.1 nginx -s reload ``` ## Step 7 - Run Test ```gherkin= curl 127.0.0.1 ```