Http协议 解决http协议无状态方法 cookie 客户端存放 session 服务端存放 http事务:一次访问的过程 请求:request 响应:response 在200主机上: [root@centos7 ~]#yum install httpd [root@centos7 ~]#cd /var/www/html [root@centos7 html]#echo 'welcome to magedu' > index.html [root@centos7 html]#systemctl restart httpd

[root@centos7 conf.d]#curl -v 192.168.141.200   这是请求报文的头部
* About to connect() to 192.168.141.200 port 80 (#0)
*   Trying 192.168.141.200...
* Connected to 192.168.141.200 (192.168.141.200) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: 192.168.141.200
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Sun, 03 Mar 2019 03:03:39 GMT
< Server: Apache/2.4.6 (CentOS)
< Last-Modified: Sun, 03 Mar 2019 02:45:40 GMT
< ETag: "1b-58327a2b2bd1e"
< Accept-Ranges: bytes
< Content-Length: 27
< Content-Type: text/html; charset=UTF-8
welcome to magedu
* Connection #0 to host 192.168.141.200 left intact
http协议常用的状态码
200: 成功,请求数据通过响应报文的entity-body部分发送;OK
301: 请求的URL指向的资源已经被删除;但在响应报文中通过首部Location指明了资源现在所处的新位置;Moved Permanently
302: 响应报文Location指明资源临时新位置 Moved Temporarily
304: 客户端发出了条件式请求,但服务器上的资源未曾发生改变,则通过响应此响应状态码通知客户端;Not Modified
401: 需要输入账号和密码认证方能访问资源;Unauthorized
403: 请求被禁止;Forbidden  404: 服务器无法找到客户端请求的资源;Not Found
500: 服务器内部错误;Internal Server Error
502: 代理服务器从后端服务器收到了一条伪响应,如无法连接到网关;Bad Gateway
503: 服务不可用,临时服务器维护或过载,服务器无法处理请求    504: 网关
Web相关工具 links URL    --dump        --source
wget [option]... [URL]...    -q 静默模式    -c 断点续传      -P /path 保存在指定目录   
-O filename 保存为指定文件名,filename 为 – 时,发送至标准输出         --limit-rate= 指定传输速率,单位K,M等
[root@centos7 html]#curl wttr.in
Weather report: Beijing, China
                                                       ┌─────────────┐                                                       
┌──────────────────────────────┬───────────────────────┤  Sun 03 Mar ├───────────────────────┬──────────────────────────────┐
│            Morning           │             Noon      └──────┬──────┘     Evening           │             Night            │
├──────────────────────────────┼──────────────────────────────┼──────────────────────────────┼──────────────────────────────┤
│    \  /       Partly cloudy  │    \  /       Partly cloudy  │    \  /       Partly cloudy  │    \  /       Partly cloudy  │
│  _ /"".-.     9..10 °C       │  _ /"".-.     13..14 °C      │  _ /"".-.     17 °C          │  _ /"".-.     14 °C          │
│    \_(   ).   ↙ 2 km/h       │    \_(   ).   ↖ 5 km/h       │    \_(   ).   ↑ 8-9 km/h     │    \_(   ).   ↗ 5-6 km/h     │
│    /(___(__)  20 km          │    /(___(__)  20 km          │    /(___(__)  20 km          │    /(___(__)  20 km          │
│               0.0 mm | 0%    │               0.0 mm | 0%    │               0.0 mm | 0%    │               0.0 mm | 0%    │
└──────────────────────────────┴──────────────────────────────┴──────────────────────────────┴──────────────────────────────┘
                                                       ┌─────────────┐                                                       
┌──────────────────────────────┬───────────────────────┤  Mon 04 Mar ├───────────────────────┬──────────────────────────────┐
│            Morning           │             Noon      └──────┬──────┘     Evening           │             Night            │
├──────────────────────────────┼──────────────────────────────┼──────────────────────────────┼──────────────────────────────┤
│    \  /       Partly cloudy  │    \  /       Partly cloudy  │    \  /       Partly cloudy  │               Cloudy         │
│  _ /"".-.     10 °C          │  _ /"".-.     15 °C          │  _ /"".-.     16 °C          │      .--.     13..14 °C      │
│    \_(   ).   ↗ 6-8 km/h     │    \_(   ).   ↙ 6-8 km/h     │    \_(   ).   ← 5-6 km/h     │   .-(    ).   ↙ 4-6 km/h     │
│    /(___(__)  20 km          │    /(___(__)  20 km          │    /(___(__)  20 km          │  (___.__)__)  19 km          │
│               0.0 mm | 0%    │               0.0 mm | 0%    │               0.0 mm | 0%    │               0.0 mm | 0%    │
└──────────────────────────────┴──────────────────────────────┴──────────────────────────────┴──────────────────────────────┘

[root@centos7 html]#curl 192.168.141.200 welcome to magedu [root@centos7 ~]#tail -f /var/log/httpd/access_log 192.168.141.150 - - [03/Mar/2019:12:00:28 +0800] "GET /hello.sh HTTP/1.1" 200 22 "-" "Wget/1.14 (linux-gnu)" [root@centos7 html]#curl -e "http://www.baidu.com" 192.168.141.200 welcome to magedu [root@centos7 ~]#tail -f /var/log/httpd/access_log 192.168.141.150 - - [03/Mar/2019:12:00:28 +0800] "GET /hello.sh HTTP/1.1" 200 22 "-" "Wget/1.14 (linux-gnu)" 192.168.141.200 - - [03/Mar/2019:12:17:45 +0800] "GET / HTTP/1.1" 200 27 "http://www.baidu.com" "curl/7.29. httpd的压力测试工具 ab, webbench, http_load, seige Jmeter 开源 Loadrunner 商业,有相关认证 tcpcopy:网易,复制生产环境中的真实请求,并将之保存 ab [OPTIONS] URL

实验:编译安装httpd-2.4.38

1、下载源码并解压缩 [root@centos7 data]#wget http://mirrors.shu.edu.cn/apache//httpd/httpd-2.4.38.tar.bz2 --2019-03-03 12:45:15-- http://mirrors.shu.edu.cn/apache//httpd/httpd-2.4.38.tar.bz2 Resolving mirrors.shu.edu.cn (mirrors.shu.edu.cn)... 202.121.199.235 Connecting to mirrors.shu.edu.cn (mirrors.shu.edu.cn)|202.121.199.235|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 7035030 (6.7M) [application/x-bzip2] Saving to: ‘httpd-2.4.38.tar.bz2’

100%[====================================================================================>] 7,035,030 6.38MB/s in 1.1s

2019-03-03 12:45:16 (6.38 MB/s) - ‘httpd-2.4.38.tar.bz2’ saved [7035030/7035030] [root@centos7 data]#wget http://mirror.bit.edu.cn/apache//apr/apr-1.6.5.tar.bz2 --2019-03-03 12:47:04-- http://mirror.bit.edu.cn/apache//apr/apr-1.6.5.tar.bz2 Resolving mirror.bit.edu.cn (mirror.bit.edu.cn)... 114.247.56.117 Connecting to mirror.bit.edu.cn (mirror.bit.edu.cn)|114.247.56.117|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 855393 (835K) [application/octet-stream] Saving to: ‘apr-1.6.5.tar.bz2’

100%[====================================================================================>] 855,393 --.-K/s in 0.1s

2019-03-03 12:47:04 (6.43 MB/s) - ‘apr-1.6.5.tar.bz2’ saved [855393/855393] [root@centos7 data]#wget http://mirror.bit.edu.cn/apache//apr/apr-util-1.6.1.tar.bz2 --2019-03-03 12:48:00-- http://mirror.bit.edu.cn/apache//apr/apr-util-1.6.1.tar.bz2 Resolving mirror.bit.edu.cn (mirror.bit.edu.cn)... 114.247.56.117 Connecting to mirror.bit.edu.cn (mirror.bit.edu.cn)|114.247.56.117|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 428595 (419K) [application/octet-stream] Saving to: ‘apr-util-1.6.1.tar.bz2’

100%[====================================================================================>] 428,595 --.-K/s in 0.1s
2019-03-03 12:48:00 (3.48 MB/s) - ‘apr-util-1.6.1.tar.bz2’ saved [428595/428595] tar xvf apr-1.6.5.tar.bz2 tar xvf apr-util-1.6.1.tar.bz2 tar xvf httpd-2.4.38.tar.bz2 [root@centos7 data]#ls apr-1.6.5.tar.bz2 apr-util-1.6.1.tar.bz2 httpd-2.4.38.tar.bz2 [root@centos7 data]#ls apr-1.6.5 apr-1.6.5.tar.bz2 apr-util-1.6.1 apr-util-1.6.1.tar.bz2 httpd-2.4.38 httpd-2.4.38.tar.bz2 2、 将三个源码合并 [root@centos7 data]#mv apr-1.6.5 httpd-2.4.38/srclib/apr [root@centos7 data]#mv apr-util-1.6.1 httpd-2.4.38/srclib/apr-util [root@centos7 data]#ls httpd-2.4.38/srclib/
apr apr-util Makefile.in 3、 安装相关包 yum install gcc gcc-c++ glibc glibc-devel pcre-devel openssl-devel expat-devel 4、编译安装[root@centos7 httpd-2.4.38]#1、 cd httpd-2.4.38/ ./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 2、make && make install configure: summary of build options: Server Version: 2.4.38 Install prefix: /app/httpd24 C compiler: gcc -std=gnu99 CFLAGS: -g -O2 -pthread
CPPFLAGS: -DLINUX -D_REENTRANT -D_GNU_SOURCE
LDFLAGS:
LIBS:
C preprocessor: gcc -E 此时,为了避免冲突,我们把本机yum安装的httpd卸载,不然都走80端口会冲突。 [root@centos7 httpd-2.4.38]#cd /app/ [root@centos7 app]#ls httpd24 [root@centos7 app]#cd httpd24/ [root@centos7 httpd24]#ls bin build cgi-bin conf error htdocs icons include lib logs man manual modules [root@centos7 httpd24]#ls bin/ ab apr-1-config apxs dbmmanage envvars-std htcacheclean htdigest httpd:主配置文件 logresolve apachectl:系统启动文件 apu-1-config checkgid envvars fcgistarter htdbm htpasswd httxt2dbm rotatelogs 5、[root@centos7 httpd24]#vim /etc/profile.d/env.sh 将变量写入文件 PS1="[\e[1;32m][\u@\h \W]\$[\e[0m]" PATH=/app/httpd24/bin:$PATH
[root@centos7 httpd24]#. /etc/profile.d/env.sh [root@centos7 httpd24]#echo $PATH /app/httpd24/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

6、尝试启动:[root@centos7 httpd24]#apachectl AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using centos7.localdomain. Set the 'ServerName' directive globally to suppress this message [root@centos7 ~]#ss -ntl State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 :::80 :::*

7、因为配置已经写入文件中 [root@centos7 ~]#cd /app/httpd24/htdocs/ [root@centos7 htdocs]#ls index.html [root@centos7 htdocs]#cat index.html <html><body>It works!</body></html> 8、此时在进程中显示是demon服务,我们要把它改为Apache服务:修改文件 [root@centos7 httpd24]#ls bin build cgi-bin conf error htdocs icons include lib logs man manual modules [root@centos7 httpd24]#cd conf [root@centos7 conf]#ls extra httpd.conf magic mime.types original [root@centos7 conf]#vim httpd.conf User apache
Group apache
[root@centos7 conf]#apachectl restart [root@centos7 conf]#ps aux apache 58161 0.0 0.1 101620 1924 ? S 14:33 0:00 /app/httpd24/bin/httpd apache 58162 0.0 0.1 101620 1924 ? S 14:33 0:00 /app/httpd24/bin/httpd apache 58163 0.0 0.1 101620 1924 ? S 14:33 0:00 /app/httpd24/bin/httpd apache 58164 0.0 0.1 101620 1924 ? S 14:33 0:00 /app/httpd24/bin/httpd apache 58165 0.0 0.1 101620 1924 ? S 14:33 0:00 /app/httpd24/bin/httpd 9、[root@centos7 conf]#cd /etc/init.d/ [root@centos7 init.d]#ls functions netconsole network README [root@centos7 init.d]#vim /etc/rc.local /app/httpd24/bin/apachectl
[root@centos7 init.d]#ll /etc/rc.d/rc.local -rw-r--r--. 1 root root 500 Mar 3 14:37 /etc/rc.d/rc.local [root@centos7 init.d]#chmod +x /etc/rc.d/rc.local [root@centos7 init.d]#reboot [root@centos7 ~]#ss -ntl State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 :::80 :::*

实验:编译实现基于FASTCGI的LAMP的wordpress

准备环境,两台主机,100做httpd+php,150做mariadb 1、将安装包rz到主机:[root@100 ~]#ls httpd-2.4.37.tar.bz2 apr-1.6.5.tar.bz2 mariadb-10.2.15-linux-x86_64.tar.gz apr-util-1.6.1.tar.bz2 php-7.3.2.tar.xz wordpress-5.0-zh_CN.zip [root@100 ~]#tar xf apr-1.6.5.tar.bz2 [root@100 ~]#tar xf httpd-2.4.37.tar.bz2 [root@100 ~]#tar xf php-7.3.2.tar.xz [root@100 ~]#tar xf apr-util-1.6.1.tar.bz2 2、100主机上:mv apr-1.6.5 httpd-2.4.37/srclib/apr mv apr-util-1.6.1 httpd-2.4.37/srclib/apr-util 3、一、cd httpd-2.4.37/ 二、yum install gcc glibc pcre-devel openssl-devel expat-devel libxml2-devel bzip2-devel libmcrypt-devel 三、./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 4、[root@100 httpd-2.4.37]#echo 'PATH=/app/httpd24/bin:$PATH' > /etc/profile.d/lamp.sh [root@100 httpd-2.4.37]#. /etc/profile.d/lamp.sh 5、useradd -r -s /sbin/nologin apache [root@centos7 httpd-2.4.37]#vim /app/httpd24/conf/httpd.conf 此项修改不是必须,主要为了方便查看 User apache Group apache 6、[root@100 httpd-2.4.37]#apachectl AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 0.0.0.100. Set the 'ServerName' directive globally to suppress this message [root@100 httpd-2.4.37]#ss -ntl State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 :::80 :::*
7、现在我们去centos6上测试:[root@centos6 ~]#curl 192.168.141.100 <html><body>It works!</body></html> 此时说明Apache已经安装成功。 8、150主机上:tar xvf mariadb-10.2.15-linux-x86_64.tar.gz -C /usr/local/ [root@centos7 ~]#cd /usr/local [root@centos7 local]#ls bin games lib libexec sbin src etc include lib64 mariadb-10.2.15-linux-x86_64 share [root@centos7 local]#ln -s mariadb-10.2.15-linux-x86_64/ mysql [root@centos7 local]#chown -R root.root /usr/local/mysql/ [root@centos7 local]#ls bin games lib libexec mysql share etc include lib64 mariadb-10.2.15-linux-x86_64 sbin src [root@centos7 local]#cd mysql/ [root@centos7 mysql]#ls bin data lib README-wsrep support-files COPYING EXCEPTIONS-CLIENT man scripts COPYING.thirdparty include mysql-test share CREDITS INSTALL-BINARY README.md sql-bench [root@centos7 mysql]#mkdir /etc/mysql/ [root@centos7 mysql]#cp support-files/my-huge.cnf /etc/mysql/my.cnf 9、[root@centos7 mysql]#vim /etc/mysql/my.cnf [mysqld] datadir=/data/mysql port = 3306 socket = /tmp/mysql.sock skip-external-locking key_buffer_size = 384M max_allowed_packet = 1M table_open_cache = 512 sort_buffer_size = 2M read_buffer_size = 2M read_rnd_buffer_size = 8M myisam_sort_buffer_size = 64M thread_cache_size = 8 query_cache_size = 32M 10、[root@centos7 mysql]#chown mysql.mysql /data/mysql [root@centos7 mysql]#ll /data/mysql total 0 [root@centos7 mysql]#ls bin data lib README-wsrep support-files COPYING EXCEPTIONS-CLIENT man scripts COPYING.thirdparty include mysql-test share CREDITS INSTALL-BINARY README.md sql-bench [root@centos7 mysql]#scripts/mysql_install_db --datadir=/data/mysql --user=mysql Installing MariaDB/MySQL system tables in '/data/mysql' ... 2019-03-04 17:09:17 140578725427008 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release. 2019-03-04 17:09:17 140578724841216 [Warning] Failed to load slave replication state from table mysql.gtid_slave_pos: 1146: Table 'mysql.gtid_slave_pos' doesn't exist OK To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER ! To do so, start the server, then issue the following commands: './bin/mysqladmin' -u root password 'new-password' './bin/mysqladmin' -u root -h centos7.localdomain password 'new-password' Alternatively you can run: './bin/mysql_secure_installation' which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the MariaDB Knowledgebase at http://mariadb.com/kb or the MySQL manual for more instructions. You can start the MariaDB daemon with: cd '.' ; ./bin/mysqld_safe --datadir='/data/mysql' You can test the MariaDB daemon with mysql-test-run.pl cd './mysql-test' ; perl mysql-test-run.pl Please report any problems at http://mariadb.org/jira The latest information about MariaDB is available at http://mariadb.org/. You can find additional information about the MySQL part at: http://dev.mysql.com Consider joining MariaDB's strong and vibrant community: https://mariadb.org/get-involved/ [root@centos7 mysql]#ls -l /data/mysql/ total 110660 -rw-rw----. 1 mysql mysql 16384 Mar 4 17:09 aria_log.00000001 -rw-rw----. 1 mysql mysql 52 Mar 4 17:09 aria_log_control -rw-rw----. 1 mysql mysql 938 Mar 4 17:09 ib_buffer_pool -rw-rw----. 1 mysql mysql 12582912 Mar 4 17:09 ibdata1 -rw-rw----. 1 mysql mysql 50331648 Mar 4 17:09 ib_logfile0 -rw-rw----. 1 mysql mysql 50331648 Mar 4 17:09 ib_logfile1 drwx------. 2 mysql root 4096 Mar 4 17:09 mysql -rw-rw----. 1 mysql mysql 29009 Mar 4 17:09 mysql-bin.000001 -rw-rw----. 1 mysql mysql 19 Mar 4 17:09 mysql-bin.index -rw-rw----. 1 mysql mysql 7 Mar 4 17:09 mysql-bin.state drwx------. 2 mysql mysql 20 Mar 4 17:09 performance_schema drwx------. 2 mysql root 6 Mar 4 17:09 test 11、[root@centos7 mysql]#cp support-files/mysql.server /etc/init.d/mysqld [root@centos7 mysql]#ll /etc/init.d/mysqld -rwxr-xr-x. 1 root root 12273 Mar 4 17:12 /etc/init.d/mysqld [root@centos7 mysql]#chkconfig --add mysqld ch[root@centos7 mysql]#chkconfig --list

Note: This output shows SysV services only and does not include native systemd services. SysV configuration data might be overridden by native systemd configuration.

  If you want to list systemd services use 'systemctl list-unit-files'.
  To see services enabled on particular target use
  'systemctl list-dependencies [target]'.

mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off 三个文件已正常可使用 netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off network 0:off 1:off 2:on 3:on 4:on 5:on 6:off [root@centos7 mysql]#service mysqld start Starting mysqld (via systemctl): [ OK ] 12、[root@centos7 mysql]#echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh [root@centos7 mysql]#. /etc/profile.d/mysql.sh [root@centos7 mysql]#mysql Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 10 Server version: 10.2.15-MariaDB-log MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database wpdb; Query OK, 1 row affected (0.01 sec)

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

MariaDB [(none)]> quit

13、[root@centos7 data]#unzip wordpress-5.0-zh_CN.zip [root@centos7 data]#ls mysql php-7.3.2 wordpress wordpress-5.0-zh_CN.zip [root@centos7 data]#cp -R wordpress /app/httpd24/htdocs/ [root@centos7 data]#cd wordpress/ [root@centos7 wordpress]#ls index.php wp-blog-header.php wp-includes wp-settings.php license.txt wp-comments-post.php wp-links-opml.php wp-signup.php readme.html wp-config-sample.php wp-load.php wp-trackback.php wp-activate.php wp-content wp-login.php xmlrpc.php wp-admin wp-cron.php wp-mail.php [root@centos7 wordpress]#cp wp-config-sample.php wp-config.php [root@centos7 wordpress]#vim wp-config.php // ** MySQL 设置 - 具体信息来自您正在使用的主机 ** // /** WordPress数据库的名称 */ define('DB_NAME', 'wpdb');

/** MySQL数据库用户名 */ define('DB_USER', 'wpuser');

/** MySQL数据库密码 */ define('DB_PASSWORD', '123gxy');

/** MySQL主机 / define('DB_HOST', '192.168.141.150'); 14、[root@centos7 ~]#vim /app/httpd24/conf/httpd.conf 把该文件下的2行取消注释,激活 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> <IfModule ssl_module> SSLRandomSeed startup builtin SSLRandomSeed connect builtin </IfModule> AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps ProxyRequests Off ProxyPassMatch ^/(..php)$ fcgi://127.0.0.1:9000/app/httpd24/htdocs/$1 这四行加入 [root@centos7 htdocs]#apachectl restart

15、我们配置php[root@centos7 wordpress]#cd /data/php-7.3.2/ [root@centos7 php-7.3.2]#cp php.ini-production /etc/php.ini [root@centos7 php-7.3.2]#chmod +x /etc/init.d/php-fpm [root@centos7 php-7.3.2]#chkconfig --add php-fpm [root@centos7 php-7.3.2]#chkconfig --list Note: This output shows SysV services only and does not include native systemd services. SysV configuration data might be overridden by native systemd configuration.

  If you want to list systemd services use 'systemctl list-unit-files'.
  To see services enabled on particular target use
  'systemctl list-dependencies [target]'.

mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off network 0:off 1:off 2:on 3:on 4:on 5:on 6:off php-fpm 0:off 1:off 2:on 3:on 4:on 5:on 6:off 16、[root@centos7 php-7.3.2]#ls /app/php/ bin etc include lib php sbin var 这是编译好的文件 [root@centos7 php-7.3.2]#cd /app/php/etc [root@centos7 etc]#ls pear.conf php-fpm.conf.default php-fpm.d [root@centos7 etc]#cp php-fpm.conf.default php-fpm.conf [root@centos7 etc]#cp php-fpm.d/www.conf.default php-fpm.d/www.conf 启动服务:[root@centos7 etc]#service php-fpm start Starting php-fpm done [root@centos7 etc]#ss -ntl State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 127.0.0.1:9000 :
现在我们去访问页面:

实验:编译实现基于FASTCGI的LAMP的wordpress

基于模块方式安装使用php 1、yum install php [root@centos7 ~]#cd /var/www/html [root@centos7 html]#ls admin a.txt hello.sh index.html setcookie.php test.html [root@centos7 html]#vim index.php <?php echo date("Y/m/d H:i:s"); phpinfo(); ?> 下图为动态页面: [root@centos7 html]#yum install php-mysql 要连数据库就要下载该包 3、yum install mariadb-server [root@centos7 html]#systemctl restart mariadb 4、[root@centos7 html]#mysql_secure_installation 安全加固脚本 5、[root@centos7 html]#vim mysql.php <?php try { $user='root'; $pass='123gxy'; $dbh= new PDO('mysql:host=localhost;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() . "<br/>"; die(); } ?> [root@centos7 html]#systemctl restart mariadb 6、[root@centos7 ~]#mysql -uroot -p123gxy MariaDB [(none)]> select user,host from mysql.user; +------+-----------+ | user | host | +------+-----------+ | root | 127.0.0.1 | | root | ::1 | | root | localhost | +------+-----------+ 3 rows in set (0.00 sec) 此时这个实验就做完了。

实验:php使用PDO扩展连接数据库

将压缩包传到主机并压缩: tar xvf phpMyAdmin-4.0.10.20-all-languages.tar.xz [root@centos7 ~]#cd phpMyAdmin-4.0.10.20-all-languages [root@centos7 phpMyAdmin-4.0.10.20-all-languages]#pwd /root/phpMyAdmin-4.0.10.20-all-languages [root@centos7 phpMyAdmin-4.0.10.20-all-languages]#cd .. [root@centos7 ~]#ls ! hellodb_innodb.sql phpMyAdmin-4.0.10.20-all-languages anaconda-ks.cfg initial-setup-ks.cfg phpMyAdmin-4.0.10.20-all-languages.tar.xz [root@centos7 ~]#mv phpMyAdmin-4.0.10.20-all-languages /var/www/html/pma [root@centos7 ~]#cd /var/www/html/pma [root@centos7 pma]#yum install php-mbstring 安装这个辅助工具 [root@centos7 pma]#cp config.sample.inc.php config.inc.php [root@centos7 pma]#vim config.inc.php 此项是修改默认密码,基于安全。 $cfg['blowfish_secret'] = '123gxy'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
[root@centos7 pma]#systemctl restart httpd 登陆用户及密码即可进入图形化界面: 这时我们已经创建了用户如下: [root@centos7 ~]#mysql -uwpuser -p123gxy -h192.168.141.200. MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | wordpress |该用户已经被创建成功。 +--------------------+ 2 rows in set (0.00 sec) 该实验完成。在网站上访问及在mysql数据库查询结果一致。

实验:部署wordpress

将下载的软件包传到主机并解压 tar xvf wordpress-5.0.3-zh_CN.tar.gz [root@centos7 ~]#cd wordpress/ [root@centos7 wordpress]#ls index.php wp-activate.php wp-comments-post.php wp-cron.php wp-load.php wp-settings.php xmlrpc.php license.txt wp-admin wp-config-sample.php wp-includes wp-login.php wp-signup.php readme.html wp-blog-header.php wp-content wp-links-opml.php wp-mail.php wp-trackback.php [root@centos7 wordpress]#cp wp-config-sample.php wp-config.php [root@centos7 wordpress]#vim wp-config.php /** WordPress数据库的名称 */ define('DB_NAME', 'wordpress');

/** MySQL数据库用户名 */ define('DB_USER', 'wpuser');

/** MySQL数据库密码 */ define('DB_PASSWORD', '123gxy');

/** MySQL主机 */ define('DB_HOST', '192.168.141.200'); [root@centos7 ~]#mv wordpress /var/www/html/ [root@centos7 ~]#cd /var/www/html/ [root@centos7 html]#ls admin pma setcookie.php wordpress 下面我们去网站登录: 成功登陆后的后台页面:我们就可以自建博客了:

实验:源码编译php.fpm

1、[root@centos7 ~]#ls httpd-2.4.37.tar.bz2 apr-util-1.6.1.tar.bz2 apr-1.6.5.tar.bz2 [root@centos7 ~]#mv httpd-2.4.38.tar.bz2 apr-* /data/ [root@centos7 ~]#cd /data/ [root@centos7 data]#ls apr-1.6.5.tar.bz2 apr-util-1.6.1.tar.bz2 httpd-2.4.38.tar.bz2 tar xvf xxxx 将其三个包解压: root@centos7 data]#ls apr-1.6.5 apr-util-1.6.1 httpd-2.4.38 apr-1.6.5.tar.bz2 apr-util-1.6.1.tar.bz2 httpd-2.4.38.tar.bz2 [root@centos7 data]#mv apr-1.6.5 httpd-2.4.38/srclib/apr [root@centos7 data]#mv apr-util-1.6.1 httpd-2.4.38/srclib/apr-util 2、[root@centos7 httpd-2.4.38]#1、yum install gcc glibc pcre-devel openssl-devel expat-devel 安装必要包 [root@centos7 httpd-2.4.38]#./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 2、[root@centos7 data]#make && make install 3、[root@centos7 httpd-2.4.38]#cd /app/httpd24/ [root@centos7 httpd24]#ls bin build cgi-bin conf error htdocs icons include lib logs man manual modules [root@centos7 httpd24]#cd bin [root@centos7 bin]#ls ab apu-1-config dbmmanage fcgistarter htdigest httxt2dbm apachectl apxs envvars htcacheclean htpasswd logresolve apr-1-config checkgid envvars-std htdbm httpd rotatelogs [root@centos7 bin]#./apachectl start 开启服务 AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using centos7.localdomain. Set the 'ServerName' directive globally to suppress this message httpd (pid 6865) already running [root@centos7 bin]#ss -ntl State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 :::80 :::*
4、现在去另一主机上curl一下:[root@centos7 ~]#curl 192.168.141.200 <html><body>It works!</body></html> 5、 yum install php-fpm php-mysql mariadb-server 安装必要的包 6、一、[root@centos7 bin]#vim /app/httpd24/conf/httpd.conf LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so 这2项取消注释,使之生效。

user apache Group apache

</IfModule> AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps ProxyRequests Off ProxyPassMatch "^/(..php(/.)?)$" "unix:/var/run/php-fpm.sock|fcgi://localhost/app/httpd24/htdocs/" 这是指定套接字的路径

二、[root@centos7 bin]# vim /etc/php-fpm.d/www.conf ;listen = 127.0.0.1:9000 listen=/var/run/php-fpm.sock

listen.mode = 0666

三、[root@centos7 bin]#ll /var/run/ srw-rw-rw-. 1 root root 0 Mar 5 21:50 php-fpm.sock 权限是066

四、root@centos7 bin]#cd /app/httpd24/htdocs/ [root@centos7 htdocs]#ls index.html [root@centos7 htdocs]#vim index.php <?php phpinfo(); ?>
7、[root@centos7 bin]#./apachectl start

8、现在我们去访问网页: