Installing Lighttpd with PHP 7 and MySQL on Ubuntu 16.04

By Sajid Qureshi, Alibaba Cloud Tech Share Author. Tech Share is Alibaba Cloud’s incentive program to encourage the sharing of technical knowledge and best practices within the cloud community.

Lighttpd is an open source web server, which is designed and optimized for high-performance environments. It is a fast, secure, and flexible web server, making it a perfect alternative for Apache and Nginx. Lighttpd can be used to serve high traffic sites even on a small virtual private servers.

In this guide, we will show you how to install Lighttpd on your Alibaba Cloud Elastic Compute Service (ECS) Ubuntu 16.04 server with PHP and MySQL.

Prerequisites

1. You must have Alibaba Cloud Elastic Compute Service (ECS) activated and verified your valid payment method. If you are a new user, you can get a free account in your Alibaba Cloud account. If you don’t know about how to set up your ECS instance, you can refer to this tutorial or quick-start guide. Your ECS instance must have at least 1GB RAM and 1 Core processor.
2. A domain name registered from Alibaba Cloud. If you have already registered a domain from Alibaba Cloud or any other host, you can update its domain nameserver records.
3. Root user

Update the System

We recommend you to install any new packages on a freshly updated server. First of all, upgrade all the available packages using the following command.

Installing MySQL

Once the system is updated, you can proceed further to install MySQL and to do so execute the following command.

You’ll be asked to enter MySQL password for root user so, type the password and confirm it by repeating password then hit the enter button.

MySQL is successfully installed so, let’s harden the security of it using the following command.

You’ll be asked to enter the root password then hit the enter button. Then you’ll be asked some general questions about the database and its user, finish this by typing Y for yes and any other key for no.

Installing Lighttpd and PHP

MySQL is installed and fully secured now. Next, you will need to install Lighttpd and PHP, here we will install PHP 7.0. Lighttpd is available as an Ubuntu package so we can directly install it using the following command.

You can verify this installation by visiting http://YourServerIP through a web browser, and you should see the Lighttpd placeholder page like this:

Image for post
Image for post

Next, we will install PHP-FPM using the following command.

Configuring Lighttpd

We have installed Lighttpd with all the required packages and now we will have to configure the Lighttpd to work with PHP. First of all, you will need to modify ‘’php.ini’’ file using any text editor.

Find and uncomment the line by removing semicolon before the line. Save the file and exit from the text editor.

Next, you’ll need to create a backup of the PHP configuration file using the following commands.

Now, modify the original PHP configuration file as follows:

Now, enable the fastcgi configuration using the following commands.

Finally, reload the Lighttpd using the following command.

If in case you get any local errors then you can use the following commands to remove the errors.

Next, we will test this PHP installation through a web browser. Change your current directory to the document root using the following command.

Now, you will have to create a small PHP test file called “php.info” using the following command.

Add the following content to the file and then save and exit from the editor.

Now, you can test this by visiting http://YourServerIP/info.php through any web browser.

You should see lots of useful details about our PHP installation, such as the installed PHP version.

Image for post
Image for post

Now you can see that PHP is working correctly. If you scroll further down, you will see all modules that are already enabled in PHP. MySQL is not listed there which means we don’t have MySQL support in PHP yet. We can install the php7.0-mysql package to get MySQL support in PHP. Execute the following command and it’ll install the required package with some additional PHP modules which can be useful for your applications.

You can add some compatibility features for software that supports the APC cache by installing APCu is an extension for the PHP. Execute the following command to do so.

Finally, reload the PHP-FPM to apply changes using the following command.

Now, reload the PHP test webpage from the web browser or visit http://YourServerIP/info.php again then scroll down. You should now find lots of new modules there, including the mysqli and mysqlnd module:

Image for post
Image for post

Installing phpMyAdmin

phpMyAdmin is a web interface that helps you to manage your MySQL database. You can install phpMyAdmin using the following command.

You’ll be asked the following questions as below:

If in case you get any errors while installing it then you can use the following commands to resolve the errors.

Finally, you can access phpMyAdmin through any web browser by visiting http://YourServerIP/phpmyadmin/ Replace YourServerIP with your actual one.

Reference:https://www.alibabacloud.com/blog/installing-lighttpd-with-php-7-and-mysql-on-ubuntu-16-04_594629?spm=a2c41.12714959.0.0

Follow me to keep abreast with the latest technology news, industry insights, and developer trends.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store