搜尋
首頁資料庫mysql教程Installing Lighttpd With PHP5 (PHP-FPM) And MySQL Support On_MySQL

Installing Lighttpd With PHP5 (PHP-FPM) And MySQL Support On Ubuntu 14.04LTS

Version 1.0
Author: Falko Timme, updated by Srijan Kishore
Last edited 07/May/2014

Lighttpd is a secure, fast, standards-compliant web server designed for speed-critical environments. This tutorial shows how you can install Lighttpd on an Ubuntu 14.04 server with PHP5 support (through PHP-FPM) and MySQL support. PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features useful for sites of any size, especially busier sites. I use PHP-FPM in this tutorial instead of Lighttpd's spawn-fcgi.

I do not issue any guarantee that this will work for you!

1 Preliminary Note

In this tutorial I use the hostnameserver1.example.comwith the IP address192.168.0.100. These settings might differ for you, so you have to replace them where appropriate.

I'm running all the steps in this tutorial with root privileges, so make sure you're logged in as root:

sudo su

2 Installing MySQL 5

First we install MySQL 5 like this:

apt-get install mysql-server mysql-client

You will be asked to provide a password for the MySQL root user - this password is valid for the userroot@localhostas well asroot@server1.example.com, so we don't have to specify a MySQL root password manually later on:

New password for the MySQL "root" user:Repeat password for the MySQL "root" user:

3 Installing Lighttpd

Lighttpd is available as an Ubuntu package, therefore we can install it like this, as apache2 is installed by default in ubuntu14.04 so first we will uninstall apache2 & then further install lighttpd.

service apache2 stop
update-rc.d -f apache2 remove
apt-get remove apache2

apt-get install lighttpd

Now direct your browser tohttp://192.168.0.100/index.lighttpd.html, and you should see the Lighttpd placeholder page:

Installing Lighttpd With PHP5 (PHP-FPM) And MySQL Support On_MySQL

Lighttpd's default document root is/var/wwwon Ubuntu, and the configuration file is/etc/lighttpd/lighttpd.conf. Additional configurations are stored in files in the/etc/lighttpd/conf-availabledirectory - these configurations can be enabled with thelighttpd-enable-modcommand which creates a symlink from the/etc/lighttpd/conf-enableddirectory to the appropriate configuration file in/etc/lighttpd/conf-available. You can disable configurations with thelighttpd-disable-modcommand.

4 Installing PHP5

We can make PHP5 work in Lighttpd through PHP-FPM which we install like this:

apt-get install php5-fpm php5

PHP-FPM is a daemon process (with the init scriptphp5-fpm) that runs a FastCGI server on the socket/var/run/php5-fpm.sock.

5 Configuring Lighttpd And PHP5

To enable PHP5 in Lighttpd, we must modify/etc/php5/fpm/php.iniand uncomment the linecgi.fix_pathinfo=1:

vi /etc/php5/fpm/php.ini

[...]; 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.; http://php.net/cgi.fix-pathinfocgi.fix_pathinfo=1[...]

The Lighttpd configuration file for PHP/etc/lighttpd/conf-available/15-fastcgi-php.confis suitable for use with spawn-fcgi, however, we want to use PHP-FPM, therefore we create a backup of the file (named15-fastcgi-php.conf.bak) and modify15-fastcgi-php.confas follows:

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

# /usr/share/doc/lighttpd-doc/fastcgi.txt.gz# http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ConfigurationOptions#mod_fastcgi-fastcgi## Start an FastCGI server for php (needs the php5-cgi package)fastcgi.server += ( ".php" =>(("socket" => "/var/run/php5-fpm.sock","broken-scriptfilename" => "enable")))

To enable the fastcgi configuration, run the following commands:

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

This creates the symlinks/etc/lighttpd/conf-enabled/10-fastcgi.confwhich points to/etc/lighttpd/conf-available/10-fastcgi.confand/etc/lighttpd/conf-enabled/15-fastcgi-php.confwhich points to/etc/lighttpd/conf-available/15-fastcgi-php.conf:

ls -l /etc/lighttpd/conf-enabled

