Install Lighttpd + PHP 7 (PHP-FPM) + MySQL 16.04 on Ubuntu 5.7

Source: Internet
Author: User
Tags redmine

Install Lighttpd + PHP 7 (PHP-FPM) + MySQL 16.04 on Ubuntu 5.7

Lighttpd is a secure, fast, and compliant Web server. This tutorial describes how to install the Lighttpd service on a Ubuntu 16.04 server through PHP7 (PHP-FPM) and MySQL5.7. PHP-FPM (FastCGI Process Manager) is an alternative to PHP's FastCGI for some additional functionality useful for websites of all sizes, especially busy websites.

1. Installation instructions

In this tutorial, the IP address is and the host name is These settings may be different from your server, so you have to change them as appropriate.

All running steps are the root permission used in this tutorial, so make sure you log on as root:


2. Install MySQL 5.7

Installation command:

Apt-get-y install mysql-server mysql-client

During installation, you must set the root account password,

MySQL installation and modification settings command:


Set as follows:

Root @ server1 :~ # Mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root: <-Enter the MySQL root password

Validate password plugin can be used to test passwords
And improve security. It checks the strength of password
And allows the users to set only those passwords which are
Secure enough. wocould you like to setup validate password plugin?

Press y | Y for Yes, any other key for No: <-Press y if you want this function or press Enter otherwise.
Using existing password for root.
Change the password for root? (Press y | Y for Yes, any other key for No): <-Press enter

... Skipping.
By default, a MySQL installation has an anonymous user,
Allowing anyone to log into MySQL without having to have
A user account created for them. This is intended only
Testing, and to make the installation go a bit smoother.
You shoshould remove them before moving into a production

Remove anonymous users? (Press y | Y for Yes, any other key for No): <-y

Normally, root shoshould only be allowed to connect from
'Localhost'. This ensures that someone cannot guess
The root password from the network.

Disallow root login remotely? (Press y | Y for Yes, any other key for No): <-y

By default, MySQL comes with a database named 'test' that
Anyone can access. This is also intended only for testing,
And shoshould be removed before moving into a production

Remove test database and access to it? (Press y | Y for Yes, any other key for No): <-y
-Dropping test database...

-Removing privileges on test database...

Reloading the privilege tables will ensure that all changes
Made so far will take effect immediately.

Reload privilege tables now? (Press y | Y for Yes, any other key for No): <-y

All done!

3. Install Lighttpd:

Installation command:

apt-get -y install lighttpd

Enter the host address in the browser to check whether the installation is successful:

Note the following:

Default Lighttpd root directory:/var/www/html
Configuration Files:/etc/lighttpd. conf,
Other configurations:/etc/lighttpd/conf-available

4. install PHP 7.0
Installation command:

apt-get -y install php7.0-fpm php7.0

5. Configure Lighttpd with PHP 7.0

Open php. ini:

nano /etc/php/7.0/fpm/php.ini

File Configuration:

[...]; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI.  PHP's; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok; what PATH_INFO is.  For more information on PATH_INFO, see the cgi specs.  Setting; this to 1 will cause PHP CGI to fix its paths to conform to the spec.  A setting; of zero causes PHP to behave as before.  Default is 1.  You should fix your scripts; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.;[...]

In the httpd configuration file, we need to back up/etc/lighttpd/conf-available/15-fastcgi-php.conf:

cd /etc/lighttpd/conf-available/
cp 15-fastcgi-php.conf 15-fastcgi-php.conf.bak
nano 15-fastcgi-php.conf

Content modification:

# /usr/share/doc/lighttpd-doc/fastcgi.txt.gz# Start an FastCGI server for php (needs the php7.0-cgi package)fastcgi.server += ( ".php" =>        ((                "socket" => "/var/run/php/php7.0-fpm.sock",                "broken-scriptfilename" => "enable"        )))

To enable FastCGI configuration, run the following command:

