静态资源:原始形式与响应内容一致,在客户端浏览器执行
动态资源(程序执行生成的结果,返回给用户):原始形式通常为程序文件,需要在服务器端执行之后,将执行结果返回给客户端
注意:静态和动态的区别,不在于网页是否能动态变化,而在于服务端的页面文件和客户端得到页面文件是否一致
#客户端主机现在的时间:
<script type="text/javascript">
document.write(new Date());
</script>
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Yzx8RSJm-1577107769905)(%E6%88%AA%E5%9B%BE/2019%E5%B9%B411%E6%9C%8821%E6%97%A5/image-20191218170146266.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-M2gFF8F0-1577107769907)(%E6%88%AA%E5%9B%BE/2019%E5%B9%B411%E6%9C%8821%E6%97%A5/image-20191218170323433.png)]
fastcgi的方式是,web服务器收到一个请求时,不会重新fork一个进程(因为这个进程在web服务器启动时就开启了,而且不会退出),web服务器直接把内容传递给这个进程(进程间通信,但fastcgi使用了别的方式,tcp方式通信),这个进程收到请求后进行处理,把结果返回给web服务器,最后自己接着等待下一个请求的到来,而不是退出
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-fHVaQE5s-1577107769908)(%E6%88%AA%E5%9B%BE/2019%E5%B9%B411%E6%9C%8821%E6%97%A5/image-20191218170642641.png)]
PHP官网:http://www.php.net/
PHP是通用服务器端脚本编程语言,主要用于web开发实现动态web页面,也是最早实现将脚本嵌入HTML源码文档中的服务器端脚本语言之一。同时,php还提供了一个命令行接口,因此,其也可以在大多数系统上作为一个独立的shell来使用
Rasmus Lerdorf于1994年开始开发PHP,最初是一组被Rasmus Lerdorf称作“Personal Home Page Tool” 的Perl脚本, 可以用于显示作者的简历并记录用户对其网站的访问。后来,Rasmus Lerdorf使用C语言将这些Perl脚本重写为CGI程序,还为其增加了运行Web forms的能力以及与数据库交互的特性,并将其重命名为“Personal Home Page/Forms Interpreter”或“PHP/FI”。此时,PHP/FI已经可以用于开发简单的动态web程序了,这即PHP1.0。1995年6月,Rasmus Lerdorf把它的PHP发布于comp.infosystems.www.authoring.cgi Usenet讨论组,从此PHP开始走进人们的视野。1997年,其2.0版本发布
1997年,两名以色列程序员Zeev Suraski和Andi Gutmans重写的PHP的分析器(parser)成为PHP发展到3.0的基础,而且从此将PHP重命名为PHP: Hypertext Preprocessor。此后,这两名程序员开始重写整个PHP核心,并于1999年发布了Zend Engine 1.0,这也意味着PHP 4.0的诞生。2004年7月,Zend Engine 2.0发布,由此也将PHP带入了PHP 5时代。PHP5包含了许多重要的新特性,如增强的面向对象编程的支持、支持PDO(PHP Data Objects)扩展机制以及一系列对PHP性能的改进
Zend Engine是开源的、PHP脚本语言的解释器,它最早是由以色列理工学院(Technion)的学生Andi Gutmans和Zeev Suraski所开发,Zend也正是此二人名字的合称。后来两人联合创立了Zend Technologies公司
Zend Engine 1.0于1999年随PHP 4发布,由C语言开发且经过高度优化,并能够做为PHP的后端模块使用。Zend Engine为PHP提供了内存和资源管理的功能以及其它的一些标准服务,其高性能、可靠性和可扩展性在促进PHP成为一种流行的语言方面发挥了重要作用
Zend Engine的出现将PHP代码的处理过程分成了两个阶段:
https://www.php.net/supported-versions.php
php 的配置文件:/etc/php.ini, /etc/php.d/*.ini
配置文件在php解释器启动时被读取
对配置文件的修改生效方法
Modules:重启httpd服务
FastCGI:重启php-fpm服务
[foo]:Section Header
directive = value #键值对
#html嵌套在php中
echo "Hello world!
"
?>
#php嵌套在html中
<h1>
echo "Hello world!" ?>
</h1>
#测试php是否正常工作
echo date("Y/m/d H:i:s");
phpinfo();
?>
httpd接收用户的web请求;静态资源则直接响应;动态资源为php脚本,对此类资源的请求将交由php来运行
[root@CentOS7 html]#grep -Ev '^#|^#' /etc/httpd/conf.d/php.conf
#识别php后缀文件后,使用php模块处理
SetHandler application/x-httpd-php
#在服务器添加mime-type;可以识别php文件
AddType text/html .php
#默认的索引文件
DirectoryIndex index.php
#session文件路径
php_value session.save_handler "files"
php_value session.save_path "/var/lib/php/session"
dnf install httpd php php-mysqlnd mariadb-server
dnf install httpd php-fpm php-mysqlnd mariadb-server
yum install httpd php php-mysql mariadb-server
yum install httpd php-fpm php-mysql mariadb-server
yum install httpd, php, php-mysql, mysql-server
#三种连接方式
[root@CentOS7 html]#rpm -ql php-mysql | grep so
/usr/lib64/php/modules/mysql.so
/usr/lib64/php/modules/mysqli.so
/usr/lib64/php/modules/pdo_mysql.so
$conn = mysql_connect('mysqlserver','username','password');
if ($conn)
echo "OK";
else
echo "Failure";
#echo mysql_error();
mysql_close();
?>
$mysqli=new mysqli("mysqlserver", "username", "password");
if(mysqli_connect_errno()){
echo "Failure";
$mysqli=null;
exit;
}
echo "OK";
$mysqli->close();
?>
$dsn='mysql:host=mysqlhost;dbname=mysql';
$username='root';
$passwd='magedu';
$dbh=new PDO($dsn,$username,$passwd);
var_dump($dbh);
?>
try {
$user='root';
$pass='magedu';
$dbh = new PDO('mysql:host=mysqlhost;dbname=mysql', $user, $pass);
foreach($dbh->query('SELECT user,host from user') as $row) {
print_r($row);
} $
dbh = null;
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "
";
die();
}
?>
#Module 模块方式实现
[root@centos8 ~]#dnf -y install httpd php php-mysqlnd mariadb-server
#修改为prefork模式支持httpd 模块方式
[root@centos8 ~]#vim /etc/httpd/conf.modules.d/00-mpm.conf
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
#LoadModule mpm_worker_module modules/mod_mpm_worker.so
#LoadModule mpm_event_module modules/mod_mpm_event.so
[root@centos8 ~]#systemctl start httpd php-fpm mariadb
#CentOS8的php默认是factcgi模式,将其注释掉;修改为httpd模块方式
[root@centos8 html]#vim /etc/httpd/conf.d/php.conf
#
#
# # Enable http authorization headers
# SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1
# #
#
# SetHandler "proxy:unix:/run/php-fpm/www.sock|fcgi://localhost"
#
#
#
[root@centos8 ~]#vim /var/www/html/lamp.php
[root@centos8 ~]#cat /var/www/html/lamp.php
query('SELECT user,host from user') as $row) {
print_r($row);
}
$dbh = null;
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "
";
die();
}
phpinfo();
?>
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-FZlKlRzj-1577107769909)(%E6%88%AA%E5%9B%BE/2019%E5%B9%B411%E6%9C%8821%E6%97%A5/image-20191218203839818.png)]
PhpMyAdmin是一个以PHP为基础,以Web-Base方式架构在网站主机上的MySQL的数据库管理工具,让管理者可用Web接口管理MySQL数据库
WordPress是一种使用PHP语言开发的博客平台,用户可以在支持PHP和MySQL数据库的服务器上架设属于自己的网站。也可把 **WordPress当作一个内容管理系统(CMS)**来使用
PHPWind:2003年发布了PHPWind的前身版本ofstar,并发展成为包含BBS、CMS、博客、SNS等一系列程序的通用型建站软件, 于2008年加入阿里巴巴集团
Crossday Discuz! Board(简称 Discuz!)是一套通用的社区论坛软件系统。自2001年6月面世以来,是全球成熟度最高、覆盖率最大的论坛软件系统之一。2010年8月23日,与腾讯达成收购协议
PowerDNS 是一个跨平台的开源DNS服务组件,它是高性能的域名服务器,除了支持普通的BIND配置文件,PowerDNS还可从MySQL,Oracle,PostgreSQL等的数据库读取数据。PowerDNS安装了Poweradmin(基于php实现),能实现Web管理DNS记录,非常方便
ECShop是一款B2C独立网店系统,适合企业及个人快速构建个性化网上商店。系统是基于PHP语言及MYSQL数据库构架开发的跨平台开源程序。2006年6月,ECShop推出第一个版本1.0
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-XpXvjFrh-1577107769910)(%E6%88%AA%E5%9B%BE/2019%E5%B9%B411%E6%9C%8821%E6%97%A5/screenshot-192.168.52.73-2019.12.19-18_07_07.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-O9c9EWPa-1577107769910)(%E6%88%AA%E5%9B%BE/2019%E5%B9%B411%E6%9C%8821%E6%97%A5/image-20191219181448805.png)]
#安装php7.2的yum源文件
[root@CentOS7 html]#yum install https://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/remi-release-7.rpm
#安装相关程序
[root@CentOS7 html]#yum install php72-php php72-php-mbstring php72-php-mysqlnd mariadb-server
#启动服务
[root@CentOS7 html]#systemctl start httpd mariadb
#下载phpMyadmin-4.9.2文件
[root@CentOS7 html]#wget https://files.phpmyadmin.net/phpMyAdmin/4.9.2/phpMyAdmin-4.9.2-alllanguages.zip
#解压文件
[root@CentOS7 html]#yum install unzip -y
[root@CentOS7 html]#unzip phpMyAdmin-4.9.2-all-languages.zip
[root@CentOS7 html]#cd phpMyAdmin-4.9.2-all-languages/
[root@CentOS7 html]#mv phpMyAdmin-4.9.2-all-languages /var/www/html/pma
#设置mysql的root密码,phpMyadmin不允许空密码登录
mysql_secure_installation
#php要求5.5版本以上,epel是5.4版本
yum -y install httpd mariadb-server php php-mysql
systemctl start mariadb
mysql_secure_installation
#下载:https://www.phpmyadmin.net/downloads/
unzip phpMyAdmin-4.4.15.10-all-languages.zip
mv phpMyAdmin-4.4.15.10-all-languages /var/www/html/phpmyadmin
cd /var/www/html/phpmyadmin/
cp config.sample.inc.php config.inc.php
#如果mysql 服务器和phpmyadmin不在同一台主机,还需要修改以下设置
vim config.inc.php
$cfg['Servers'][$i]['host'] = 'mysqlserverIP';
yum -y install php-mbstring
systemctl start httpd
#浏览器访问:http://LAMP服务器IP/phpmyadmin,输入root及口令即可登录
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ay87hMQ1-1577107769911)(%E6%88%AA%E5%9B%BE/2019%E5%B9%B411%E6%9C%8821%E6%97%A5/image-20191218213311445.png)]
[root@centos8 ~]#dnf -y install httpd php php-json php-mysqlnd mariadb-server
[root@centos8 ~]#systemctl start httpd mariadb
[root@centos8 ~]#mysql
MariaDB [(none)]> create database wordpress;
MariaDB [(none)]> grant all on wordpress.* to wordpress@'localhost' identified
by 'magedu';
[root@centos8 ~]#tar xvf wordpress-5.3-zh_CN.tar.gz -C /var/www/html/
[root@centos8 ~]#chown -R apache.apache wordpress/
#无需修改wp-config.php;
#浏览器访问进行页面安装
http://LAMP服务器/wordpress
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-CQP9Ryaz-1577107769911)(%E6%88%AA%E5%9B%BE/2019%E5%B9%B411%E6%9C%8821%E6%97%A5/image-20191219152914410.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-7TvCYglp-1577107769912)(%E6%88%AA%E5%9B%BE/2019%E5%B9%B411%E6%9C%8821%E6%97%A5/image-20191219152931954.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-kxOVASwf-1577107769913)(%E6%88%AA%E5%9B%BE/2019%E5%B9%B411%E6%9C%8821%E6%97%A5/image-20191219152946517.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-0CJ4254i-1577107769913)(%E6%88%AA%E5%9B%BE/2019%E5%B9%B411%E6%9C%8821%E6%97%A5/image-20191219152959891.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-R1aCSfj8-1577107769914)(%E6%88%AA%E5%9B%BE/2019%E5%B9%B411%E6%9C%8821%E6%97%A5/screenshot-192.168.52.8-2019.12.19-17_57_25.png)]
#下载官网地址:https://cn.wordpress.org/
#解压缩WordPress博客程序到网页站点目录下
unzip wordpress-5.1.1-zh_CN.zip
mv wordpress /var/www/html/
#新建wpdb库和wpuser用户
mysql> create database wpdb;
mysql> grant all on wpdb.* to wpuser@'%' identified by "wppass";
setfacl –R –m u:apache:rwx /var/www/html/wordpress/
#或者chown –R apache.apache /var/www/html/wordpress
#打开http://LAMP服务器IP/wordpress进行页面安装
[root@centos8 ~]#dnf -y install httpd php php-xml(模块) php-mysqlnd mariadb-server
[root@centos8 ~]#unzip Discuz_X3.4_SC_UTF8【20191201】.zip
[root@centos8 ~]#mv upload/ /var/www/html/forum
[root@centos8 ~]#chown -R apache.apache /var/www/html/forum
#单建数据库和用户
[root@centos8 ~]#mysql
MariaDB [ultrax]> create database ultrax;
MariaDB [ultrax]> grant all on ultrax.* to ultrax@'localhost' identified by
'magedu';
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-e5jhhDPN-1577107769914)(%E6%88%AA%E5%9B%BE/2019%E5%B9%B411%E6%9C%8821%E6%97%A5/image-20191219130120410.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-VDI8V3tC-1577107769915)(%E6%88%AA%E5%9B%BE/2019%E5%B9%B411%E6%9C%8821%E6%97%A5/image-20191219130146865.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-9LrQBzib-1577107769915)(%E6%88%AA%E5%9B%BE/2019%E5%B9%B411%E6%9C%8821%E6%97%A5/image-20191219130206654.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-1Gyt1FW8-1577107769916)(%E6%88%AA%E5%9B%BE/2019%E5%B9%B411%E6%9C%8821%E6%97%A5/image-20191219130231944.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Rz2zaa8q-1577107769917)(%E6%88%AA%E5%9B%BE/2019%E5%B9%B411%E6%9C%8821%E6%97%A5/image-20191219130714203.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-HO1LxhHq-1577107769918)(%E6%88%AA%E5%9B%BE/2019%E5%B9%B411%E6%9C%8821%E6%97%A5/image-20191219130726403.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-7YkDKbM1-1577107769918)(%E6%88%AA%E5%9B%BE/2019%E5%B9%B411%E6%9C%8821%E6%97%A5/image-20191219130736268.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-0hkNDCrV-1577107769919)(%E6%88%AA%E5%9B%BE/2019%E5%B9%B411%E6%9C%8821%E6%97%A5/screenshot-www.yanyimedia.com-2019.12.19-17_55_46.png)]
#官网:http://www.discuz.net
#下载源码:
wget http://download.comsenz.com/DiscuzX/3.3/Discuz_X3.3_SC_UTF8.zip
unzip Discuz_X3.3_SC_UTF8.zip
mv upload/ /var/www/html/forum
setfacl -R -m u:apache:rwx /var/www/html/forum
mysql>create database discuz;
mysql>grant all on discuz.* to discuz@'172.16.0.%’identified by"magedu";
安装向导:http://localhost/forum
PowerDNS官网:https://www.powerdns.com/
PowerDNS文档:https://doc.powerdns.com/
Poweradmin官网:http://www.poweradmin.org/
[root@centos8 ~]#yum install -y pdns pdns-backend-mysql mariadb-server
[root@centos8 ~]#systemctl start mariadb
[root@centos8 ~]#mysql
MariaDB [(none)]> CREATE DATABASE powerdns;
Query OK, 1 row affected (0.000 sec)
MariaDB [(none)]> GRANT ALL ON powerdns.* TO 'powerdns'@'localhost' IDENTIFIED
BY 'magedu';
Query OK, 0 rows affected (0.001 sec)
[root@centos8 ~]#mysql powerdns < pdns.sql
[root@centos8 ~]#vim /etc/pdns/pdns.conf
launch=gmysql
gmysql-host=localhost
gmysql-port=3306
gmysql-dbname=powerdns
gmysql-user=powerdns
gmysql-password=magedu
[root@centos8 ~]#grep -Ev "^#|^$" /etc/pdns/pdns.conf
launch=gmysql
gmysql-host=localhost
gmysql-port=3306
gmysql-dbname=powerdns
gmysql-user=powerdns
gmysql-password=magedu
setgid=pdns
setuid=pdns
[root@centos8 ~]#systemctl enable --now pdns
[root@centos8 ~]#ss -ntlpu |grep pdns_server
udp UNCONN 0 0 0.0.0.0:53 0.0.0.0:*
users:(("pdns_server",pid=3073,fd=9))
udp UNCONN 0 0 [::]:53 [::]:*
users:(("pdns_server",pid=3073,fd=10))
tcp LISTEN 0 128 0.0.0.0:53 0.0.0.0:*
users:(("pdns_server",pid=3073,fd=11))
tcp LISTEN 0 128 [::]:53 [::]:*
users:(("pdns_server",pid=3073,fd=12))
#安装httpd和php相关包
[root@centos8 ~]#yum -y install httpd php php-devel php-gd php-mcrypt php-imap php-ldap php-mysql php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mhash gettext
[root@centos8 ~]#systemctl enable --now httpd
#下载poweradmin程序,并解压缩到相应目录
[root@centos8 ~]#wget
http://downloads.sourceforge.net/project/poweradmin/poweradmin-2.1.7.tgz
[root@centos8 ~]#tar xvf poweradmin-2.1.7.tgz -C /var/www/html
[root@centos8 ~]#cd /var/www/html
[root@centos8 ~]#mv poweradmin-2.1.7 poweradmin
#安装包:基于EPEL源
[root@centos7 ~]#yum install -y pdns pdns-backend-mysql mariadb-server
[root@centos7 ~]#systemctl enable --now mariadb
#准备mariadb中的数据库,表和用户
[root@centos7 ~]#mysql
CREATE DATABASE powerdns;
GRANT ALL ON powerdns.* TO 'powerdns'@'localhost' IDENTIFIED BY 'magedu';
#创建powerdns数据库中的表,参看下面文档实现
#https://doc.powerdns.com/md/authoritative/backend-generic-mysql/
use powerdns
CREATE TABLE domains (
id INT AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
master VARCHAR(128) DEFAULT NULL,
last_check INT DEFAULT NULL,
type VARCHAR(6) NOT NULL,
notified_serial INT DEFAULT NULL,
account VARCHAR(40) DEFAULT NULL,
PRIMARY KEY (id)
) Engine=InnoDB;
CREATE UNIQUE INDEX name_index ON domains(name);
CREATE TABLE records (
id BIGINT AUTO_INCREMENT,
domain_id INT DEFAULT NULL,
name VARCHAR(255) DEFAULT NULL,
type VARCHAR(10) DEFAULT NULL,
content VARCHAR(64000) DEFAULT NULL,
ttl INT DEFAULT NULL,
prio INT DEFAULT NULL,
change_date INT DEFAULT NULL,
disabled TINYINT(1) DEFAULT 0,
ordername VARCHAR(255) BINARY DEFAULT NULL,
auth TINYINT(1) DEFAULT 1,
PRIMARY KEY (id)
) Engine=InnoDB;
CREATE INDEX nametype_index ON records(name,type);
CREATE INDEX domain_id ON records(domain_id);
CREATE INDEX recordorder ON records (domain_id, ordername);
CREATE TABLE supermasters (
ip VARCHAR(64) NOT NULL,
nameserver VARCHAR(255) NOT NULL,
account VARCHAR(40) NOT NULL,
PRIMARY KEY (ip, nameserver)
) Engine=InnoDB;
CREATE TABLE comments (
id INT AUTO_INCREMENT,
domain_id INT NOT NULL,
name VARCHAR(255) NOT NULL,
type VARCHAR(10) NOT NULL,
modified_at INT NOT NULL,
account VARCHAR(40) NOT NULL,
comment VARCHAR(64000) NOT NULL,
PRIMARY KEY (id)
) Engine=InnoDB;
CREATE INDEX comments_domain_id_idx ON comments (domain_id);
CREATE INDEX comments_name_type_idx ON comments (name, type);
CREATE INDEX comments_order_idx ON comments (domain_id, modified_at);
CREATE TABLE domainmetadata (
id INT AUTO_INCREMENT,
domain_id INT NOT NULL,
kind VARCHAR(32),
content TEXT,
PRIMARY KEY (id)
) Engine=InnoDB;
CREATE INDEX domainmetadata_idx ON domainmetadata (domain_id, kind);
CREATE TABLE cryptokeys (
id INT AUTO_INCREMENT,
domain_id INT NOT NULL,
flags INT NOT NULL,
active BOOL,
content TEXT,
PRIMARY KEY(id)
) Engine=InnoDB;
CREATE INDEX domainidindex ON cryptokeys(domain_id);
CREATE TABLE tsigkeys (
id INT AUTO_INCREMENT,
name VARCHAR(255),
algorithm VARCHAR(50),
secret VARCHAR(255),
PRIMARY KEY (id)
) Engine=InnoDB;
CREATE UNIQUE INDEX namealgoindex ON tsigkeys(name, algorithm);
#配置PowerDNS使用mariadb作为后台数据存储
[root@centos7 ~]#vim /etc/pdns/pdns.conf,查找到包含launch= 的行,修改并添加下面的内容
launch=gmysql
gmysql-host=localhost
gmysql-port=3306
gmysql-dbname=powerdns
gmysql-user=powerdns
gmysql-password=magedu
[root@centos7 ~]#grep -Ev "^#|^$" /etc/pdns/pdns.conf
launch=gmysql
gmysql-host=localhost
gmysql-port=3306
gmysql-dbname=powerdns
gmysql-user=powerdns
gmysql-password=magedu
setgid=pdns
setuid=pdns
#启动服务
[root@centos7 ~]#systemctl enable --now pdns
[root@centos7 ~]#ss -ntl
State Recv-Q Send-Q Local Address:Port
Peer Address:Port
LISTEN 0 100 127.0.0.1:25
*:*
LISTEN 0 50 *:3306
*:*
LISTEN 0 128 *:53
*:*
LISTEN 0 128 *:22
*:*
LISTEN 0 100 [::1]:25
[::]:*
LISTEN 0 128 [::]:53
[::]:*
LISTEN 0 128 [::]:22
[::]:*
#安装httpd和php相关包
[root@centos7 ~]#yum -y install httpd php php-devel php-gd php-mcrypt php-imap php-ldap php-mysql php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mhash gettext
[root@centos7 ~]#systemctl enable --now httpd
#下载poweradmin程序,并解压缩到相应目录
[root@centos7 ~]#wget
http://downloads.sourceforge.net/project/poweradmin/poweradmin-2.1.7.tgz
[root@centos7 ~]#tar xvf poweradmin-2.1.7.tgz -C /var/www/html
[root@centos7 ~]#cd /var/www/html
[root@centos7 ~]#mv poweradmin-2.1.7 poweradmin
http://powerdns服务器IP/poweradmin/install/
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-nu5rVKCK-1577107769919)(%E6%88%AA%E5%9B%BE/2019%E5%B9%B411%E6%9C%8821%E6%97%A5/screenshot-192.168.52.72-2019.12.19-16_51_55.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-MNStcq29-1577107769920)(%E6%88%AA%E5%9B%BE/2019%E5%B9%B411%E6%9C%8821%E6%97%A5/screenshot-192.168.52.72-2019.12.19-16_53_35.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-MtTrfXBV-1577107769920)(%E6%88%AA%E5%9B%BE/2019%E5%B9%B411%E6%9C%8821%E6%97%A5/screenshot-192.168.52.72-2019.12.19-17_15_29.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-lS60BMgR-1577107769921)(%E6%88%AA%E5%9B%BE/2019%E5%B9%B411%E6%9C%8821%E6%97%A5/screenshot-www.yanyimedia.com-2019.12.20-10_23_57.png)]
MariaDB [(none)]>GRANT SELECT,INSERT,UPDATE,DELETE ON powerdns.* TO
'poweradmin'@'localhost‘ IDENTIFIED BY 'magedu';
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ifYWVRID-1577107769921)(%E6%88%AA%E5%9B%BE/2019%E5%B9%B411%E6%9C%8821%E6%97%A5/screenshot-192.168.52.72-2019.12.19-17_26_32.png)]
vim /var/www/html/poweradmin/inc/config.inc.php
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-UvMv7yrO-1577107769922)(%E6%88%AA%E5%9B%BE/2019%E5%B9%B411%E6%9C%8821%E6%97%A5/screenshot-www.yanyimedia.com-2019.12.20-10_26_51.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-l2O1kiqy-1577107769923)(%E6%88%AA%E5%9B%BE/2019%E5%B9%B411%E6%9C%8821%E6%97%A5/screenshot-192.168.52.72-2019.12.19-17_34_24.png)]
rm -rf /var/www/html/poweradmin/install/
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-fbf0P4db-1577107769923)(%E6%88%AA%E5%9B%BE/2019%E5%B9%B411%E6%9C%8821%E6%97%A5/screenshot-192.168.52.72-2019.12.19-17_39_39.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-rMbRuZlB-1577107769924)(%E6%88%AA%E5%9B%BE/2019%E5%B9%B411%E6%9C%8821%E6%97%A5/screenshot-192.168.52.72-2019.12.19-17_42_02.png)]
Zend Optimizer并非一个opcode加速器,它是由Zend Technologies为PHP5.2及以前的版本提供的一个免费、闭源的PHP扩展,其能够运行由Zend Guard生成的加密的PHP代码或模糊代码。 而Zend Guard Loader则是专为PHP5.3提供的类似于Zend Optimizer功能的扩展。
项目地址http://www.zend.com/en/products/guard/runtime-decoders
NuSphere的一款开源PHP加速器,它支持装载通过NuSphere PHP Encoder编码的PHP程序文件,并能够实现对常规PHP文件的执行加速。
项目地址,http://www.nusphere.com/products/phpexpress. htm
[root@centos7 ~]#yum -y install
https://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/remi-release-7.rpm
[root@centos7 ~]#yum install php56-php php56-php-mysqlnd mariadb-server
[root@centos7 ~]#systemctl enable --now httpd mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service
to /usr/lib/systemd/system/httpd.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service
to /usr/lib/systemd/system/mariadb.service.
[root@centos7 ~]#mysql
MariaDB [(none)]> create database wordpress;
MariaDB [(none)]> grant all on wordpress.* to wordpress@'localhost' identified
by 'magedu';
[root@centos7 ~]#tar xvf wordpress-5.2.4-zh_CN.tar.gz -C /var/www/html
[root@centos7 ~]#cd /var/www/html
[root@centos7 ~]#chown -R apache.apache wordpress/
[root@centos7 ~]#yum -y install gcc php56-php-devel php56-php-cli
#编译安装xcache
#下载并解压缩xcache-3.2.0.tar.bz2
[root@centos7 ~]#tar xf xcache-3.2.0.tar.gz
#生成编译环境
[root@centos7 ~]#cd xcache-3.2.0/
[root@centos7 xcache-3.2.0]#/opt/remi/php56/root/usr/bin/phpize
Configuring for:
PHP Api Version: 20131106
Zend Module Api No: 20131226
Zend Extension Api No: 220131226
[root@centos7 xcache-3.2.0]#./configure --enable-xcache --with-php-config=/opt/remi/php56/root/usr/bin/php-config
[root@centos7 xcache-3.2.0]#make && make install
...省略...
Installing shared extensions: /opt/remi/php56/root/usr/lib64/php/modules/
[root@centos7 xcache-3.2.0]#cat xcache.ini >> /opt/remi/php56/root/etc/php.ini
#安装base源中执行即可cp xcache.ini /etc/php.d/
[root@centos7 ~]#systemctl restart httpd.service
#测试性能
[root@centos7 ~]#ab -c10 -n 100 http://LAMP服务器/wordpress
#测试页
[root@CentOS7 html]#vim test.php
#访问测试页面http://LAMP服务器/test.php
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-BSqYss8r-1577107769924)(%E6%88%AA%E5%9B%BE/2019%E5%B9%B411%E6%9C%8821%E6%97%A5/screenshot-192.168.52.74-2019.12.20-09_54_45.png)]
[root@centos8 ~]#dnf install php-opcache
[root@centos8 ~]#cat /etc/php.d/10-opcache.ini
[opcache]
zend_extension=opcache.so
opcache.enable=1
[root@centos8 ~]#dnf install php-opcache
[root@centos8 ~]#rpm -ql php-opcache
/etc/php.d/10-opcache.ini
/etc/php.d/opcache-default.blacklist
/usr/lib/.build-id
/usr/lib/.build-id/71
/usr/lib/.build-id/71/55ebb00f7ebcab9d708c1d5c7b7e634cce259c
/usr/lib64/php/modules/opcache.so
#模块加载配置文件不需要修改,直接启用了
[root@centos8 ~]#grep -Ev '^;|^$' /etc/php.d/10-opcache.ini
zend_extension=opcache
opcache.enable=1 #启用加速器
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.blacklist_filename=/etc/php.d/opcache*.blacklist
opcache.huge_code_pages=1
#测试性能
[root@centos8 ~]#ab -c10 -n 100 http://LAMP服务器/wordpress
#测试页
[root@CentOS8 html]#vim test.php
#访问测试页面http://LAMP服务器/test.php
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-yVmu5HyD-1577107769925)(%E6%88%AA%E5%9B%BE/2019%E5%B9%B411%E6%9C%8821%E6%97%A5/image-20191220104616566.png)]
## 5 php-fpm 模式实现LAMP
### 5.1 实现php-fpm模式
- 对于php请求,httpd可以用模块和fastcgi两种方式实现动态程序的支持。
- fastcgi模式:php处理请求,不再由http服务器自身进行管理,http服务器把http协议转化为factcgi协议,通过socket发送给fastcgi专用进程处理php程序
- 从稳定性上看,fastcgi是以独立的进程池运行来程序,如果单独一个进程死掉,系统可以很轻易的丢弃,然后重新分配新的进程来运行逻辑。从安全性上看,fastcgi和http的server完全独立, fastcgi怎么down也不会把server搞垮。
- 从性能上看,fastcgi把动态逻辑的处理从http server中分离出来,大负荷的IO处理还是留给宿主server,这样hpttd server可以一心一意作IO,对于一个普通的动态网页来说,逻辑处理可能只有一小部分,大量的图片等静态IO处理完全不需要逻辑程序的参与。从扩展性上讲,fastcgi是一个中立的技术标准,完全可以支持任何语言写的处理程序,如php,java,python等。而php-fpm就是用来支持php的fastcgi服务器。
- ##### 各种OS版本对fastcgi的支持
- CentOS 8: 默认使用fpm模式
- CentOS 7:
- httpd-2.4:默认rpm包支持fcgi模块
- php-fpm包:专用于将php运行于fpm模式
- CentOS 6:
- PHP-5.3.2之前:默认不支持fpm机制;需要自行打补丁并编译安装
- httpd-2.2:默认不支持fcgi协议,需要自行编译此模块
- 解决方案:编译安装httpd-2.4, php-5.3.3+
### 5.2 安装php-fpm
- ##### CentOS 7 安装php-fpm
- ##### BASE源安装PHP-FPM
```ini
yum install php-fpm
yum install https://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/remi-release-
7.rpm
#安装php-fpm5.6版
yum install php56-php-fpm php56-php-mysql
#安装php-fpm7.3版
yum install php73-php-fpm php73-php-mysql
rpm -ql php-fpm
/etc/httpd/conf.d/php.conf #自动生成httpd配置文件
/etc/logrotate.d/php-fpm
/etc/nginx/conf.d/php-fpm.conf #自动生成nginx配置文件
/etc/nginx/default.d/php.conf #自动生成nginx配置文件
/etc/php-fpm.conf #主配置文件
/etc/php-fpm.d #配置文件目录
/etc/php-fpm.d/www.conf #配置文件
/etc/systemd/system/php-fpm.service.d
/run/php-fpm
/usr/lib/systemd/system/php-fpm.service #生成systemd进程
cat /etc/php-fpm.d/www.conf
[www]
listen = 127.0.0.1:9000 #监听地址及IP
listen.allowed_clients = 127.0.0.1 #允许客户端从哪个源IP地址访问,要允许所有行首加 ;注释即可
user = apache #php-fpm启动的用户和组,会涉及到后期文件的权限问题
group = apache
pm = dynamic #动态模式进程管理
pm.max_children = 500 #静态方式下开启的php-fpm进程数量,在动态方式下他限定php-fpm的最大进程数
pm.start_servers = 100 #动态模式下初始进程数,必须大于等于pm.min_spare_servers和小于等于pm.max_children的值。
pm.min_spare_servers = 100 #最小空闲进程数
pm.max_spare_servers = 200 #最大空闲进程数
pm.max_requests = 500000 #进程累计请求回收值,会重启
pm.status_path = /pm_status #状态访问URL
ping.path = /ping #ping访问动地址
ping.response = ping-pong #ping返回值
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 #phpsession保存方式及路径
php_value[session.save_path] = /var/lib/php/session #当时使用file保存session的文件路径
[root@centos8 ~]#httpd -M |grep fcgi
AH00558: httpd: Could not reliably determine the server's fully qualified domain
name, using centos8.localdomain. Set the 'ServerName' directive globally to
suppress this message
proxy_fcgi_module (shared)
[root@centos8 ~]#cat /etc/httpd/conf.modules.d/00-proxy.conf
# This file configures all the proxy modules:
LoadModule proxy_module modules/mod_proxy.so
LoadModule lbmethod_bybusyness_module modules/mod_lbmethod_bybusyness.so
LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so
LoadModule lbmethod_bytraffic_module modules/mod_lbmethod_bytraffic.so
LoadModule lbmethod_heartbeat_module modules/mod_lbmethod_heartbeat.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_express_module modules/mod_proxy_express.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
LoadModule proxy_fdpass_module modules/mod_proxy_fdpass.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_hcheck_module modules/mod_proxy_hcheck.so
LoadModule proxy_scgi_module modules/mod_proxy_scgi.so
LoadModule proxy_uwsgi_module modules/mod_proxy_uwsgi.so
LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so
DirectoryIndex index.php
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://php-fpm服务器IP:9000/var/www/html/$1
#以上开启FCGI反向代理,“^/”这处的”/“相对于后面的/var/www/html而言,后面的$1是指前面的/(.*.php)
#php-fpm服务器需要修改配置文件
#unix套接字文件;要求httpd版本2.4.9以上
ProxyPassMatch ^/(.*\.php)$
unix:/var/run/php.sock|fcgi://localhost/app/httpd24/htdocs/
#三台主机:
192.168.52.8 mysql
192.168.52.18 httpd
192.168.52.28 php-fpm
#192.168.52.8 mysql
[root@mysql ~]#yum install mariadb-server -y
[root@mysql ~]#systemctl start mariadb.service
[root@mysql ~]#mysql
#创建WordPress数据库
MariaDB [(none)]> create database wordpress;
#设置WordPress账户和权限
MariaDB [(none)]> grant all on wordpress.* to wordpress@‘192.168.52.%’ identified by ‘yanyi’;
#最后在数据库生成WordPress数据表
MariaDB [wordpress]> show tables;
±----------------------+
| Tables_in_wordpress |
±----------------------+
| wp_commentmeta |
| wp_comments |
| wp_links |
| wp_options |
| wp_postmeta |
| wp_posts |
| wp_term_relationships |
| wp_term_taxonomy |
| wp_termmeta |
| wp_terms |
| wp_usermeta |
| wp_users |
±----------------------+
12 rows in set (0.00 sec)
#192.168.52.28 php-fpm
#安装php程序
[root@fcgi ~]#yyum install php-fpm php-mysqlnd -y
[root@fcgi ~]#rpm -ql php-fpm
/etc/httpd/conf.d/php.conf
/etc/logrotate.d/php-fpm
/etc/nginx/conf.d/php-fpm.conf
/etc/nginx/default.d/php.conf
/etc/php-fpm.conf
/etc/php-fpm.d
/etc/php-fpm.d/www.conf #修改
/etc/systemd/system/php-fpm.service.d
/run/php-fpm
/usr/lib/systemd/system/php-fpm.service
…省略…
#修改配置文件
[root@fcgi ~]#vim /etc/php-fpm.d/www.conf
;listen = /run/php-fpm/www.sock #注释掉此行
listen = 9000 #添加此行:监听端口9000
;listen.allowed_clients = 127.0.0.1 #注释掉此行:允许监听所有主机
#启动php-fpm服务
[root@fcgi ~]#systemctl start php-fpm.service
#9000监听端口开启
[root@fcgi ~]#ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]
LISTEN 0 128 *:9000 :
[root@fcgi ~]#cd /data/
[root@fcgi data]#mkdir html
[root@fcgi html]#vim test.php
#生成WordPress在FCGI服务器为了加载*.php文件
[root@fcgi html]#tar xvf wordpress-5.2.4-zh_CN.tar.gz -C /data/html
[root@fcgi html]#chown -R apache:apache wordpress
#192.168.52.18 httpd
[root@httpd html]#yum install httpd -y
[root@httpd html]#httpd -M |grep fcgi
proxy_fcgi_module (shared)
#新建配置文件;获取fcgi
[root@httpd html]#vim /etc/httpd/conf.d/fcgi.conf
DirectoryIndex index.php
ProxyRequests Off
ProxyPassMatch ^/(..php)$ fcgi://192.168.52.8:9000/data/html/$1
#修改httpd主配置文件
[root@httpd html]#vim /etc/httpd/conf/httpd.conf
DirectoryIndex index.php index.html #此行添加index.php
#在httpd服务器生成WordPress是为了加载静态的html、css、js页面(美观效果);生成WordPress在FCGI服务器为了加载.php文件;不在httpd创建此,无法在网页加载WordPress服务
[root@httpd html]#tar xvf wordpress-5.2.4-zh_CN.tar.gz
[root@httpd html]#chown -R apache:apache wordpress
[root@httpd html]systemctl restart httpd
#执行安装WordPress 192.168.52.18/wordpress
#注意:在网页上无法实现发布图片,因为没有资源共享服务,其他客户端无法获取php-fpm上的资源;上传的资源是存放在php-fpm主机上的;
#一般情况下是php和httpd服务是在同一台主机上的,但是多台之间由调度器;也需要资源共享
[root@fcgi uploads]#pwd
/data/html/wordpress/wp-content/uploads
[root@fcgi uploads]#tree
.
└── 2019
└── 12
└── mod_synths_D_SimpleDesktops.png
2 directories, 1 file
- ##### 无法加载图片,但是图片已经存储在php-fpm服务器
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-TVvlyJY5-1577107769926)(%E6%88%AA%E5%9B%BE/2019%E5%B9%B411%E6%9C%8821%E6%97%A5/image-20191220154135041.png)]
#### 5.4.1 实战案例:虚拟主机配置支持FCGI
- ```ini
vim /etc/httpd/conf.d/vhosts.conf
DirectoryIndex index.php
ServerName www.magedu.net
DocumentRoot /apps/vhosts/magedu.net
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/apps/vhosts/magedu.net/$1
Options None
AllowOverride None
Require all granted
#安装httpd包00:0C:29:89:72:C0
yum install httpd
#查看Httpd mod_fcgi模块是否加载
httpd -M | grep fcgi
proxy_fcgi_module (shared)
#添加FCGI的配置文件
DirectoryIndex index.php
ProxyRequests off //是否开启正向代理
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/html/$1
vim /etc/php-fpm.d/www.conf
pm.status_path = /status #启用:启用PHP-FPM状态模式
ping.path = /ping #启用:为了测试存活性
vim /etc/httpd/conf.d/php.conf
#增加#######之间内容
# Enable http authorization headers
SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1
SetHandler "proxy:unix:/run/php-fpm/www.sock|fcgi://localhost"
#######使得status|ping后缀由php程序处理通过/run/php-fpm/www.sock
SetHandler "proxy:unix:/run/php-fpm/www.sock|fcgi://localhost"
#######
#测试
[root@centos8 ~]#curl 192.168.52.18/ping
pong
[root@centos8 ~]#curl 192.168.52.18/status
pool: www
process manager: dynamic
start time: 20/Dec/2019:16:06:50 +0800
start since: 194
accepted conn: 10
listen queue: 0
max listen queue: 0
listen queue len: 0
idle processes: 5
active processes: 1
total processes: 6
max active processes: 2
max children reached: 0
slow requests: 0
- ##### status支持多种格式
```ini
[root@centos8 ~]#curl 192.168.52.18/status
pool: www
process manager: dynamic
start time: 20/Dec/2019:16:06:50 +0800
start since: 424
accepted conn: 15
listen queue: 0
max listen queue: 0
listen queue len: 0
idle processes: 5
active processes: 1
total processes: 6
max active processes: 2
max children reached: 0
slow requests: 0
#192.168.52.18/status?html
[root@centos8 ~]#curl 192.168.52.18/status?html
PHP-FPM Status Page
pool www
process manager dynamic
start time 20/Dec/2019:16:06:50 +0800
start since 454
accepted conn 16
listen queue 0
max listen queue 0
listen queue len 0
idle processes 5
active processes 1
total processes 6
max active processes 2
max children reached 0
slow requests 0
#status?xml
[root@centos8 ~]#curl 192.168.52.18/status?xml
www
dynamic
1576829210
500
20
0
0
0
5
1
6
2
0
0
#status?full
[root@centos8 ~]#curl 192.168.52.18/status?full
pool: www
process manager: dynamic
start time: 20/Dec/2019:16:06:50 +0800
start since: 527
accepted conn: 21
listen queue: 0
max listen queue: 0
listen queue len: 0
idle processes: 5
active processes: 1
total processes: 6
max active processes: 2
max children reached: 0
slow requests: 0
************************
pid: 4427
state: Idle
start time: 20/Dec/2019:16:06:50 +0800
start since: 527
requests: 4
request duration: 147
request method: GET
request URI: /status?xml
content length: 0
user: -
script: -
last request cpu: 0.00
last request memory: 2097152
************************
pid: 4428
state: Idle
start time: 20/Dec/2019:16:06:50 +0800
start since: 527
requests: 3
request duration: 226
request method: GET
request URI: /status?xml
content length: 0
user: -
script: -
last request cpu: 0.00
last request memory: 2097152
************************
pid: 4429
state: Running
start time: 20/Dec/2019:16:06:50 +0800
start since: 527
requests: 4
request duration: 379
request method: GET
request URI: /status?full
content length: 0
user: -
script: -
last request cpu: 0.00
last request memory: 0
************************
pid: 4430
state: Idle
start time: 20/Dec/2019:16:06:50 +0800
start since: 527
requests: 4
request duration: 195
request method: GET
request URI: /status?html
content length: 0
user: -
script: -
last request cpu: 0.00
last request memory: 2097152
************************
pid: 4431
state: Idle
start time: 20/Dec/2019:16:06:50 +0800
start since: 527
requests: 3
request duration: 259
request method: GET
request URI: /status?html
content length: 0
user: -
script: -
last request cpu: 0.00
last request memory: 2097152
************************
pid: 4652
state: Idle
start time: 20/Dec/2019:16:06:58 +0800
start since: 519
requests: 3
request duration: 251
request method: GET
request URI: /status?fun
content length: 0
user: -
script: -
last request cpu: 0.00
last request memory: 2097152
#安装httpd 2.4 和 php 7.3 相关包
yum install https://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/remi-release-
7.rpm
vim /etc/yum.repos.d/remi-php73.repo
yum install httpd php73-php-fpm php73-php-mysqlnd php73-php-opcache php73-php-json-y
#配置php为UDS模式
vi /etc/opt/remi/php73/php-fpm.d/www.conf
listen=/var/run/php.sock
listen.owner = apache
listen.group = apache
listen.mode = 0660
#配置httpd 支持 php 的fastcgi模式
vim /etc/httpd/conf.d/test.conf
DirectoryIndex index.php
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ unix:/var/run/php.sock|fcgi://localhost/var/www/html/$1
systemctl start httpd php73-php-fpm.service
#准备wordpress程序文件
mkdir /data/
unzip wordpress-5.2.3-zh_CN.zip
mv wordpress/ /var/www/html/
setfacl –R –m u:apache:rwx /var/www/html/wordpress/
#或者chown –R apache.apache /var/www/html/wordpress
#在另一台主机上安装mariadb
yum install mariadb-server
systemctl start mariadb+
mysql -uroot
mysql> create database wordpress;
mysql> grant all on wordpress.* to wpuser@'192.168.8.%' identified by "magedu";
mysql> flush privileges;
#打开浏览器访问 http://httpd服务器IP/wordpress,进行初始化和安装
#安装相关包,依赖epel源
yum install gcc make libxml2-devel bzip2-devel libmcrypt-devel
#编译安装php
tar xvf php-5.6.30.tar.bz2
cd php-5.6.30
./configure --prefix=/app/php \
--with-mysql=/usr/local/mysql \
--with-openssl \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--enable-mbstring \
--with-png-dir \
--with-jpeg-dir \
--with-freetype-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--enable-sockets \
--with-apxs2=/app/httpd24/bin/apxs \
--with-mcrypt \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--with-bz2
make -j 4 && make install
#准备php的配置文件
cd php-5.6.30
cp php.ini-production /etc/php.ini
#修改httpd配置文件支持php
vim /etc/httpd24/conf/httpd.conf
#下面加二行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
#定位至DirectoryIndex index.html, 修改为
DirectoryIndex index.php index.html
apachectl restart
#安装相关包, 依赖epel源
yum install gcc make libxml2-devel bzip2-devel libmcrypt-devel
#编译安装php 7.3
tar xvf php-7.3.10.tar.xz
cd php-7.3.10/
./configure \
--prefix=/app/php \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-openssl \
--with-pdo-mysql=mysqlnd \
--enable-mbstring \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--enable-sockets \
--with-apxs2=/app/httpd24/bin/apxs \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--enable-maintainer-zts \
--disable-fileinfo
#说明:
#--enable-maintainer-zts 仅针对mpm为event和worker的情况,编译成zts模块,如果是prefork则不需要
#php-7.0 以上版本使用--enable-mysqlnd --with-mysqli=mysqlnd ,原--with-mysql不再支持
make -j 4 && make install
cp php.ini-production /etc/php.ini
vim /etc/httpd24/httpd.conf
在文件尾部加两行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
修改下面行
DirectoryIndex index.php index.html
#安装相关包,依赖EPEL源
yum install gcc make libxml2-devel bzip2-devel libmcrypt-devel
#编译安装 php 7.3
tar xvf php-7.3.10.tar.bz2
cd php-7.3.10/
./configure --prefix=/app/php \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-openssl \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--enable-mbstring \
--enable-xml \
--enable-sockets \
--enable-fpm \
--enable-maintainer-zts \
--disable-fileinfo
make && make install
#准备php的配置文件
cd php-7.3.10/
cp php.ini-production /etc/php.ini #php主配置文件
cd /app/php/etc
cp php-fpm.conf.default php-fpm.conf #php-fpm配置文件
#专门针对web服务的php-fpm配置文件
cp php-fpm.d/www.conf.default php-fpm.d/www.conf
#配置FCGI;准备php-fpm启动脚本或service unit文件
#php-fpm启动脚本
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
service php-fpm start
#php-fpm启动service unit文件
cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/
systemctl daemon reload
systemctl start php-fpm
#配置httpd支持php
vim /app/httpd24/conf/httpd.conf
#取消下面两行的注释;启用下面两个模块
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
#修改下面行添加index.php
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
#加下面四行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
ProxyRequests Off
ProxyPassMatch ^/(.*.php) fcgi://127.0.0.1:9000/var/www/html/$1
#支持opcache加速
vim /etc/php.ini
[opcache]
zend_extension=opcache.so
opcache.enable=1
useradd -r -s /sbin/nologin mysql
tar xvf mariadb-10.2.27-linux-x86_64.tar.gz -C /usr/local
cd /usr/local
ls -sv mariadb-10.2.27-linux-x86_64 mysql
cd mysql
chown -R root.root ./*
mkdir /data/mysql -p
chown -R mysql.mysql /data/mysql
mkdir /etc/mysql
cp support-files/my-huge.cnf /etc/mysql/my.cnf
vim /etc/mysql/my.cnf
[mysqld]
#加三行
datadir =/data/mysql
skip_name_resolve = ON
#准备PATH变量
vim /etc/profile.d/lamp.sh
PATH=/usr/local/mysql/bin/:$PATH
. /etc/profile.d/lamp.sh
cd /usr/local/mysql;scripts/mysql_install_db --user=mysql --datadir=/data/mysql
cp support-files/mysql.server /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
service mysqld start
#为wordpress应用准备数据库和用户
mysql
mysql> create database wordpress;
mysql> grant all on wordpress.* to wpuser@'192.168.8.%' identified by "wppass";
useradd -r -s /sbin/nologin apache
yum install gcc pcre-devel openssl-devel expat-devel
tar xvf apr-1.7.0.tar.bz2
tar xvf apr-util-1.6.1.tar.bz2
tar xf httpd-2.4.41.tar.gz
mv apr-1.7.0 httpd-2.4.41/srclib/apr
mv apr-util-1.6.1 httpd-2.4.41/srclib/apr-uti
cd httpd-2.4.41/
./configure --prefix=/app/httpd24 \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=prefork \
--with-included-apr
make -j 4 && make install
#配置PATH变量
vim /etc/profile.d/lamp.sh
PATH=/usr/local/mysql/bin/:/app/httpd24/bin:$PATH
. /etc/profile.d/lamp.sh
vim /app/httpd24/conf/httpd
#修改下面两行
user apache
group apache
apachectl start
#安装相关包,依赖EPEL源
yum install gcc libxml2-devel bzip2-devel libmcrypt-devel
#编译安装php
tar xvf php-7.3.10.tar.xz
cd php-7.3.10/
./configure \
--prefix=/app/php \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-openssl \
--with-pdo-mysql=mysqlnd \
--enable-mbstring \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--enable-sockets \
--with-apxs2=/app/httpd24/bin/apxs \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--enable-maintainer-zts \
--disable-fileinfo
make -j 4 && make install
#为php提供配置文件
cp php.ini-production /etc/php.ini
vim /etc/httpd24/conf/httpd.conf
#下面加二行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
#定位至DirectoryIndex index.html, 修改为
DirectoryIndex index.php index.html
apachectl restart
unzip wordpress-5.2.3-zh_CN.zip
mv wordpress /var/www/html
setfacl –R –m u:apache:rwx /var/www/html/wordpress/
#或者chown –R apache.apache /var/www/html/wordpress
#打开http://LAMP服务器IP/wordpress进行页面安装
两台主机:
软件版本:
mariadb-10.2.27-linux-x86_64.tar.gz 通用二进制格式
apr-1.7.0.tar.bz2
apr-util-1.6.1.tar.bz2
httpd-2.4.41.tar.gz
php-7.3.10.tar.bz2
wordpress-5.3-zh_CN.tar.gz
Discuz_X3.4_SC_UTF8【20190917】.zip
[root@mariadb data]#ll
total 449668
-rw-r--r-- 1 root root 460459738 Sep 12 09:08 mariadb-10.2.27-linux-x86_64.tar.gz
[root@websrv data]#ll
total 43980
-rw-r--r-- 1 root root 872238 May 14 2019 apr-1.7.0.tar.bz2
-rw-r--r-- 1 root root 428595 May 14 2019 apr-util-1.6.1.tar.bz2
-rw-r--r-- 1 root root 11800498 Dec 12 Discuz_X3.4_SC_UTF8【20191201】.zip
-rw-r--r-- 1 root root 9267917 Oct 8 15:10 httpd-2.4.41.tar.gz
-rw-r--r-- 1 root root 10232208 Dec 14 08:30 php-7.4.0.tar.xz
-rw-r--r-- 1 root root 12423575 Dec 12 14:18 wordpress-5.3-zh_CN.tar.gz
yum install libaio -y
useradd -r -s /sbin/nologin mysql
tar xvf mariadb-10.2.27-linux-x86_64.tar.gz -C /usr/local
cd /usr/local
ls -sv mariadb-10.2.27-linux-x86_64 mysql
cd mysql
chown -R root.root ./*
mkdir /data/mysql -p
chown -R mysql.mysql /data/mysql
mkdir /etc/mysql
cp support-files/my-huge.cnf /etc/mysql/my.cnf
vim /etc/mysql/my.cnf
[mysqld]
#加三行
datadir =/data/mysql
skip_name_resolve = ON
#准备PATH变量
vim /etc/profile.d/lamp.sh
PATH=/usr/local/mysql/bin/:$PATH
. /etc/profile.d/lamp.sh
cd /usr/local/mysql
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
cp support-files/mysql.server /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
service mysqld start
#为wordprss和discuz应用准备数据库和用户帐号
mysql -uroot
mysql> create database wordpress;
mysql> create database discuz;
mysql> grant all on wordpress.* to wpuser@'192.168.8.%' identified by "wppass";
mysql> grant all on discuz.* to discuz@'192.168.8.%' identified by 'dispass';
#安装相关包
yum install gcc pcre-devel openssl-devel expat-devel -y
#编译安装httpd
tar xvf apr-1.7.0.tar.bz2
tar xvf apr-util-1.6.1.tar.bz2
tar xf httpd-2.4.41.tar.gz
mv apr-1.7.0 httpd-2.4.41/srclib/apr
mv apr-util-1.6.1 httpd-2.4.41/srclib/apr-uti
cd httpd-2.4.41/
./configure \
--prefix=/app/httpd24 \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--with-included-apr \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=prefork
make && make install
#准备PATH变量
vim /etc/profile.d/lamp.sh
PATH=/app/httpd24/bin:$PATH
. /etc/profile.d/lamp.sh
#创建和配置用户和组
useradd -s /sbin/nologin -r -u 88 apache
vim /app/httpd24/conf/httpd.conf
user apapche
group apache
#修改为event模式
vim /app/httpd24/conf/httpd.conf
LoadModule mpm_event_module modules/mod_mpm_event.so
#LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
#LoadModule mpm_worker_module modules/mod_mpm_worker.so
httpd -M |grep mpm
mpm_event_module (sharepad)
apachectl start
#安装相关包,依赖EPEL源
#php 7.3 相关包
yum install gcc libxml2-devel bzip2-devel libmcrypt-devel
#php 7.4 相关包
yum install gcc libxml2-devel bzip2-devel libmcrypt-devel sqlite-devel oniguruma-devel
#编译安装php7.3
tar xvf php-7.3.10.tar.bz2
cd php-7.3.10
./configure --prefix=/app/php73 \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-openssl \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--enable-mbstring \
--enable-xml \
--enable-sockets \
--enable-fpm \
--enable-maintainer-zts \
--disable-fileinfo
#php7.4 编译
tar xvf php-7.4.0.tar.xz
cd php-7.4.0/
./configure \
--prefix=/app/php74 \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-openssl \
--with-zlib \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--enable-mbstring \
--enable-xml \
--enable-sockets \
--enable-fpm \
--enable-maintainer-zts \
--disable-fileinfo
make -j 4 && make install
[root@websrv php-7.3.12]#/app/php73/bin/php --version
PHP 7.3.12 (cli) (built: Dec 14 2019 10:20:40) ( ZTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.12, Copyright (c) 1998-2018 Zend Technologies
#准备PATH变量
vim /etc/profile.d/lamp.sh
PATH=i/app/httpd24/bin:$PATH
. /etc/profile.d/lamp.sh
#准备php配置文件和启动文件
cp php.ini-production /etc/php.ini
cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/
cd /app/php73/etc
cp php-fpm.conf.default php-fpm.conf
cd php-fpm.d/
cp www.conf.default www.conf
#修改进程所有者
vim www.conf
user apache
group apache
#支持status和ping页面
vim www.conf
pm.status_path = /status
ping.path = /ping
#支持opcache加速
mkdir /etc/php.d/
vim /etc/php.d/opcache.ini
[opcache]
zend_extension=opcache.so
opcache.enable=1
systemctl daemon-reload
systemctl status php-fpm.service
systemctl enable --now php-fpm.service
vim /app/httpd24/conf/httpd.conf
#取消下面两行的注释
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
#修改下面行
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
#加下面三行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
ProxyRequests Off
#实现两个虚拟主机:公用端口号
# wordpress.magedu.org
<virtualhost *:80>
servername wordpress.magedu.org
documentroot /data/wordpress
<directory /data/wordpress>
require all granted
</directory>
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/data/wordpress/$1
#实现status和ping页面
ProxyPassMatch ^/(status|ping)$ fcgi://127.0.0.1:9000/$1
CustomLog "logs/access_wordpress_log" common
</virtualhost>
#discuz.magedu.org
<virtualhost *:80>
servername discuz.magedu.org
documentroot /data/discuz
<directory /data/discuz/>
require all granted
</directory>
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/data/discuz/$1
CustomLog "logs/access_discuz_log" common
</virtualhost>
apachectl restart
#准备wordpress程序文件
mkdir /data/
tar xvf wordpress-5.3-zh_CN.tar.gz
mv wordpress/ /data
setfacl –R –m u:apache:rwx /data/wordpress/
#或者chown –R apache.apache /data/wordpress
#准备discuz!程序文件
unzip Discuz_X3.4_SC_UTF8【20190917】.zip
mkdir /data/discuz
mv upload/* /data/discuz
setfacl -R -m u:apache:rwx /data/discuz/
vim /etc/hosts
192.168.8.100 wordpress.magedu.org discuz.magedu.org
#php7.3修改/app/php/etc/php-fpm.d/www.conf
vim /app/php/etc/php-fpm.d/www.conf
;listen = 127.0.0.1:9000
listen = /run/php-fpm.sock #uds套接字文件
listen.owner = apache #uds套接字文件所有者
listen.group = apache #uds套接字文件所属组
listen.mode = 0660 #uds套接字文件权限
#注意php7.4修改/app/php/etc/php-fpm.d/www.conf
;listen = 127.0.0.1:9000
listen = /run/php-fpm.sock #uds套接字文件
listen.mode = 0666 #uds套接字文件权限 但是危险,所有成员都可以访问socket文件
systemctl restart php-fpm
ll /run/php-fpm.sock
srw-rw---- 1 apache apache 0 Dec 14 11:11 /run/php-fpm.sock
vim /app/httpd24/conf/httpd.conf
servername wordpress.magedu.org
documentroot /data/wordpress
require all granted
#ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/data/wordpress/$1
#ProxyPassMatch ^/(status|ping)$ fcgi://127.0.0.1:9000/$1
ProxyPassMatch ^/(.*\.php)$ "unix:/run/php-fpm.sock|fcgi://localhost/data/wordpress/"
ProxyPassMatch ^/(status|ping)$ "unix:/run/php-fpm.sock|fcgi://localhost/"
CustomLog "logs/access_wordpress_log" common
servername discuz.magedu.org
documentroot /data/discuz
require all granted
#ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/data/discuz/$1
#ProxyPassMatch ^/(status|ping)$ fcgi://127.0.0.1:9000/$1
ProxyPassMatch ^/(.*\.php)$ "unix:/run/php-fpm.sock|fcgi://localhost/data/discuz/"
ProxyPassMatch ^/(status|ping)$ "unix:/run/php-fpm.sock|fcgi://localhost/"
CustomLog "logs/access_wordpress_log" common
apachectl restart