LAPM 相关实验01

时间:2023-03-08 22:24:53

目录

lab1 静态、动态资源的区别
lab2 部署phpMyadmin
lab3 部署wordpress
lab4 编译安装php-Xcache加速器
lab5 fcgi实现lamp

lab1 静态、动态资源的区别
静态资源:原始形式与响应内容一致,在客户端浏览器执行
动态资源:原始形式通常为程序文件,需要在服务器端执行之后,将执行结果返回给客户端
1、首先来看看什么是静态页面
构建第一个静态页面
yum install httpd
cd /var/www/html #进入网站默认路径
vim index.html #构建一个静态页面
<h1>Hello World! Welcome to Beijing!</h1>
LAPM 相关实验01
LAPM 相关实验01
可以看到:
客户端看到的代码,和服务器端看到的代码,是一模一样,是为静态资源
构建第二个静态页面:变化中的静态页面
  vim test01.html
编写js代码,输出一个时间
<script type="text/javascript">
document.write(new Date());
</script>
 LAPM 相关实验01

LAPM 相关实验01

 LAPM 相关实验01
可看到源码和服务器端的一样
LAPM 相关实验01
2、来看看什么是动态资源?
服务器端看到的代码,和客户端看到的是不一致的
yum install php #安装httpd的php模块
vim test1.php #构建一个php文件
编写php代码
<?php
phpinfo();
?>
 LAPM 相关实验01
  systemctl restart httpd
LAPM 相关实验01
 LAPM 相关实验01
结论:
可以看到服务器端的php代码只有短短几行,而客户端看到的确实这么一大片。
为什么客户端看到不是服务器端写的代码,原因是服务端写的代码是个程序,需要在客户端执行,并将执行结果封装在html页面,显示在客户端。
 也就是说,原始形式通常为程序文件,需要在服务器端执行之后,将执行结果返回给客户端,所以看到的不相同,是为动态资源。
lab2、部署phpMyadmin
yum -y install httpd mariadb-server php php-mysql
systemctl start httpd
systemctl start mariadb
mysql_secure_installation
tar xvf phpMyAdmin-4.0.10.20-all-languages.tar.xz cd /var/www/html
cd phpadmin/
cp config.sample.inc.php config.inc.php
yum -y install php-mbstring
systemctl reload httpd
1)官网下载、解压到指定目录
注意phpMyAdmin软件的版本,要能够和当前系统中php、mysql版本兼容
先确认当前系统ohp、mysql的版本,然后下载版本兼容的phpMyAdmin
yum info php #确认当前php版本号
yum info mariadb #确认当前mysql版本号
 LAPM 相关实验01
#download compatible phpMyAdmin
rz #上传源码包 phpMyAdmin-4.0.10.20-all-languages.zip)
上传至服务器的源码包
LAPM 相关实验01
unzip phpMyAdmin-4.0.10.20-all-languages.zip -d /var/www/html
(必须解压到网站目录下)
LAPM 相关实验01

  

    mv phpMyAdmin-4.0.10.20-all-languages/ pma 改个简短的名

2)定制配置文件
LAPM 相关实验01
cp config.sample.inc.php config.inc.php #使用模板配置文件生成
vim config.inc.php
$cfg['blowfish_secret'] = 'sferxddf5'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */     
(#使用任意的随机的字符串,将默认的字符串改掉)
更改cookie验证
LAPM 相关实验01
     yum install php-mbstring #安装php-string模块
systemctl restart httpd #安装完新模块后需要重启apache服务
测试:
LAPM 相关实验01
3)设置mariadb用户口令,并简单测试
mysql_secure_installation #通过运行安全加固脚本设置root口令
mysql -uroot -pcentos #使用设置新的口令登录
MariaDB [(none)]> select user,host from mysql.user; #查看用户账户信息
#输入root账户、口令登录
 LAPM 相关实验01
先来熟悉下操作界面
来个删除用户的操作
LAPM 相关实验01
创建一个数据库,用以后边实验存放wordpress博客数据
LAPM 相关实验01
创建一个wordpress管理账号,使其对wordpress数据库具有完全控制权限
 LAPM 相关实验01

LAPM 相关实验01

 LAPM 相关实验01
尝鲜至此完成
lab3、部署wordpress
1)官网下载、解压到指定目录
LAPM 相关实验01
上传至服务器,解压到指定目录
LAPM 相关实验01
tar xvf wordpress-4.9.4-zh_CN.tar.gz -C /var/www/html/ #解压到网站子文件夹存放博客
2)定制配置文件
 LAPM 相关实验01
cp wp-config-sample.php wp-config.php #使用模板配置文件生成
vim wp-config.php #定制配置文件,将上个实验中为它创建的数据库、账户信息写入

/** WordPress数据库的名称 */

define('DB_NAME', 'wordpressdb');

/** MySQL数据库用户名 */

define('DB_USER', 'wpadmin');

/** MySQL数据库密码 */

define('DB_PASSWORD', 'centos');

/** MySQL主机 */

define('DB_HOST', '192.168.142.139');

LAPM 相关实验01

LAPM 相关实验01

安装WordPress

 LAPM 相关实验01
登录到博客管理后台
LAPM 相关实验01
登录管理后台
 LAPM 相关实验01
 LAPM 相关实验01

客户端测试
http://192.168.142.139/wordpress/

LAPM 相关实验01

好了,开始第一篇博客写作吧。


lab 4 编译安装php-Xcache加速器
 
1)测试
ab -c 10 -n 100 http://192.168.142.139/wordpress/
Requests per second: 5.60 [#/sec] (mean)
2)编译安装:官网下载源码、上传至服务器
 LAPM 相关实验01
tar xvf xcache-3.2.0.tar.gz 
cd xcache-3.2.0/
yum groupinstall "development tools"   #安装开发包组
3)定制配置文件
默认没有生产conf文件,
LAPM 相关实验01

LAPM 相关实验01

生成conf配置文件
yum -y install php-devel #
phpize #生成编译环境

LAPM 相关实验01

./configure --enable-xcache --with-php-config=/usr/bin/php-config
make -j 4 && make install
至此,编译结束
4)测试
ab -c 10 -n 100 http://192.168.142.139/wordpress/
Requests per second: 10.55 [#/sec] (mean)
 

lab5、fcgi实现lamp
简单集中部署方式
1、安装包
yum install httpd php-fpm php-mysql mariadb-server
systemctl start php-fpm
ss -ntl (9000)
2、定制配置文件
vim /etc/httpd/conf.d/fcgi.conf #没有这个文件,因此需要新创建一个
DirectoryIndex index.php
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/html/$1
 LAPM 相关实验01
systemctl restart httpd mariadb
至此,fcgi就可以工作了,完整的lamp配置已经实现,接下来进行测试:
3、测试集中部署式的lamp
cd /var/www/html
vim index.php #编写一个php测试页面文件
# 先测试下数据库连接性,使用pdo测试代码测试
LAPM 相关实验01

LAPM 相关实验01


下篇 独立模式方式(未完待续)

LAPM 相关实验01