在CentOS 7上用FastCGI安装PHP和PHP-fpm

安装PHP和必要的扩展插件

# yum -y install php php-mysqlnd php-pdo php-gd php-mbstring

安装PHP-FPM和FastCGI

# yum -y install php-fpm lighttpd-fastcgi

修改配置文件

lighttpd的配置文件为:/etc/php-fpm.d/www.conf

将user和group改成lighttpd

; RPM: apache Choosed to be able to access some dir as httpd
user = lighttpd
; RPM: Keep a group allowed to write in log dir.
group = lighttpd

启动PHP-FPM服务

# systemctl start php-fpm.service
# systemctl enable php-fpm.service
如何在CentOS 7上安装Lighttpd,PHP, PHP-fpm和MariaDB

Lighttpd是一个开放源码的、安全的、快速的、灵活的和更优化的web服务器,它是为速度要求很高的环境设计的,与其他web服务器相比,它的内存利用率更低。

它可以在一台服务器上并行处理多达10,000个连接,具有有效的cpu负载管理,并具有FastCGI、SCGI、Auth、输出压缩、url重写等高级特性。

测试

  1. 创建一个测试文件 /var/www/lighttpd/info.php
<?php
phpinfo();
?>
  1. 使用浏览器打开页面 http://服务器ip地址/info.php
    可以看到php的有关信息。

安装lighttpd

  1. 使用yum安装lighttpd
# yum -y update
# yum -y install epel-release
# yum -y update
# yum install lighttpd
  1. 启动lighttpd服务,并设置开机自启动
# systemctl start lighttpd
# systemctl enable lighttpd
# systemctl status lighttpd
  1. 如果提示下面的内容,需要禁用ipv6
Dec 10 02:14:26 seg.com lighttpd[1463]: 2018-12-10 02:14:26: (network.c.167) warning: please use server.use-ipv6 only for hostnames, not without server.bind / empty address...ONLY changes
Dec 10 02:14:26 seg.com lighttpd[1463]: 2018-12-10 02:14:26: (server.c.1352) can't have more connections than fds/2:  1024 1024
Hint: Some lines were ellipsized, use -l to show in full.
  1. 修改配置文件 /etc/lighttpd/lighttpd.conf, 将ipv6禁用
##
## Use IPv6?
##
server.use-ipv6 = "disable"
  1. 重启lighttpd服务
# systemctl restart lighttpd
# systemctl status lighttpd
  1. 查看lighttpd 版本
# lighttpd -v

lighttpd/1.4.51 (ssl) - a light and fast webserver
  1. 配置防火墙,开放80和443端口
# firewall-cmd --permanent --zone=public --add-service=http
# firewall-cmd --permanent --zone=public --add-service=https
# firewall-cmd --reload
  1. 使用浏览器打开 http://服务器ip,看web服务是否正常。

在CentOS 7中安装MariaDB当作MySQL

MariaDB是基于MySQL的一个开源版本

安装 mariadb服务器

# yum -y install mariadb mariadb-server

启动mariadb并设置开机自启动

# systemctl start mariadb.service
# systemctl enable mariadb.service
# systemctl status mariadb.service

配置MariaDB

首次安装需要运行mysql_secure_installation,做一些安全设置

# mysql_secure_installation

登录MariaDB

# mysql -u root -p
Enter password: 

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

MariaDB [(none)]>

启用对Lighttpd的PHP-FPM和FastCGI支持

修改文件:

/etc/php.ini,
/etc/lighttpd/modules.conf
/etc/lighttpd/conf.d/fastcgi.conf

/etc/php.ini

将这行cgi.fix_pathinfo=1取消注释

cgi.fix_pathinfo=1

/etc/lighttpd/modules.conf

下面这行取消注释

include "conf.d/fastcgi.conf"

/etc/lighttpd/conf.d/fastcgi.conf

在文件末尾填写下面内容

fastcgi.server += ( ".php" =>
        ((
                "host" => "127.0.0.1",
                "port" => "9000",
                "broken-scriptfilename" => "enable"
        ))
)

重新启动Lighttpd服务,使配置生效

# systemctl restart lighttpd
日期:2019-04-29 03:17:13 来源:oir作者:oir