{"id":12940,"date":"2019-03-29T03:35:04","date_gmt":"2019-03-29T03:35:04","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=12940"},"modified":"2019-03-29T03:35:04","modified_gmt":"2019-03-29T03:35:04","slug":"how-to-install-lighttpd-with-php-php-fpm-and-mariadb-on-centos-7","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/29\/how-to-install-lighttpd-with-php-php-fpm-and-mariadb-on-centos-7\/","title":{"rendered":"How to Install Lighttpd with PHP, PHP-FPM and MariaDB on CentOS 7"},"content":{"rendered":"<p><strong>Lighttpd<\/strong>\u00a0is an open source, secure, fast, flexible and more optimized web server designed for speed-critical environments with less memory utilization as compared to other web servers.<\/p>\n<p>It can handle up-to\u00a0<strong>10,000<\/strong>\u00a0connections parallel in one server with effective cpu-load management and comes with advanced feature set such as FastCGI, SCGI, Auth, Output-Compression, URL-Rewriting and many more.<\/p>\n<p><strong>Lighttpd<\/strong>\u00a0is the excellent solution for every Linux server, due to its high speed io-infrastructure that allows us to scale several times better performance with the same hardware than with other alternative web-servers.<\/p>\n<p>In this tutorial, we will explain how to install\u00a0<strong>Lighttpd<\/strong>\u00a0with\u00a0<strong>PHP-FPM<\/strong>\u00a0and\u00a0<strong>MariaDB<\/strong>\u00a0on\u00a0<strong>CentOS\/RHEL 7<\/strong>distributions with hostname\u00a0<strong>tecmint.example.com<\/strong>\u00a0and IP address\u00a0<strong>192.168.0.103<\/strong>.<\/p>\n<h3>Step 1: Install Lighttpd on CentOS 7<\/h3>\n<p><strong>1.<\/strong>\u00a0To install\u00a0<strong>Lighttpd<\/strong>, first you need to update your system software packages and available repositories using following command.<\/p>\n<pre># yum -y update\r\n<\/pre>\n<p><strong>2.<\/strong>\u00a0Next, you need to enable EPEL repository on your system and update software packages using following commands.<\/p>\n<pre># yum -y install epel-release\r\n# yum -y update\r\n<\/pre>\n<p><strong>3.<\/strong>\u00a0Once you\u2019ve enabled EPEL repository, you can now install\u00a0<strong>Lighttpd<\/strong>\u00a0by running the following command.<\/p>\n<pre># yum install lighttpd\r\n<\/pre>\n<p><strong>4.<\/strong>\u00a0Once the\u00a0<strong>Lighttpd<\/strong>\u00a0packages are installed, you can start and enable the service to automatically start at boot time and make sure to verify the status using the following commands.<\/p>\n<pre># systemctl start lighttpd\r\n# systemctl enable lighttpd\r\n# systemctl status lighttpd\r\n<\/pre>\n<p>If you see any error message similar to below in the status, you need to fix few things to get it start properly without displaying any error messages.<\/p>\n<pre>Dec 10 02:14:26 tecmint.com lighttpd[1463]: 2018-12-10 02:14:26: (network.c.167) warning: please use server.use-ipv6 only for hostnames, not without server.bind \/ empty address...ONLY changes\r\nDec 10 02:14:26 tecmint.com lighttpd[1463]: 2018-12-10 02:14:26: (server.c.1352) can't have more connections than fds\/2:  1024 1024\r\nHint: Some lines were ellipsized, use -l to show in full.\r\n<\/pre>\n<p>Open the file called\u00a0<strong>\/etc\/lighttpd\/lighttpd.conf<\/strong>\u00a0with any editor.<\/p>\n<pre># vi \/etc\/lighttpd\/lighttpd.conf\r\n<\/pre>\n<p>Change the line that says\u00a0<strong>server.use-ipv6<\/strong>\u00a0from\u00a0<code>enable<\/code>\u00a0to\u00a0<code>disable<\/code>. It will fix error messages shown above.<\/p>\n<pre>##\r\n## Use IPv6?\r\n##\r\n<strong>server.use-ipv6 = \"disable\"<\/strong><\/pre>\n<p>Now try again to start\u00a0<strong>Lighttpd<\/strong>, it should work\u00a0<strong>100%<\/strong>\u00a0without any error messages.<\/p>\n<pre># systemctl restart lighttpd\r\n# systemctl status lighttpd<\/pre>\n<p><strong>5.<\/strong>\u00a0Now verify the version of\u00a0<strong>Lighttpd<\/strong>\u00a0installed on your system using the following command.<\/p>\n<pre># lighttpd -v\r\n\r\n<strong>lighttpd\/1.4.51 (ssl) - a light and fast webserver<\/strong>\r\n<\/pre>\n<p><strong>6.<\/strong>\u00a0Now you need to allow\u00a0<strong>HTTP<\/strong>\u00a0and\u00a0<strong>HTTPS<\/strong>\u00a0traffic on your firewall.<\/p>\n<pre># firewall-cmd --permanent --zone=public --add-service=http\r\n# firewall-cmd --permanent --zone=public --add-service=https\r\n# firewall-cmd --reload\r\n<\/pre>\n<p><strong>7.<\/strong>\u00a0Now open your browser and point to the following URL to see your\u00a0<strong>Lighttpd<\/strong>\u00a0web server working.<\/p>\n<pre>http:\/\/Your-Domain.com\r\nOR\r\nhttp:\/\/Your-IP-addr\r\n<\/pre>\n<div id=\"attachment_31238\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/08\/Check-Lighttpd-Page.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-31238\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/08\/Check-Lighttpd-Page.png\" sizes=\"auto, (max-width: 874px) 100vw, 874px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/08\/Check-Lighttpd-Page.png 874w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/08\/Check-Lighttpd-Page-768x523.png 768w\" alt=\"Check Lighttpd Page\" width=\"874\" height=\"595\" aria-describedby=\"caption-attachment-31238\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-31238\" class=\"wp-caption-text\">Check Lighttpd Page<\/p>\n<\/div>\n<p>The default document root directory for Lighttpd is\u00a0<strong>\/var\/www\/lighttpd\/<\/strong>\u00a0and the main configuration file is located under\u00a0<strong>\/etc\/lighttpd\/lighttpd.conf<\/strong>.<\/p>\n<h3>Step 2: Installing MariaDB as MySQL in CentOS 7<\/h3>\n<p><strong>8.<\/strong>\u00a0Next, install\u00a0<strong>MySQL<\/strong>\u00a0support for\u00a0<strong>Lighttpd<\/strong>\u00a0using following commands.<\/p>\n<pre># yum -y install mariadb mariadb-server\r\n<\/pre>\n<p><strong>9.<\/strong>\u00a0Once the installation is complete, start, enable and verify the status of MariaDB using following commands.<\/p>\n<pre># systemctl start mariadb.service\r\n# systemctl enable mariadb.service\r\n# systemctl status mariadb.service\r\n<\/pre>\n<p><strong>10.<\/strong>\u00a0Finally, you will need to secure your MariaDB installation by issuing the following command.<\/p>\n<pre># mysql_secure_installation\r\n<\/pre>\n<p>You will be prompted a few different questions regarding your MariaDB installation and how you would like to secure it. You can change the database root user password, disable the test database, disable anonymous users, and disable root login remotely.<\/p>\n<h5>Sample Output<\/h5>\n<pre>NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB\r\n      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!\r\n\r\nIn order to log into MariaDB to secure it, we'll need the current\r\npassword for the root user.  If you've just installed MariaDB, and\r\nyou haven't set the root password yet, the password will be blank,\r\nso you should just press enter here.\r\n\r\nEnter current password for root (enter for none): <code>Enter<\/code> OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. Set root password? [Y\/n] <code>y<\/code> New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y\/n] <code>y<\/code> ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y\/n] <code>y<\/code> ... Success! By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y\/n] <code>y<\/code> - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y\/n] <code>y<\/code> ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!<\/pre>\n<p><strong>11.<\/strong>\u00a0Try connecting to MySQL server and review the existing databases on your database server with following commands on the terminal.<\/p>\n<pre># mysql -u root -p<\/pre>\n<h5>Sample Output<\/h5>\n<pre>Enter password: \r\nWelcome to the MariaDB monitor.  Commands end with ; or \\g.\r\nYour MariaDB connection id is 10\r\nServer version: 5.5.60-MariaDB MariaDB Server\r\n\r\nCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.\r\n\r\nType 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.\r\n\r\nMariaDB [(none)]&gt; <strong>show databases;<\/strong>\r\n+--------------------+\r\n| Database           |\r\n+--------------------+\r\n| information_schema |\r\n| mysql              |\r\n| performance_schema |\r\n+--------------------+\r\n3 rows in set (0.00 sec)\r\n\r\nMariaDB [(none)]&gt;\r\n<\/pre>\n<h3>Step 3: Installing PHP and PHP-FPM with FastCGI on CentOS 7<\/h3>\n<p><strong>12.<\/strong>\u00a0To enable\u00a0<strong>PHP-FPM<\/strong>\u00a0with\u00a0<strong>FastCGI<\/strong>\u00a0support, first you need to install\u00a0<strong>PHP<\/strong>\u00a0along with necessary extensions using following command.<\/p>\n<pre># yum -y install php php-mysqlnd php-pdo php-gd php-mbstring<\/pre>\n<p><strong>13.<\/strong>\u00a0Once\u00a0<strong>PHP<\/strong>\u00a0installed, now enable\u00a0<strong>PHP-FPM<\/strong>\u00a0and\u00a0<strong>FastCGI<\/strong>\u00a0support for\u00a0<strong>Lighttpd<\/strong>, to do this you need to install these packages too.<\/p>\n<pre># yum -y install php-fpm lighttpd-fastcgi\r\n<\/pre>\n<p><strong>14.<\/strong>\u00a0Now open a file called\u00a0<strong>\/etc\/php-fpm.d\/www.conf<\/strong>.<\/p>\n<pre># vi \/etc\/php-fpm.d\/www.conf<\/pre>\n<p>Set the user and group to\u00a0<strong>lighttpd<\/strong>.<\/p>\n<pre>; Unix user\/group of processes\r\n; Note: The user is mandatory. If the group is not set, the default user's group\r\n;       will be used.\r\n; RPM: apache Choosed to be able to access some dir as httpd\r\n<strong>user = lighttpd<\/strong>\r\n; RPM: Keep a group allowed to write in log dir.\r\n<strong>group = lighttpd<\/strong><\/pre>\n<p><strong>15.<\/strong>\u00a0Now start\u00a0<strong>PHP-FPM<\/strong>\u00a0service and make sure to enable it to automatically start at boot time using the following commands.<\/p>\n<pre># systemctl start php-fpm.service\r\n# systemctl enable php-fpm.service\r\n<\/pre>\n<h3>Step 4: Enabling PHP and PHP-FPM with FastCGI in Lighttpd<\/h3>\n<p><strong>16.<\/strong>\u00a0Here, we need to modify three files\u00a0<strong>\/etc\/php.ini<\/strong>,\u00a0<strong>\/etc\/lighttpd\/modules.conf<\/strong>\u00a0and\u00a0<strong>\/etc\/lighttpd\/conf.d\/fastcgi.conf<\/strong>\u00a0to enable\u00a0<strong>PHP<\/strong>\u00a0support for\u00a0<strong>Lighttpd<\/strong>.<\/p>\n<p>Open first file\u00a0<strong>\/etc\/php.ini<\/strong>.<\/p>\n<pre># vi \/etc\/php.ini<\/pre>\n<p>Un-comment the following line that says\u00a0<strong>line cgi.fix_pathinfo=1<\/strong>.<\/p>\n<pre>; cgi.fix_pathinfo provides *real* PATH_INFO\/PATH_TRANSLATED support for CGI.  PHP's\r\n; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok\r\n; what PATH_INFO is.  For more information on PATH_INFO, see the cgi specs.  Setting\r\n; this to 1 will cause PHP CGI to fix its paths to conform to the spec.  A setting\r\n; of zero causes PHP to behave as before.  Default is 1.  You should fix your scripts\r\n; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.\r\n; http:\/\/php.net\/cgi.fix-pathinfo\r\n<strong>cgi.fix_pathinfo=1<\/strong><\/pre>\n<p>Then open second file called\u00a0<strong>\/etc\/lighttpd\/modules.conf<\/strong>.<\/p>\n<pre># vi \/etc\/lighttpd\/modules.conf<\/pre>\n<p>Un-comment the following line that says\u00a0<strong>include \u201cconf.d\/fastcgi.conf\u201d<\/strong>.<\/p>\n<pre>##\r\n## FastCGI (mod_fastcgi)\r\n##\r\n<strong>include \"conf.d\/fastcgi.conf\"<\/strong><\/pre>\n<p>Next, open third file called\u00a0<strong>\/etc\/lighttpd\/conf.d\/fastcgi.conf<\/strong>.<\/p>\n<pre># vi \/etc\/lighttpd\/conf.d\/fastcgi.conf<\/pre>\n<p>Now add the following container at the bottom of the file and save it.<\/p>\n<pre>fastcgi.server += ( \".php\" =&gt;\r\n        ((\r\n                \"host\" =&gt; \"127.0.0.1\",\r\n                \"port\" =&gt; \"9000\",\r\n                \"broken-scriptfilename\" =&gt; \"enable\"\r\n        ))\r\n)<\/pre>\n<p>Restart the\u00a0<strong>Lighttpd<\/strong>\u00a0service to reflect changes and enable\u00a0<strong>PHP<\/strong>\u00a0support.<\/p>\n<pre># systemctl restart lighttpd\r\n<\/pre>\n<h4>Step 5: Testing PHP and PHP-FPM with FastCGI Support in Lighttpd<\/h4>\n<p><strong>17.<\/strong>\u00a0As We said above that the default document root for\u00a0<strong>Lighttpd<\/strong>\u00a0is\u00a0<strong>\/var\/www\/lighttpd\/<\/strong>. So, here we will create a\u00a0<strong>phpinfo.php<\/strong>\u00a0file into this directory.<\/p>\n<pre># vi \/var\/www\/lighttpd\/info.php<\/pre>\n<p>Add the following lines to it. This small piece of code will display information about\u00a0<strong>PHP<\/strong>\u00a0installation with their versions.<\/p>\n<pre>&lt;?php\r\nphpinfo();\r\n?&gt;\r\n<\/pre>\n<p><strong>18.<\/strong>\u00a0Open your browser and navigate to the following links.<\/p>\n<pre>http:\/\/Your-Domain.com\r\nOR\r\nhttp:\/\/Your-IP-addr\r\n<\/pre>\n<div id=\"attachment_31248\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/08\/Check-PHP-Support-in-CentOS-7.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-31248\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/08\/Check-PHP-Support-in-CentOS-7.png\" sizes=\"auto, (max-width: 867px) 100vw, 867px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/08\/Check-PHP-Support-in-CentOS-7.png 867w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/08\/Check-PHP-Support-in-CentOS-7-768x706.png 768w\" alt=\"Check PHP Support in CentOS 7\" width=\"867\" height=\"797\" aria-describedby=\"caption-attachment-31248\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-31248\" class=\"wp-caption-text\">Check PHP Support in CentOS 7<\/p>\n<\/div>\n<p>You will see working information of\u00a0<strong>PHP<\/strong>,\u00a0<strong>PHP-FPM<\/strong>\u00a0and\u00a0<strong>MySQL<\/strong>\u00a0with lots of other modules that are already enabled.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/install-lighttpd-with-php-fpm-mariadb-on-centos-7\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Lighttpd\u00a0is an open source, secure, fast, flexible and more optimized web server designed for speed-critical environments with less memory utilization as compared to other web servers. It can handle up-to\u00a010,000\u00a0connections parallel in one server with effective cpu-load management and comes with advanced feature set such as FastCGI, SCGI, Auth, Output-Compression, URL-Rewriting and many more. Lighttpd\u00a0is &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/29\/how-to-install-lighttpd-with-php-php-fpm-and-mariadb-on-centos-7\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Install Lighttpd with PHP, PHP-FPM and MariaDB on CentOS 7&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-12940","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12940","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=12940"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12940\/revisions"}],"predecessor-version":[{"id":12942,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12940\/revisions\/12942"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=12940"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=12940"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=12940"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}