lighttpd-enable-mod fastcgi
lighttpd-enable-mod fastcgi-php

This creates a symbolic link.
/Etc/lighttpd/conf-enabled/10-fastcgi.conf points to/etc/lighttpd/conf-available/10-fastcgi.conf
/Etc/lighttpd/conf-enabled/15-fastcgi-php.conf points to/etc/lighttpd/conf-available/15-fastcgi-php.conf

ls -l /etc/lighttpd/conf-enabled

Execution status:

root@server1:/etc/lighttpd/conf-available# ls -l /etc/lighttpd/conf-enabledtotal 0lrwxrwxrwx 1 root root 33 Apr 27 11:26 10-fastcgi.conf -> ../conf-available/10-fastcgi.conflrwxrwxrwx 1 root root 37 Apr 27 11:26 15-fastcgi-php.conf -> ../conf-available/15-fastcgi-php.conflrwxrwxrwx 1 root root 42 Apr 21 11:10 90-javascript-alias.conf -> ../conf-available/90-javascript-alias.confroot@server1:/etc/lighttpd/conf-available#

Reload Lighttpd:

service lighttpd force-reload

Note: If you are prompted that your language environment is incorrect, you can run the following command to delete the error:

apt-get -y install language-pack-en-base
dpkg-reconfigure locales

6. Create a probe file to check the installation:

nano /var/www/html/info.php



Okay, visit the probe file in the browser: http: // php.

7. PHP supports MySQL

Production module:

apt-cache search php7.0

Installation module:

apt-get -y install php7.0-mysql php7.0-curl php7.0-gd php7.0-intl php-pear php-imagick php7.0-imap php7.0-mcrypt php-memcache php7.0-pspell php7.0-recode php7.0-sqlite3 php7.0-tidy php7.0-xmlrpc php7.0-xsl php7.0-mbstring php-gettext

apt-get -y install php-apcu

Reload php7.0-fpm:

service php7.0-fpm reload

8. Install phpmyadmin


apt-get -y install phpmyadmin

During installation, ask for settings:

Web server to reconfigure automatically: Configure database for phpmyadmin with dbconfig-common? MySQL application password for phpmyadmin:

If an error occurs:
Run/etc/init. d/lighttpd force-reload to enable changes
Dpkg: error processing package phpmyadmin (-configure ):
Subprocess installed post-installation script returned error exit status 2
E: Sub-process/usr/bin/dpkg returned an error code (1)
Run the following command:

/etc/init.d/lighttpd force-reload
apt-get -y install phpmyadmin

Access the phpMyAdmin browser and enter: http: //

9. Make the PHP-FPM use a TCP connection (optional)

ano /etc/php/7.0/fpm/pool.d/www.conf

The content is as follows:

[...];listen = /var/run/php/php7.0-fpm.socklisten =[...]

Reload the PHP-FPM:

service php7.0-fpm reload

Configure another file:

nano /etc/lighttpd/conf-available/15-fastcgi-php.conf

The configuration is as follows:

# /usr/share/doc/lighttpd-doc/fastcgi.txt.gz# Start an FastCGI server for php (needs the php7.0-cgi package)fastcgi.server += ( ".php" =>        ((                "host" => "",                "port" => "9000",                "broken-scriptfilename" => "enable"        )))

Reload Lighttpd:
service lighttpd force-reload

How to try Mir and Unity 8 on Ubuntu 16.04

Ubuntu 16.04 LTS was officially released and downloaded for 5 years of technical support

Ubuntu 16.04 USB flash drive installation graphic tutorial

15 things to be configured after installing Ubuntu 16.04 LTS

Ubuntu 16.04 LTS released Canonical today to announce new system features

Upgrade Ubuntu 15.10 To Ubuntu 16.04

Install Lua game engine in Ubuntu 16.04

Ubuntu 16.04 requires your help to make GNOME Software more beautiful

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.