LAMP之fcgi技术

LAMP之fcgi技术

搭建基础服务wordpress

服务器规划

  • 主机A: apache+php+wordpress(192.168.1.223)
  • 主机B:mysql(192.168.1.222)
步骤1
 # 主机A配置

[root@vm1 html]# yum install httpd php php-mysql -y
[root@vm1 html]# systemctl start httpd
[root@vm1 html]# httpd -M | grep php
 php5_module (shared)
[root@vm1 html]# tar zxvf wordpress-5.0.4-zh_CN.tar.gz  -C /var/www/html/
[root@vm1 html]# setfacl -Rm u:apache:rwx /var/www/html/wordpress/  
##让apache用户具有wordpress/目录的写权限,因为在网页配置的时候需要通过apache用户创建一个 wp-config.php文件,wp-config.php内有后台需要连接的数据库等信息

步骤2
 # 主机B配置
[root@localhost ~]# yum install mariadb-server -y
[root@localhost ~]# systemctl restart mariadb
MariaDB [(none)]> create database wpdb;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> grant all on wpdb.* to wpuser@'192.168.1.%' identified by  'centos';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges
步骤3

通过访问http://192.168.1.223/wordpress/配置后台连接的数据库信息,通过apache用户自动生成wp-config.php

fcgi技术–提升php网站访问速率

httpd+php的实现方式

  • module:php模块
  • fcgi:php-fpm------httpd(nginx)将.php请求转发给后台php-fpm服务,httpd等于做了反向代理

php-fpm
centos6:php-5.32之前,默认不支持fpm机制,需要自行打补丁编译安装
httpd-2.2:默认不支持fcgi协议,需要自行编译此模块
centos7
httpd-2.4:rpm包默认编译支持fcgi模块
php-fpm包:将php运行于fpm模式

[root@vm1 php-fpm.d]# yum install php-fpm
[root@vm1 php-fpm.d]# rpm -ql php-fpm
/etc/logrotate.d/php-fpm
/etc/php-fpm.conf          ## php-fpm的主配置文件
/etc/php-fpm.d
/etc/php-fpm.d/www.conf     ##扩展配置文件
/etc/sysconfig/php-fpm
/run/php-fpm
/usr/lib/systemd/system/php-fpm.service   ##systemd 启动脚本
/usr/lib/tmpfiles.d/php-fpm.conf
/usr/sbin/php-fpm
/usr/share/doc/php-fpm-5.4.16
/usr/share/doc/php-fpm-5.4.16/fpm_LICENSE
/usr/share/doc/php-fpm-5.4.16/php-fpm.conf.default
/usr/share/fpm
/usr/share/fpm/status.html
/usr/share/man/man8/php-fpm.8.gz
/var/log/php-fpm
[root@vm1 php-fpm.d]# cat /etc/php-fpm.d/www.conf |  egrep -v '^;|^$'
[www]
listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1
user = apache
group = apache
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
slowlog = /var/log/php-fpm/www-slow.log
php_admin_value[error_log] = /var/log/php-fpm/www-error.log
php_admin_flag[log_errors] = on
php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php/session

[root@vm1 php-fpm.d]# systemctl restart php-fpm
[root@vm1 php-fpm.d]# systemctl status php-fpm
● php-fpm.service - The PHP FastCGI Process Manager
   Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; disabled; vendor preset: disabled)
   Active: active (running) since Mon 2021-05-03 21:41:15 CST; 4s ago
 Main PID: 89554 (php-fpm)
   Status: "Ready to handle connections"
    Tasks: 6
   CGroup: /system.slice/php-fpm.service
           ├─89554 php-fpm: master process (/etc/php-fpm.conf)
           ├─89556 php-fpm: pool www
           ├─89557 php-fpm: pool www
           ├─89558 php-fpm: pool www
           ├─89559 php-fpm: pool www
           └─89560 php-fpm: pool www

May 03 21:41:15 vm1 systemd[1]: Starting The PHP FastCGI Process Manager...
May 03 21:41:15 vm1 systemd[1]: Started The PHP FastCGI Process Manager.

[root@vm1 php-fpm.d]# vim /etc/httpd/conf.d/fcgi.conf
Directoryindex index.php
proxyrequests off
proxypassmatch  ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/html/$1  ##告诉httpd将.php结尾的请求以fcgi协议转发给后台9000端口的php-fpm服务
[root@vm1 php-fpm.d]# systemctl restart httpd

[root@vm1 php-fpm.d]# systemctl status php-fpm
● php-fpm.service - The PHP FastCGI Process Manager
   Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; disabled; vendor preset: disabled)
   Active: active (running) since Mon 2021-05-03 21:41:15 CST; 12min ago
 Main PID: 89554 (php-fpm)
   Status: "Processes active: 0, idle: 16, Requests: 201, slow: 0, Traffic: 0req/sec"
    Tasks: 17

你可能感兴趣的:(httpd,apache,php,wordpress,lamp)