共计 6211 个字符,预计需要花费 16 分钟才能阅读完成。
Lighttpd 是一款安全、快速、符合标准的 Web 服务器。本教程介绍了如何通过 PHP7(PHP-FPM)和 MySQL5.7 在 Ubuntu 16.04 服务器上安装 Lighttpd 服务。PHP-FPM(FastCGI 进程管理器)是一种替代 PHP 的 FastCGI 适用于各种规模的网站,尤其是繁忙的网站有用的一些额外的功能。
1、安装初步说明
在本教程中,使用的 IP 地址为 192.168.1.100,主机名 server1.example.com。这些设置可能与你的服务器不同,所以你不得不在适当情况下更换他们。
运行的所有步骤在本教程中使用的 root 权限,所以一定要确保你以 root 身份登录:
sudo -s
2、安装 MySQL 5.7
安装命令:
apt-get -y install mysql-server mysql-client
安装过程中要求设置 root 账户密码,如图:
MySQL 安装更改设置命令:
mysql_secure_installation
如下进行设置:
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. Would 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 for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : <– y
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? (Press y|Y for Yes, any other key for No) : <– y
Success.
By default, MySQL 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? (Press y|Y for Yes, any other key for No) : <– y
– 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? (Press y|Y for Yes, any other key for No) : <– y
Success.
All done!
3、安装 Lighttpd:
安装命令:
apt-get -y install lighttpd
浏览器输入主机地址,看看安装是否成功:
另外说明一下:
Lighttpd 默认根目录:/var/www/html
配置文件:/etc/lighttpd/lighttpd.conf、
其他配置:/etc/lighttpd/conf-available
/etc/lighttpd/conf-enabled
/etc/lighttpd/conf-available
4、安装 PHP 7.0
安装命令:
apt-get -y install php7.0-fpm php7.0
5、配置 Lighttpd 与 PHP 7.0
打开 php.ini:
nano /etc/php/7.0/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-pathinfo
cgi.fix_pathinfo=1
[...]
httpd 配置文件,我们需要将 /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
内容修改:
# /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 php7.0-cgi package)
fastcgi.server += ( ".php" =>
((
"socket" => "/var/run/php/php7.0-fpm.sock",
"broken-scriptfilename" => "enable"
))
)
要启用 FastCGI 配置,运行以下命令:
lighttpd-enable-mod fastcgi
lighttpd-enable-mod fastcgi-php
这将创建符号链接
/etc/lighttpd/conf-enabled/10-fastcgi.conf 指向 /etc/lighttpd/conf-available/10-fastcgi.conf
/etc/lighttpd/conf-enabled/15-fastcgi-php.conf 指向 /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 Apr 27 11:26 10-fastcgi.conf -> ../conf-available/10-fastcgi.conf
lrwxrwxrwx 1 root root 37 Apr 27 11:26 15-fastcgi-php.conf -> ../conf-available/15-fastcgi-php.conf
lrwxrwxrwx 1 root root 42 Apr 21 11:10 90-javascript-alias.conf -> ../conf-available/90-javascript-alias.conf
root@server1:/etc/lighttpd/conf-available#
重新加载 Lighttpd:
service lighttpd force-reload
注意:如果提示你的语言环境错误,那么你可以下面的命令删除错误:
apt-get -y install language-pack-en-base
dpkg-reconfigure locales
6、建立一个探针文件看看安装情况:
nano /var/www/html/info.php
内容:
<?php
phpinfo();
?>
好了,浏览器访问这个探针文件:http://192.168.1.100/info.php
7、PHP 获得 MySQL 支持
产看模块:
apt-cache search php7.0
安装模块:
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
重新加载 php7.0-fpm:
service php7.0-fpm reload
8、安装 phpmyadmin
命令:
apt-get -y install phpmyadmin
安装过程中询问设置:
Web server to reconfigure automatically: Configure database for phpmyadmin with dbconfig-common? MySQL application password for phpmyadmin:
如果出现错误:
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)
运行下面的命令:
/etc/init.d/lighttpd force-reload
apt-get -y install phpmyadmin
然后访问 phpMyAdmin 浏览器输入:http://192.168.1.100/phpmyadmin/
9、使 PHP-FPM 使用 TCP 连接(可选)
编辑:ano /etc/php/7.0/fpm/pool.d/www.conf
内容如下:
[...]
;listen = /var/run/php/php7.0-fpm.sock
listen = 127.0.0.1:9000
[...]
重新加载 PHP-FPM:
service php7.0-fpm reload
再配置一个文件:
nano /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 php7.0-cgi package)
fastcgi.server += ( ".php" =>
((
"host" => "127.0.0.1",
"port" => "9000",
"broken-scriptfilename" => "enable"
))
)
重新加载 Lighttpd:service lighttpd force-reload
Ubuntu 16.04 上怎样试用 Mir 和 Unity 8 http://www.linuxidc.com/Linux/2016-04/130702.htm
Ubuntu 16.04 LTS 正式发布下载 ,长达 5 年技术支持 http://www.linuxidc.com/Linux/2016-04/130508.htm
Ubuntu 16.04 U 盘安装图文教程 http://www.linuxidc.com/Linux/2016-04/130520.htm
Ubuntu 16.04 LTS 安装好需要设置的 15 件事 http://www.linuxidc.com/Linux/2016-04/130519.htm
Ubuntu 16.04 LTS 今日发布 Canonical 公布系统新特性 http://www.linuxidc.com/Linux/2016-04/130466.htm
将 Ubuntu 15.10 升级到 Ubuntu 16.04 http://www.linuxidc.com/Linux/2016-03/129158.htm
Ubuntu 16.04 安装 Lua 游戏引擎 Love http://www.linuxidc.com/Linux/2016-03/129108.htm
Ubuntu 16.04 需要你的帮助,让 GNOME Software 更美观 http://www.linuxidc.com/Linux/2016-03/129237.htm
更多 Ubuntu 相关信息见 Ubuntu 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=2
本文永久更新链接地址 :http://www.linuxidc.com/Linux/2016-05/131425.htm