Ubuntu 16.04上安装Lighttpd+PHP 7(PHP

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_password

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

浏览器输入主机地址,看看安装是否成功:

ubuntu_lighttpd_default_page

另外说明一下:

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. ; 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 # :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

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/618bde756a928c7f429136280ea8e1ff.html