企业中网站架构

LNMP:Linux  Nginx  MySQL  PHP 
LAMP:Linux Apache MySQL PHP
LNMT:Linux Nginx MySQL Tomcat
LAMT:Linux Apache MySQL Tomcat

Nginx
Apache
运行:html css js

nginx
php

部署PHP

# 1.卸载Linux自带的旧版本php
[root@web01 ~]# yum remove php-mysql-5.4 php php-fpm php-common

# 2.添加php第三方源
[root@nginx ~]# vim /etc/yum.repos.d/php.repo
[php-webtatic]
name = PHP Repository
baseurl = http://us-east.repo.webtatic.com/yum/el7/x86_64/
gpgcheck = 0

# 3.安装php
[root@web01 ~]# yum -y install php71w php71w-cli php71w-common php71w-devel php71w- embedded php71w-gd php71w-mcrypt php71w-mbstring php71w-pdo php71w-xml php71w-fpm php71w-mysqlnd php71w-opcache php71w-pecl-memcached php71w-pecl-redis php71w-pecl- mongodb

# 4.创建用户
[root@web01 ~]# groupadd www -g 666
[root@web01 ~]# useradd www -u 666 -g 666 -s /sbin/nologin -M

# 5.修改nginx运行用户
[root@web01 ~]# vim /etc/nginx/nginx.conf
user www;

php-fpm作用:用来管理php程序运行
## php相关配置文件
/etc/php-fpm.conf # php管理进程配置文件
/etc/php.ini # php程序配置文件
/etc/php-fpm.d/www.conf # php管理进程的子配置文件

# 6.修改php的启动用户
[root@web01 ~]# vim /etc/php-fpm.d/www.conf
[www]
user = www
group = www

# 7.启动php并加入开机自启
[root@web01 ~]# systemctl start php-fpm
[root@web01 ~]# systemctl enable php-fpm

# 8.检查php进程和端口
[root@web01 ~]# ps -ef|grep php
root 856 1 0 15:17 ? 00:00:00 php-fpm: master process (/etc/php-fpm.conf)
www 893 856 0 15:17 ? 00:00:00 php-fpm: pool www
www 894 856 0 15:17 ? 00:00:00 php-fpm: pool www
www 895 856 0 15:17 ? 00:00:00 php-fpm: pool www
www 896 856 0 15:17 ? 00:00:00 php-fpm: pool www
www 897 856 0 15:17 ? 00:00:00 php-fpm: pool www
root 1167 1139 0 15:23 pts/0 00:00:00 grep --color=auto php

[root@web01 ~]# netstat -lntup|grep php
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 856/php-fpm: master

配置nginx连接php

[root@web01 movie]# vim /etc/nginx/conf.d/movie.conf

server{
listen 80;
server_name movie.yjt.com;

location /{
root /movie;
index index.php index.html;
}

location ~ \.php$ {
root /movie;
## nginx调用本机的9000端口(php-fpm程序)
fastcgi_pass 127.0.0.1:9000;
## 用php程序,解析哪个目录下的哪个.php的文件
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
## 包含php变量的文件
include /etc/nginx/fastcgi_params;

}
}
#授权
[root@web01 movie]# chown www.www /movie/
[root@web01 movie]# ll -ld
drwxr-xr-x 2 www www 102 Jun 7 15:26 .

## 去Windows改域名

 Nginx实现web架构_php

 Nginx实现web架构_nginx_02

部署wordpress

# 1.编辑nginx配置文件
[root@web01 conf.d]# vim /etc/nginx/conf.d/blog.yjt.com.conf
server{
listen 80;
server_name blog.yjt.com;
root /blog/wordpress;

location /{
index index.php index.html;
}

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;

}
}

# 2 重新加载nginx
[root@web01 conf.d]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

[root@web01 conf.d]# systemctl reload nginx

# 3.测试nginx连接php(编写php info代码)
[root@web01 conf.d]# vim /blog/info.php
<?php
phpinfo();
?>

# 4.创建站点目录并授权
[root@web01 ~]# mkdir /blog/wordpress
[root@web01 wordpress]# chown -R www.www /blog/wordpress/

# 5.windows域名解析
打开路径:C:\Windows\System32\drivers\etc 编辑hosts文件
10.0.0.7 blog.yjt.com

# 6.打开浏览器访问:http://blog.zls.com/info.php

 Nginx实现web架构_php_03

# 7.下载wordpress代码
wordpress官网:https://wordpress.org/
[root@web01 blog]# wget https://cn.wordpress.org/latest-zh_CN.tar.gz

 Nginx实现web架构_mysql_04

 Nginx实现web架构_mysql_05

# 8.解压代码
[root@web01 blog]# tar xf latest.tar.gz

# 9.修改nginx配置文件
[root@web01 blog]# vim /etc/nginx/conf.d/blog.yjt.com.conf
server{
listen 80;
server_name blog.yjt.com;
root /blog/wordpress;

location /{
index index.php index.html;
}

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;

}
}

# 10.重新加载nginx
[root@web01 blog]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

[root@web01 blog]# systemctl reload nginx

# 11.打开浏览器,访问:http://blog.yjt.com/

 Nginx实现web架构_php_06

 Nginx实现web架构_php_07

 Nginx实现web架构_mysql_08

安装数据库

## 数据库是C/S结构
## 默认端口:3306