root@server1:/etc/lighttpd/conf-available# ls -l /etc/lighttpd/conf-enabled
total 0
lrwxrwxrwx 1 root root 33 May  7 05:33 10-fastcgi.conf -> ../conf-available/10-fastcgi.conf
lrwxrwxrwx 1 root root 37 May  7 05:33 15-fastcgi-php.conf -> ../conf-available/15-fastcgi-php.conf
root@server1:/etc/lighttpd/conf-available#

Then we reload Lighttpd:

service lighttpd force-reload

 Note: If you get locale errors then you can remove the error by using

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

6 Testing PHP5 / Getting Details About Your PHP5 Installation

The document root of the default web site is/var/www. We will now create a small PHP file (info.php) in that directory and call it in a browser. The file will display lots of useful details about our PHP installation, such as the installed PHP version.

vi /var/www/info.php

<?phpphpinfo ();?>

Now we call that file in a browser (e.g.http://192.168.0.100/info.php):

Installing Lighttpd With PHP5 (PHP-FPM) And MySQL Support On_MySQL

As you see, PHP5 is working, and it's working through FPM/FastCGI, as shown in theServer APIline. If you scroll further down, you will see all modules that are already enabled in PHP5. MySQL is not listed there which means we don't have MySQL support in PHP5 yet.

7 Getting MySQL Support In PHP5

To get MySQL support in PHP, we can install thephp5-mysqlpackage. It's a good idea to install some other PHP5 modules as well as you might need them for your applications. You can search for available PHP5 modules like this:

apt-cache search php5

Pick the ones you need and install them like this:

apt-get install php5-mysql php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl

Xcache is a free and open PHP opcode cacher for caching and optimizing PHP intermediate code. It's similar to other PHP opcode cachers, such as eAccelerator and APC. It is strongly recommended to have one of these installed to speed up your PHP page.

Xcache can be installed as follows:

apt-get install php5-xcache

Now reload PHP-FPM:

service php5-fpm reload

Now reloadhttp://192.168.0.100/info.phpin your browser and scroll down to the modules section again. You should now find lots of new modules there, including the MySQL module:

Installing Lighttpd With PHP5 (PHP-FPM) And MySQL Support On_MySQL

8 phpMyAdmin

phpMyAdminis a web interface through which you can manage your MySQL databases. It's a good idea to install it:

apt-get install phpmyadmin

You will see the following questions:

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

Afterwards, you can access phpMyAdmin underhttp://192.168.0.100/phpmyadmin/:

Installing Lighttpd With PHP5 (PHP-FPM) And MySQL Support On_MySQL

9 Making PHP-FPM Use A TCP Connection

By default PHP-FPM is listening on the socket/var/run/php5-fpm.sock. It is also possible to make PHP-FPM use a TCP connection. To do this, open/etc/php5/fpm/pool.d/www.conf...

vi /etc/php5/fpm/pool.d/www.conf

... and make thelistenline look as follows:

[...];listen = /var/run/php5-fpm.socklisten = 127.0.0.1:9000[...]

This will make PHP-FPM listen on port9000on the IP127.0.0.1(localhost). Make sure you use a port that is not in use on your system.

Then reload PHP-FPM:

service php5-fpm reload

Next open Lighttpd's PHP configuration file/etc/lighttpd/conf-available/15-fastcgi-php.confand replace thesocketline withhostandportlines:

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

# /usr/share/doc/lighttpd-doc/fastcgi.txt.gz# http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ConfigurationOptions#mod_fastcgi-fastcgi## Start an FastCGI server for php (needs the php5-cgi package)fastcgi.server += ( ".php" =>(("host" => "127.0.0.1","port" => "9000","broken-scriptfilename" => "enable")))

Finally reload Lighttpd:

service lighttpd force-reload

  • Lighttpd:http://www.lighttpd.net/
  • PHP:http://www.php.net/
  • PHP-FPM:http://php-fpm.org/
  • MySQL:http://www.mysql.com/
  • Ubuntu:http://www.ubuntu.com/
  • phpMyAdmin:http://www.phpmyadmin.net/
陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
您什麼時候應該使用複合索引與多個單列索引?您什麼時候應該使用複合索引與多個單列索引?Apr 11, 2025 am 12:06 AM

在數據庫優化中,應根據查詢需求選擇索引策略:1.當查詢涉及多個列且條件順序固定時,使用複合索引;2.當查詢涉及多個列但條件順序不固定時,使用多個單列索引。複合索引適用於優化多列查詢,單列索引則適合單列查詢。

如何識別和優化MySQL中的慢速查詢? (慢查詢日誌,performance_schema)如何識別和優化MySQL中的慢速查詢? (慢查詢日誌,performance_schema)Apr 10, 2025 am 09:36 AM

要優化MySQL慢查詢,需使用slowquerylog和performance_schema:1.啟用slowquerylog並設置閾值,記錄慢查詢;2.利用performance_schema分析查詢執行細節,找出性能瓶頸並優化。

MySQL和SQL:開發人員的基本技能MySQL和SQL:開發人員的基本技能Apr 10, 2025 am 09:30 AM

MySQL和SQL是開發者必備技能。 1.MySQL是開源的關係型數據庫管理系統,SQL是用於管理和操作數據庫的標準語言。 2.MySQL通過高效的數據存儲和檢索功能支持多種存儲引擎,SQL通過簡單語句完成複雜數據操作。 3.使用示例包括基本查詢和高級查詢,如按條件過濾和排序。 4.常見錯誤包括語法錯誤和性能問題,可通過檢查SQL語句和使用EXPLAIN命令優化。 5.性能優化技巧包括使用索引、避免全表掃描、優化JOIN操作和提升代碼可讀性。

描述MySQL異步主奴隸複製過程。描述MySQL異步主奴隸複製過程。Apr 10, 2025 am 09:30 AM

MySQL異步主從復制通過binlog實現數據同步,提升讀性能和高可用性。 1)主服務器記錄變更到binlog;2)從服務器通過I/O線程讀取binlog;3)從服務器的SQL線程應用binlog同步數據。

