{"id":3025,"date":"2018-03-08T22:20:48","date_gmt":"2018-03-08T19:20:48","guid":{"rendered":"https:\/\/www.howtoforge.com\/tutorial\/ubuntu-caddy-web-server-installation\/"},"modified":"2018-03-08T22:20:48","modified_gmt":"2018-03-08T19:20:48","slug":"how-to-install-caddy-web-server-with-php-fpm-on-ubuntu-16-04","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/how-to-install-caddy-web-server-with-php-fpm-on-ubuntu-16-04\/","title":{"rendered":"How to Install Caddy Web Server with PHP-FPM on Ubuntu 16.04"},"content":{"rendered":"<p>Caddy or Caddy web server is an open source HTTP\/2 enabled web server written in Go. Caddy can run on various systems, including those running Linux, Windows, Mac OS, Android, and BSD operating systems. Caddy has a lot of features and can be installed as a web server and as a reverse proxy for your application. The most notable Caddy web server features are automatic HTTPS enabled by default with no extra configuration.<\/p>\n<p>In this tutorial, I will show you step by step how to install and configure the Caddy web server with PHP-FPM 7.x on Ubuntu 16.04. We will install caddy in the local environment, and then configure PHP-FPM for PHP\u00a0based applications.<\/p>\n<h2 id=\"prerequisites\">Prerequisites<\/h2>\n<ul>\n<li>Ubuntu 16.04 server<\/li>\n<li>Root privileges<\/li>\n<\/ul>\n<h2 id=\"what-we-will-do\">What we will do<\/h2>\n<ol>\n<li>Install Caddy web server<\/li>\n<li>Configure Caddy web server<\/li>\n<li>Running Caddy as a Service on Systemd Ubuntu 16.04<\/li>\n<li>Install PHP and PHP-FPM 7.0<\/li>\n<li>Configure Caddy web server with PHP-FPM<\/li>\n<li>Testing<\/li>\n<\/ol>\n<h2 id=\"step-install-caddy-web-server\">Step 1 &#8211; Install Caddy web server<\/h2>\n<p>In this step, we will install the Caddy web server using the installer script. The script will automatically download the binary file and extract it to the bin directory.<\/p>\n<p>Download the installer script and make it executable.<\/p>\n<p class=\"command\">wget https:\/\/getcaddy.com -O getcaddy<br \/>chmod +x getcaddy<\/p>\n<p>Now run the installer script with sudo.<\/p>\n<p class=\"command\">sudo .\/getcaddy personal http.ipfilter,http.ratelimit<\/p>\n<p><strong>Note:<\/strong><\/p>\n<ul>\n<li><em>getcaddy<\/em> = caddy installer script.<\/li>\n<li><em>personal<\/em> = license for our installation.<\/li>\n<li><em>http.ipfileter &#8230;<\/em> = include caddy plugins installation.<\/li>\n<\/ul>\n<p>Wait for the caddy web server installation and you will get the result as below.<\/p>\n<p><a class=\"fancybox\" id=\"img-1\" href=\"https:\/\/www.howtoforge.com\/images\/how_to_install_caddy_web_server_with_php_fpm_on_ubuntu_1604\/big\/1.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/03\/how-to-install-caddy-web-server-with-php-fpm-on-ubuntu-16-04.png\" alt=\"Install Caddy web server\" width=\"500\" height=\"186\" title=\"\"><\/a><\/p>\n<p>Caddy web server has been installed on Ubuntu 16.04.<\/p>\n<h2 id=\"step-basic-caddy-web-server-configuration\">Step 2 &#8211; Basic Caddy web server configuration<\/h2>\n<p>In this step, we will configure the Caddy web server. We will create a new user named &#8216;caddy&#8217;, create a new directory for caddy configuration file, a new directory for caddy log files and a new directory for caddy web root directory.<\/p>\n<p>Create a new &#8216;caddy&#8217; user using the &#8216;\/bin\/false&#8217; option as shown below.<\/p>\n<p class=\"command\">useradd -M -s \/bin\/false caddy<\/p>\n<p>Now run the following mkdir commands to create the caddy directory.<\/p>\n<p class=\"command\">mkdir -p \/etc\/caddy<br \/>mkdir -p \/var\/log\/caddy<br \/>mkdir -p \/var\/www\/html<\/p>\n<p>And change the ownership to the caddy user.<\/p>\n<p class=\"command\">chown -R caddy:root \/etc\/caddy \/var\/log\/caddy<\/p>\n<p>Next, we will create new caddy configuration file named &#8216;Caddyfile&#8217;. Go to the &#8216;\/etc\/caddy&#8217; directory and create the configuration with the\u00a0<a href=\"https:\/\/www.howtoforge.com\/vim-basics\" target=\"_blank\" rel=\"noopener noreferrer\">vim<\/a> command.<\/p>\n<p class=\"command\">cd \/etc\/caddy\/<br \/>vim Caddyfile<\/p>\n<p>Paste basic caddy configuration there.<\/p>\n<pre class=\"system\">http:\/\/hakase-labs.co {<br\/>\u00a0\u00a0\u00a0 root \/var\/www\/html<br\/>\u00a0\u00a0\u00a0 log \/var\/log\/caddy\/hakase-labs.log<br\/>\u00a0\u00a0\u00a0 tls off<br\/>\u00a0\u00a0\u00a0 gzip<br\/>}<\/pre>\n<p>Save and exit.<\/p>\n<p><strong>Note:<\/strong><\/p>\n<ul>\n<li>tls off = we&#8217;re running caddy on the local server, if you&#8217;re on the live server, enable the option.<\/li>\n<\/ul>\n<p><a class=\"fancybox\" id=\"img-2\" href=\"https:\/\/www.howtoforge.com\/images\/how_to_install_caddy_web_server_with_php_fpm_on_ubuntu_1604\/big\/2.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/03\/how-to-install-caddy-web-server-with-php-fpm-on-ubuntu-16-04-1.png\" alt=\"Caddy web server configuration\" width=\"500\" height=\"196\" title=\"\"><\/a><\/p>\n<p>Basic configuration for Caddy web server has been completed.<\/p>\n<h2 id=\"step-running-caddy-as-a-service-on-systemd-ubuntu-\">Step 3 &#8211; Running Caddy as a Service on Systemd Ubuntu 16.04<\/h2>\n<p>In this step, we will run the caddy web server as service on systemd system and create the index.html file for our caddy web server.<\/p>\n<p>Create new service file named &#8216;caddy.service&#8217; using vim.<\/p>\n<p class=\"command\">vim \/etc\/systemd\/system\/caddy.service<\/p>\n<p>Paste the following configuration there.<\/p>\n<pre class=\"system\" readability=\"9\">[Unit]<br\/>Description=Caddy HTTP\/2 web server<p>[Service]<br\/>User=caddy<br\/>Group=caddy<br\/>Environment=CADDYPATH=\/etc\/caddy<br\/>ExecStart=\/usr\/local\/bin\/caddy -agree=true -log=\/var\/log\/caddy\/caddy.log -conf=\/etc\/caddy\/Caddyfile -root=\/dev\/null<br\/>ExecReload=\/bin\/kill -USR1 $MAINPID<br\/>LimitNOFILE=1048576<br\/>LimitNPROC=64<\/p><p>[Install]<br\/>WantedBy=multi-user.target<\/p><\/pre>\n<p>Save and exit.<\/p>\n<p>Now reload the systemd system and start the caddy service using the systemctl command as shown below.<\/p>\n<p class=\"command\">systemctl daemon-reload<br \/>systemctl start caddy<\/p>\n<p>Enable it to launch everytime at system boot.<\/p>\n<p class=\"command\">systemctl enable caddy<\/p>\n<p>The Caddy web server is now running as a service on Ubuntu 16.04.<\/p>\n<p><a class=\"fancybox\" id=\"img-3\" href=\"https:\/\/www.howtoforge.com\/images\/how_to_install_caddy_web_server_with_php_fpm_on_ubuntu_1604\/big\/3.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/03\/how-to-install-caddy-web-server-with-php-fpm-on-ubuntu-16-04-2.png\" alt=\"Running Caddy as a Service on Systemd Ubuntu 16.04\" width=\"500\" height=\"238\" title=\"\"><\/a><\/p>\n<p>Next, we will create a new index.html file under the web root directory &#8216;\/var\/www\/html&#8217;.<\/p>\n<p>Go to that directory and create the index.html file using commands below.<\/p>\n<p class=\"command\">cd \/var\/www\/html<br \/>echo &#8216;&lt;h1&gt;&lt;center&gt;Caddy web server&lt;\/center&gt;&lt;\/h1&gt;&#8217; &gt; index.html<\/p>\n<p>Now change the owner of the file to the &#8216;caddy&#8217; user and group.<\/p>\n<p class=\"command\">chown -R caddy:caddy \/var\/www\/html<\/p>\n<p>The index.html file has been created. Open the web browser and type the domain name address that you typed on the &#8216;Caddyfile&#8217; configuration, mine is:<\/p>\n<p><em><strong>http:\/\/hakase-labs.co\/<\/strong><\/em><\/p>\n<p>And you will get the index page that we&#8217;ve created.<\/p>\n<p><a class=\"fancybox\" id=\"img-4\" href=\"https:\/\/www.howtoforge.com\/images\/how_to_install_caddy_web_server_with_php_fpm_on_ubuntu_1604\/big\/4.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/03\/how-to-install-caddy-web-server-with-php-fpm-on-ubuntu-16-04-3.png\" alt=\"Caddy web server is running\" width=\"500\" height=\"120\" title=\"\"><\/a><\/p>\n<h2 id=\"step-install-php-and-phpfpm-\">Step 4 &#8211; Install PHP and PHP-FPM 7.0<\/h2>\n<p>In this step, we will install PHP-FPM packages from the Ubuntu repository.<\/p>\n<p>Run the apt command below.<\/p>\n<p class=\"command\">sudo apt install -y php7.0-fpm php7.0-cli curl<\/p>\n<p>After the installation is complete, we will configure the configuration file for PHP-FPM.<\/p>\n<p>Go to the &#8216;\/etc\/php\/7.0\/fpm&#8217; directory and edit the pool configuration file &#8216;www&#8217;conf&#8217; using vim.<\/p>\n<p class=\"command\">cd \/etc\/php\/7.0\/fpm<br \/>vim pool.d\/www.conf<\/p>\n<p>Uncomment lines below.<\/p>\n<p class=\"system\">listen.owner = www-data<br \/>listen.group = www-data<br \/>listen.mode = 0660<\/p>\n<p>Save and exit.<\/p>\n<p>Now add the &#8216;caddy&#8217; user to the &#8216;www-data&#8217; group.<\/p>\n<p class=\"command\">usermod -a -G www-data caddy<\/p>\n<p>Start the PHP-FPM service and enable it to launch everytime at system boot.<\/p>\n<p class=\"command\">systemctl start php7.0-fpm<br \/>systemctl enable php7.0-fpm<\/p>\n<p>PHP-FPM installation and configuration for our Caddy web server installation have been completed.<\/p>\n<p><a class=\"fancybox\" id=\"img-5\" href=\"https:\/\/www.howtoforge.com\/images\/how_to_install_caddy_web_server_with_php_fpm_on_ubuntu_1604\/big\/5.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/03\/how-to-install-caddy-web-server-with-php-fpm-on-ubuntu-16-04-4.png\" alt=\"Install PHP and PHP-FPM 7.0\" width=\"500\" height=\"180\" title=\"\"><\/a><\/p>\n<p>Check the PHP-FPM socket file process using the netstat command below.<\/p>\n<p class=\"command\">netstat -pl | grep php<\/p>\n<h2 id=\"step-configure-caddy-web-server-with-phpfpm\">Step 5 &#8211; Configure Caddy web server with PHP-FPM<\/h2>\n<p>After the PHP-FPM installation and configuration, we will add PHP-FPM support to the Caddy web server.<\/p>\n<p>Go to the &#8216;\/etc\/caddy&#8217; configuration directory and edit the configuration file &#8216;Caddyfile&#8217; using vim.<\/p>\n<p class=\"command\">cd \/etc\/caddy<br \/>vim Caddyfile<\/p>\n<p>Now add the following PHP-FPM configuration for caddy under your domain name bracket as below.<\/p>\n<pre class=\"system\" readability=\"6\">http:\/\/hakase-labs.co {<br\/>\u00a0\u00a0\u00a0 root \/var\/www\/html<br\/>\u00a0\u00a0\u00a0 log \/var\/log\/caddy\/hakase-labs.log<br\/>\u00a0\u00a0\u00a0 errors \/var\/log\/caddy\/errors.log<br\/>\u00a0\u00a0\u00a0 tls off<br\/>\u00a0\u00a0\u00a0 gzip<p>\u00a0\u00a0\u00a0 # PHP-FPM Configuration for Caddy<br\/>\u00a0\u00a0\u00a0 fastcgi \/ \/run\/php\/php7.0-fpm.sock php {<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ext .php<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 split .php<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 index index.php<br\/>\u00a0\u00a0\u00a0 }<br\/>}<\/p><\/pre>\n<p>Save and exit.<\/p>\n<p>Restart the caddy web server and the PHP-FPM service.<\/p>\n<p class=\"command\">systemctl restart caddy<br \/>systemctl restart php7.0-fpm<\/p>\n<p>The Caddy web server configuration with PHP-FPM has been completed.<\/p>\n<p><a class=\"fancybox\" id=\"img-6\" href=\"https:\/\/www.howtoforge.com\/images\/how_to_install_caddy_web_server_with_php_fpm_on_ubuntu_1604\/big\/6.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/03\/how-to-install-caddy-web-server-with-php-fpm-on-ubuntu-16-04-5.png\" alt=\"Configure Caddy web server with PHP-FPM\" width=\"500\" height=\"165\" title=\"\"><\/a><\/p>\n<h2 id=\"step-testing\">Step 6 &#8211; Testing<\/h2>\n<p>Go to the web root directory &#8216;\/var\/ww\/html&#8217; and create the phpinfo file &#8216;info.php&#8217;.<\/p>\n<p class=\"command\">cd \/var\/www\/html<br \/>echo &#8216;&lt;?php phpinfo(); ?&gt;&#8217; &gt; info.php<\/p>\n<p>Open your web browser and type the Caddy web server URL installation as below.<\/p>\n<p><em><strong>http:\/\/hakase-labs.co\/info.php<\/strong><\/em><\/p>\n<p>And you will get the PHP information page as shown below.<\/p>\n<p><a class=\"fancybox\" id=\"img-7\" href=\"https:\/\/www.howtoforge.com\/images\/how_to_install_caddy_web_server_with_php_fpm_on_ubuntu_1604\/big\/7.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/03\/how-to-install-caddy-web-server-with-php-fpm-on-ubuntu-16-04-6.png\" alt=\"Testing Caddy Web Server\" width=\"500\" height=\"289\" title=\"\"><\/a><\/p>\n<p>Installation for Caddy web server with PHP-FPM on Ubuntu 16.04 has been completed successfully.<\/p>\n<h2 id=\"reference\">Reference<\/h2>\n<div>\n<p><b>Share this page:<\/b><\/p>\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Caddy or Caddy web server is an open source HTTP\/2 enabled web server written in Go. Caddy can run on various systems, including those running Linux, Windows, Mac OS, Android, and BSD operating systems. Caddy has a lot of features and can be installed as a web server and as a reverse proxy for your &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-3025","post","type-post","status-publish","format-standard","hentry","category-36"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/3025","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=3025"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/3025\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=3025"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=3025"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=3025"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}