# 1.安装mariadb
[root@web01 ~]# yum install -y mariadb-server

# 2.启动数据库并加入开机自启
[root@web01 ~]# systemctl start mariadb
[root@web01 ~]# systemctl enable mariadb

# 3.登录数据库
[root@web01 ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.68-MariaDB 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)]>


# 4.查看所有库
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)

# 5.切换数据库
MariaDB [(none)]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

# 6.查看该库中的所有表
MariaDB [mysql]> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| event |
| func |
| general_log |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| host |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| servers |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
24 rows in set (0.00 sec)


# 7.创建数据库
MariaDB [mysql]> create database 库名字;
MariaDB [mysql]> create database wordpress;
Query OK, 1 row affected (0.00 sec)

# 8.创建用户
MariaDB [(none)]> grant all on 所有库 . 所有表 to 用户名@'主机IP' identified by '密码';
MariaDB [(none)]> grant all on *.* to wp@'localhost' identified by '123';

# 9.查看用户
MariaDB [mysql]> select user,host from mysql.user;
+------+-----------+
| user | host |
+------+-----------+
| root | 127.0.0.1 |
| root | ::1 |
| | localhost |
| root | localhost |
| wp | localhost |
| | web01 |
| root | web01 |
+------+-----------+


# 10.退出数据库
MariaDB [(none)]> exit
MariaDB [(none)]> quit
MariaDB [(none)]> \q

数据库名字:wordpress
连接用户名:wp
连接密码:123
连接IP:localhost

# 11.测试php是否可以跟MySQL建立连接
[root@web01 ~]# vim /blog/pm.php
<?php
$servername = "localhost";
$username = "wp_user";
$password = "111";

// 创建连接
$conn = mysqli_connect($servername, $username, $password);

// 检测连接
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "小哥哥,php可以连接MySQL...";
?>

<img style='width:100%;height:100%;'
src=https://blog.driverzeng.com/zenglaoshi/php_mysql.png>

## 浏览器访问:http://blog.yjt.com/pm.php

 Nginx实现web架构_nginx_09

 Nginx实现web架构_mysql_10 Nginx实现web架构_nginx_11

## 鼠标样式代码

<script type="text/javascript">
/* 鼠标特效 */
$(function() {
var a_idx = 0,
b_idx = 0;
c_idx = 0;
jQuery(document).ready(function($) {
$("body").click(function(e) {
var a = new Array("苍井空", "武藤兰", "小泽玛利亚","泷泽萝拉", "波多野结衣", "吉泽 明步", "西野翔", "饭岛爱", "天海翼", "邱老师" ,"麻生希", "绫濑遥", "滨崎步", "黑木瞳", "由加 奈"),
b = new Array("#09ebfc", "#ff6651", "#ffb351", "#51ff65", "#5197ff", "#a551ff", "#ff51f7", "#ff518e", "#ff5163", "#efff51"),
c = new Array("12", "14", "16", "18", "20", "22", "24", "26", "28", "30");
var $i = $("<span/>").text(a[a_idx]);
a_idx = (a_idx + 1) % a.length;
b_idx = (b_idx + 1) % b.length;
c_idx = (c_idx + 1) % c.length;
var x = e.pageX,
y = e.pageY;
$i.css({
"z-index": 999,
"top": y - 20,
"left": x,
"position": "absolute",
"font-weight": "bold",
"font-size": c[c_idx] + "px",
"color": b[b_idx]
});
$("body").append($i);
$i.animate({
"top": y - 180,
"opacity": 0
}, 1500, function() {
$i.remove();
});
});
});
var _hmt = _hmt || [];
})
</script>


[root@web01 QQ2.8]# cd /blog/wordpress/wp-content/themes/QQ2.8
[root@web01 QQ2.8]# vim header.php

修改nginx上传

[root@web01 nginx]# vim /etc/php.ini

0M表示无限制大小

 Nginx实现web架构_php_12

[root@web01 nginx]# systemctl reload php-fpm.service 

[root@web01 ~]# vim /etc/nginx/nginx.conf

 Nginx实现web架构_mysql_13

[root@web01 nginx]# systemctl reload ngin

优化php

## 启动php服务时,创建php.sock安全套接字文件,该文件的属主和属组
listen = /opt/php.sock
listen.owner = www
listen.group = www

### 完整php配置文件
[www]
user = www
group = www
;listen = 0.0.0.0:9000 ### (在php配置文件中;是注释的意思)
listen = /opt/php.sock
listen.owner = www
listen.group = www
listen.allowed_clients = 127.0.0.1
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
php_value[soap.wsdl_cache_dir] = /var/lib/php/wsdlcache

# 7.配置nginx连接php
[root@web01 ~]# vim /etc/nginx/conf.d/blog.zls.com.conf
server{
listen 80;
server_name blog.yjt.com;
root /blog;
index index.php index.html;

location ~ \.php$ {
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/opt/php.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

wordpress更换域名排坑

 Nginx实现web架构_php_14

# 1.修改nginx配置文件域名
[root@web01 conf.d]# vim blog.yjt.com.conf
server{
listen 80;
server_name www.yjt.com;
root /blog/wordpress;
index index.php index.html;

location ~ \.php$ {
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/opt/php.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

# 2.重新加载nginx
[root@web01 conf.d]# systemctl reload nginx