mysql:簡單的概念,用於輕鬆學習mysql:簡單的概念,用於輕鬆學習Apr 10, 2025 am 09:29 AM

MySQL是一個開源的關係型數據庫管理系統。 1)創建數據庫和表:使用CREATEDATABASE和CREATETABLE命令。 2)基本操作:INSERT、UPDATE、DELETE和SELECT。 3)高級操作:JOIN、子查詢和事務處理。 4)調試技巧:檢查語法、數據類型和權限。 5)優化建議:使用索引、避免SELECT*和使用事務。

MySQL:數據庫的用戶友好介紹MySQL:數據庫的用戶友好介紹Apr 10, 2025 am 09:27 AM

MySQL的安裝和基本操作包括:1.下載並安裝MySQL,設置根用戶密碼;2.使用SQL命令創建數據庫和表,如CREATEDATABASE和CREATETABLE;3.執行CRUD操作,使用INSERT,SELECT,UPDATE,DELETE命令;4.創建索引和存儲過程以優化性能和實現複雜邏輯。通過這些步驟,你可以從零開始構建和管理MySQL數據庫。

InnoDB緩衝池如何工作,為什麼對性能至關重要?InnoDB緩衝池如何工作,為什麼對性能至關重要?Apr 09, 2025 am 12:12 AM

InnoDBBufferPool通過將數據和索引頁加載到內存中來提升MySQL數據庫的性能。 1)數據頁加載到BufferPool中,減少磁盤I/O。 2)臟頁被標記並定期刷新到磁盤。 3)LRU算法管理數據頁淘汰。 4)預讀機制提前加載可能需要的數據頁。

MySQL:初學者的數據管理易用性MySQL:初學者的數據管理易用性Apr 09, 2025 am 12:07 AM

MySQL適合初學者使用,因為它安裝簡單、功能強大且易於管理數據。 1.安裝和配置簡單,適用於多種操作系統。 2.支持基本操作如創建數據庫和表、插入、查詢、更新和刪除數據。 3.提供高級功能如JOIN操作和子查詢。 4.可以通過索引、查詢優化和分錶分區來提升性能。 5.支持備份、恢復和安全措施,確保數據的安全和一致性。

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您聽不到任何人,如何修復音頻
3 週前By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解鎖Myrise中的所有內容
3 週前By尊渡假赌尊渡假赌尊渡假赌

熱工具

WebStorm Mac版

WebStorm Mac版

好用的JavaScript開發工具

DVWA

DVWA

Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

MantisBT

MantisBT

Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。