LAMP架构配置命令与搭建论坛
LAMP介绍
LAMP架构是目前成熟的企业网站应用模式之一,指的是协同工作的一整套系统和相关软件,能够提供动态Web站点服务及其应用开发环境。LAMP是一个缩写词,具体包括Linux操作系统、Apache网站服务器、MySQL数据库服务器、PHP(或Perl、Python)网页编程语言。
各组件的主要作用
(平台)Linux:作为LAMP架构的基础,提供用于支撑Web站点的操作系统,能够与其他三个组件提供更好的稳定性,兼容性(AMP组件也支持Windows、UNIX等平台) 。
(前台)Apache:作为LAMP架构的前端,是一款功能强大,稳定性好的Web服务器程序,该服务器直接面向用户提供网站访问,发送网页,图片等文件内容。
(后台)MySQL:作为LAMP架构的后端,是一款流行的开源关系数据库系统。在企业网站、业务系统等应用中,各种账户信息、产品信息,客户资料、业务数据等都可以存储到MySQL数据库,其他程序可以通过SQL语句来查询,更改这些信息。
(中间连接)PHP/Perl/Python:作为三种开发动态网页的编程语言,负责解释动态网页文件,负责沟通Web服务器和数据库系统以协同工作,并提供Web应用程序的开发和运行环境。其中PHP是一种被广泛应用的开放源代码的多用途脚本语言,它可以嵌入到HTML中,尤其适合于Web应用开发。
编译安装Apache httpd服务
1.关闭防火墙
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# setenforce 0
2.配置本地yum源仓库
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# mount /dev/sr0 /mnt
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost yum.repos.d]# mkdir repos.bak
[root@localhost yum.repos.d]# mv *.repo repos.bak
[root@localhost yum.repos.d]# cd repos.bak/
[root@localhost repos.bak]# ls
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo
[root@localhost repos.bak]# cd -
/etc/yum.repos.d
[root@localhost yum.repos.d]# vim local.repo
[local]
name=local
baseurl=file:///mnt
enabled=1
gpgcheck=0
[root@localhost yum.repos.d]# yum clean all && yum makecache
3.安装环境依赖包
[root@localhost yum.repos.d]# yum -y install gcc gcc-c++ make pcre pcre-devel expat-devel perl
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
软件包 1:make-3.82-23.el7.x86_64 已安装并且是最新版本
软件包 pcre-8.32-17.el7.x86_64 已安装并且是最新版本
软件包 4:perl-5.16.3-292.el7.x86_64 已安装并且是最新版本
正在解决依赖关系
--> 正在检查事务
---> 软件包 expat-devel.x86_64.0.2.1.0-10.el7_3 将被 安装
---> 软件包 gcc.x86_64.0.4.8.5-16.el7 将被 安装
--> 正在处理依赖关系 cpp = 4.8.5-16.el7,它被软件包 gcc-4.8.5-16.el7.x86_64 需要
--> 正在处理依赖关系 glibc-devel >= 2.2.90-12,它被软件包 gcc-4.8.5-16.el7.x86_64 需要
--> 正在处理依赖关系 libmpc.so.3()(64bit),它被软件包 gcc-4.8.5-16.el7.x86_64 需要
---> 软件包 gcc-c++.x86_64.0.4.8.5-16.el7 将被 安装
--> 正在处理依赖关系 libstdc++-devel = 4.8.5-16.el7,它被软件包 gcc-c++-4.8.5-16.el7.x86_64 需要
---> 软件包 pcre-devel.x86_64.0.8.32-17.el7 将被 安装
--> 正在检查事务
---> 软件包 cpp.x86_64.0.4.8.5-16.el7 将被 安装
---> 软件包 glibc-devel.x86_64.0.2.17-196.el7 将被 安装
--> 正在处理依赖关系 glibc-headers = 2.17-196.el7,它被软件包 glibc-devel-2.17-196.el7.x86_64 需要
--> 正在处理依赖关系 glibc-headers,它被软件包 glibc-devel-2.17-196.el7.x86_64 需要
---> 软件包 libmpc.x86_64.0.1.0.1-3.el7 将被 安装
---> 软件包 libstdc++-devel.x86_64.0.4.8.5-16.el7 将被 安装
--> 正在检查事务
---> 软件包 glibc-headers.x86_64.0.2.17-196.el7 将被 安装
--> 正在处理依赖关系 kernel-headers >= 2.2.1,它被软件包 glibc-headers-2.17-196.el7.x86_64 需要
--> 正在处理依赖关系 kernel-headers,它被软件包 glibc-headers-2.17-196.el7.x86_64 需要
--> 正在检查事务
---> 软件包 kernel-headers.x86_64.0.3.10.0-693.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
=========================================================================================
Package 架构 版本 源 大小
=========================================================================================
正在安装:
expat-devel x86_64 2.1.0-10.el7_3 local 57 k
gcc x86_64 4.8.5-16.el7 local 16 M
gcc-c++ x86_64 4.8.5-16.el7 local 7.2 M
pcre-devel x86_64 8.32-17.el7 local 480 k
为依赖而安装:
cpp x86_64 4.8.5-16.el7 local 5.9 M
glibc-devel x86_64 2.17-196.el7 local 1.1 M
glibc-headers x86_64 2.17-196.el7 local 675 k
kernel-headers x86_64 3.10.0-693.el7 local 6.0 M
libmpc x86_64 1.0.1-3.el7 local 51 k
libstdc++-devel x86_64 4.8.5-16.el7 local 1.5 M
事务概要
=========================================================================================
安装 4 软件包 (+6 依赖软件包)
总下载量:39 M
安装大小:85 M
Downloading packages:
-----------------------------------------------------------------------------------------
总计 120 MB/s | 39 MB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : libmpc-1.0.1-3.el7.x86_64 1/10
正在安装 : cpp-4.8.5-16.el7.x86_64 2/10
正在安装 : libstdc++-devel-4.8.5-16.el7.x86_64 3/10
正在安装 : kernel-headers-3.10.0-693.el7.x86_64 4/10
正在安装 : glibc-headers-2.17-196.el7.x86_64 5/10
正在安装 : glibc-devel-2.17-196.el7.x86_64 6/10
正在安装 : gcc-4.8.5-16.el7.x86_64 7/10
正在安装 : gcc-c++-4.8.5-16.el7.x86_64 8/10
正在安装 : expat-devel-2.1.0-10.el7_3.x86_64 9/10
正在安装 : pcre-devel-8.32-17.el7.x86_64 10/10
验证中 : kernel-headers-3.10.0-693.el7.x86_64 1/10
验证中 : gcc-c++-4.8.5-16.el7.x86_64 2/10
验证中 : libstdc++-devel-4.8.5-16.el7.x86_64 3/10
验证中 : pcre-devel-8.32-17.el7.x86_64 4/10
验证中 : libmpc-1.0.1-3.el7.x86_64 5/10
验证中 : cpp-4.8.5-16.el7.x86_64 6/10
验证中 : gcc-4.8.5-16.el7.x86_64 7/10
验证中 : glibc-devel-2.17-196.el7.x86_64 8/10
验证中 : expat-devel-2.1.0-10.el7_3.x86_64 9/10
验证中 : glibc-headers-2.17-196.el7.x86_64 10/10
已安装:
expat-devel.x86_64 0:2.1.0-10.el7_3 gcc.x86_64 0:4.8.5-16.el7
gcc-c++.x86_64 0:4.8.5-16.el7 pcre-devel.x86_64 0:8.32-17.el7
作为依赖被安装:
cpp.x86_64 0:4.8.5-16.el7 glibc-devel.x86_64 0:2.17-196.el7
glibc-headers.x86_64 0:2.17-196.el7 kernel-headers.x86_64 0:3.10.0-693.el7
libmpc.x86_64 0:1.0.1-3.el7 libstdc++-devel.x86_64 0:4.8.5-16.el7
完毕!
=============================================================================
yum -y install \
gcc \ C语言的编译器
gcc-c++ \ C++的编译器
make \ 源代码编译器(源代码转换成二进制文件)
pcre \ pcre是一个Perl函数库,包括perl 兼容的正则表达式库
pcre-devel \ perl的接口开发包
expat-devel \ 用于支持网站解析HTML、XML文件
perl perl语言编译器
4.将安装Apache所需软件包放到/opt目录下
httpd-2.4.29.tar.gz
apr-1.6.2.tar.gz
apr-util-1.6.0.tar.gz
apr组件包用于支持Apache上层应用跨平台,提供底层接口库,能有效的降低并发连接数、降低进程和减少访问堵塞。
5.配置软件模块
[root@localhost yum.repos.d]# cd /opt/
[root@localhost opt]# tar zxvf apr-1.6.2.tar.gz
[root@localhost opt]# tar zxvf apr-util-1.6.0.tar.gz
[root@localhost opt]# tar jxvf httpd-2.4.29.tar.bz2
[root@localhost opt]# mv apr-1.6.2 /opt/httpd-2.4.29/srclib/apr
[root@localhost opt]# mv apr-util-1.6.0 /opt/httpd-2.4.29/srclib/apr-util
[root@localhost opt]# cd /opt/httpd-2.4.29/
[root@localhost httpd-2.4.29]# ./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi
=============================================================================
./configure \
--prefix=/usr/local/httpd \ 指定将 httpd 服务程序的安装路径
--enable-so \ 启用动态加载模块支持,使 httpd 具备进一步扩展功能的能力
--enable-rewrite \ 启用网页地址重写功能,用于网站优化、防盗链及目录迁移维护
--enable-charset-lite \ 启动字符集支持,以便支持使用各种字符集编码的页面
--enable-cgi 启用CGI(通用网关接口)脚本程序支持,便于网站的外部扩展应用访问能力
6.编译及安装
[root@localhost httpd-2.4.29]# make && make install
make -j 2 表示开2核同时进行编译(使用这个,会跑很久)
7.优化配置文件路径,并把httpd服务的可执行程序文件放入路径环境变量的目录中便于系统识别
[root@localhost httpd-2.4.29]# ln -s /usr/local/httpd/conf/httpd.conf /etc/
[root@localhost httpd-2.4.29]# ln -s /usr/local/httpd/bin/* /usr/local/bin/
8.添加httpd系统服务
[root@localhost httpd-2.4.29]# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
[root@localhost httpd-2.4.29]# chmod +x /etc/init.d/httpd #用于service服务管理
[root@localhost httpd-2.4.29]# vi /etc/init.d/httpd
#!/bin/bash #在第一行前插入新行,添加此三行内容
# chkconfig: 35 85 21 #35级别自动运行 第85个启动 第21个关闭
# description: Apache is a World Wide Web server
[root@localhost httpd-2.4.29]# chkconfig --add httpd #将httpd服务加入到service管理器
[root@localhost httpd-2.4.29]# systemctl start httpd.service
9.修改httpd 服务配置文件
[root@localhost httpd-2.4.29]# vim /etc/httpd.conf
--52行--修改写本机的ip地址
Listen 20.0.0.200:80
--197行--取消注释,修改
ServerName www.webtest.com:80
--221行--默认首页存放路径
DocumentRoot "/usr/local/httpd/htdocs"
--255行--默认首页文件名设置
DirectoryIndex index.html
[root@localhost etc]# cat /usr/local/httpd/htdocs/index.html
<html><body><h1>It works!</h1></body></html>
[root@localhost etc]# httpd -t
Syntax OK
## httpd -t 或 apachectl -t #检查配置文件的配置项是否有误
[root@localhost httpd-2.4.29]# systemctl restart httpd.service
编译安装mysqld 服务
1.将安装mysql 所需软件包放到/opt目录下
boost_1_59_0.tar.gz
mysql-5.7.17.tar.gz
2.安装环境依赖包
[root@localhost httpd-2.4.29]# yum -y install gcc gcc-c++ ncurses ncurses-devel bison cmake
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
软件包 gcc-4.8.5-16.el7.x86_64 已安装并且是最新版本
软件包 gcc-c++-4.8.5-16.el7.x86_64 已安装并且是最新版本
软件包 ncurses-5.9-13.20130511.el7.x86_64 已安装并且是最新版本
正在解决依赖关系
--> 正在检查事务
---> 软件包 bison.x86_64.0.3.0.4-1.el7 将被 安装
--> 正在处理依赖关系 m4 >= 1.4,它被软件包 bison-3.0.4-1.el7.x86_64 需要
---> 软件包 cmake.x86_64.0.2.8.12.2-2.el7 将被 安装
---> 软件包 ncurses-devel.x86_64.0.5.9-13.20130511.el7 将被 安装
--> 正在检查事务
---> 软件包 m4.x86_64.0.1.4.16-10.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
=========================================================================================
Package 架构 版本 源 大小
=========================================================================================
正在安装:
bison x86_64 3.0.4-1.el7 local 674 k
cmake x86_64 2.8.12.2-2.el7 local 7.1 M
ncurses-devel x86_64 5.9-13.20130511.el7 local 713 k
为依赖而安装:
m4 x86_64 1.4.16-10.el7 local 256 k
事务概要
=========================================================================================
安装 3 软件包 (+1 依赖软件包)
总下载量:8.7 M
安装大小:31 M
Downloading packages:
-----------------------------------------------------------------------------------------
总计 84 MB/s | 8.7 MB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : m4-1.4.16-10.el7.x86_64 1/4
正在安装 : bison-3.0.4-1.el7.x86_64 2/4
正在安装 : cmake-2.8.12.2-2.el7.x86_64 3/4
正在安装 : ncurses-devel-5.9-13.20130511.el7.x86_64 4/4
验证中 : m4-1.4.16-10.el7.x86_64 1/4
验证中 : bison-3.0.4-1.el7.x86_64 2/4
验证中 : ncurses-devel-5.9-13.20130511.el7.x86_64 3/4
验证中 : cmake-2.8.12.2-2.el7.x86_64 4/4
已安装:
bison.x86_64 0:3.0.4-1.el7 cmake.x86_64 0:2.8.12.2-2.el7
ncurses-devel.x86_64 0:5.9-13.20130511.el7
作为依赖被安装:
m4.x86_64 0:1.4.16-10.el7
完毕!
=============================================================================
yum -y install \
gcc \
gcc-c++ \
ncurses \ 字符终端下图形互动功能的动态库
ncurses-devel \ ncurses开发包
bison \ 语法分析器
cmake mysql需要用cmake编译安装
3.配置软件模块
[root@localhost httpd-2.4.29]# cd /opt
[root@localhost opt]# tar zxvf mysql-5.7.17.tar.gz
[root@localhost opt]# tar zxvf boost_1_59_0.tar.gz
[root@localhost opt]# mv boost_1_59_0 /usr/local/boost #重命名
[root@localhost opt]# cd /opt/mysql-5.7.17/
[root@localhost mysql-5.7.17]# cmake \
> -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
> -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
> -DSYSCONFDIR=/etc \
> -DSYSTEMD_PID_DIR=/usr/local/mysql \
> -DDEFAULT_CHARSET=utf8 \
> -DDEFAULT_COLLATION=utf8_general_ci \
> -DWITH_EXTRA_CHARSETS=all \
> -DWITH_INNOBASE_STORAGE_ENGINE=1 \
> -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
> -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
> -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
> -DMYSQL_DATADIR=/usr/local/mysql/data \
> -DWITH_BOOST=/usr/local/boost \
> -DWITH_SYSTEMD=1
============================================================
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ 指定mysql的安装路径
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \ 指定mysql进程监听套接字文件(数据库连接文件)的存储路径
-DSYSCONFDIR=/etc \ 指定配置文件的存储路径
-DSYSTEMD_PID_DIR=/usr/local/mysql \ 指定进程文件的存储路径
-DDEFAULT_CHARSET=utf8 \ 指定默认使用的字符集编码,如 utf8
-DDEFAULT_COLLATION=utf8_general_ci \ 指定默认使用的字符集校对规则
-DWITH_EXTRA_CHARSETS=all \ 指定支持其他字符集编码
-DWITH_INNOBASE_STORAGE_ENGINE=1 \ 安装INNOBASE存储引擎
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \ 安装ARCHIVE存储引擎
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ 安装BLACKHOLE存储引擎
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \ 安装FEDERATED存储引擎
-DMYSQL_DATADIR=/usr/local/mysql/data \ 指定数据库文件的存储路径
-DWITH_BOOST=/usr/local/boost \ 指定boost的路径,若使用mysql-boost集成包安装则-DWITH_BOOST=boost
-DWITH_SYSTEMD=1 生成便于systemctl管理的文件
注意:如果在CMAKE的过程中有报错,当报错解决后,需要把源码目录中的CMakeCache.txt文件删除,然后再重新CMAKE,否则错误依旧
[root@localhost mysql-5.7.17]# make -j2 && make install
存储引擎选项:
MYISAM,MERGE,MEMORY,和CSV引擎是默认编译到服务器中,并不需要明确地安装。
静态编译一个存储引擎到服务器,使用-DWITH_engine_STORAGE_ENGINE= 1
可用的存储引擎值有:ARCHIVE, BLACKHOLE, EXAMPLE, FEDERATED, INNOBASE (InnoDB), PARTITION (partitioning suppor),和PERFSCHEMA (Performance Schema)
[root@localhost mysql-5.7.17]# vim /etc/my.cnf
[client]
port = 3306
socket=/usr/local/mysql/mysql.sock
[mysqld]
user = mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port = 3306
character-set-server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket=/usr/local/mysql/mysql.sock
bind-address = 0.0.0.0
skip-name-resolve
max_connections=2048
default-storage-engine=INNODB
max_allowed_packet=16M
server-id = 1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
==========================================================================
[client] 客户端设置
port = 3306
socket=/usr/local/mysql/mysql.sock
[mysqld] 服务全局设置
user = mysql 设置管理用户
basedir=/usr/local/mysql 指定数据库的安装目录
datadir=/usr/local/mysql/data 指定数据库文件的存储路径
port = 3306 指定端口
character-set-server=utf8 设置服务器字符集编码格式为utf8
pid-file = /usr/local/mysql/mysqld.pid 指定pid 进程文件路径
socket=/usr/local/mysql/mysql.sock 指定数据库连接文件
bind-address = 0.0.0.0 设置监听地址,0.0.0.0代表允许所有,如允许多个IP需空格隔开
skip-name-resolve 禁用DNS解析
max_connections=2048 设置mysql的最大连接数
default-storage-engine=INNODB 指定默认存储引擎
max_allowed_packet=16M 设置数据库接收的数据包大小的最大值
server-id = 1 指定服务ID号
---------------------------------------------------------
sql_mode常用值如下
NO_ENGINE_SUBSTITUTION
如果需要的存储引擎被禁用或未编译,那么抛出错误。不设置此值时,用默认的存储引擎替代,并抛出一个异常
STRICT_TRANS_TABLES
在该模式下,如果一个值不能插入到一个事务表中,则中断当前的操作,对非事务表不做限制
NO_AUTO_CREATE_USER
禁止GRANT创建密码为空的用户
NO_AUTO_VALUE_ON_ZERO
mysql中的自增长列可以从0开始。默认情况下自增长列是从1开始的,如果你插入值为0的数据会报错
NO_ZERO_IN_DATE
不允许日期和月份为零
NO_ZERO_DATE
mysql数据库不允许插入零日期,插入零日期会抛出错误而不是警告
ERROR_FOR_DIVISION_BY_ZERO
在INSERT或UPDATE过程中,如果数据被零除,则产生错误而非警告。默认情况下数据被零除时MySQL返回NULL
PIPES_AS_CONCAT
将"||"视为字符串的连接操作符而非或运算符,这和Oracle数据库是一样的,也和字符串的拼接函数Concat相类似
ANSI_QUOTES
启用ANSI_QUOTES后,不能用双引号来引用字符串,因为它被解释为识别符
4.更改mysql安装目录和配置文件的属主属组
如果出现chown: 无效的用户: "mysql:mysql"此错误,要建立mysql用户和组
[root@localhost mysql-5.7.17]# groupadd mysql
[root@localhost mysql-5.7.17]# useradd -g mysql mysql
[root@localhost mysql-5.7.17]# chown -R mysql:mysql /usr/local/mysql/
[root@localhost mysql-5.7.17]# chown mysql:mysql /etc/my.cnf
5.设置路径环境变量
[root@localhost mysql-5.7.17]# echo 'export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
[root@localhost mysql-5.7.17]# source /etc/profile
6.初始化数据库
[root@localhost mysql-5.7.17]# cd /usr/local/mysql/bin/
[root@localhost bin]# ./mysqld \
> --initialize-insecure \
> --user=mysql \
> --basedir=/usr/local/mysql \
> --datadir=/usr/local/mysql/data
==================================================
./mysqld \
--initialize-insecure \ 生成初始化密码为空
--user=mysql \ 指定管理用户
--basedir=/usr/local/mysql \ 指定数据库的安装目录
--datadir=/usr/local/mysql/data 指定数据库文件的存储路径
7.添加mysqld系统服务
[root@localhost bin]# cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/ #用于systemctl服务管理
[root@localhost bin]# systemctl daemon-reload #刷新识别
[root@localhost bin]# systemctl start mysqld.service #开启服务
[root@localhost bin]# systemctl enable mysqld #开机自启动
Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld.service to /usr/lib/systemd/system/mysqld.service.
[root@localhost bin]# netstat -anpt | grep 3306 #查看端口
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 55887/mysqld
8.修改mysql 的登录密码
[root@localhost bin]# mysqladmin -u root -p password "abc123"
Enter password:
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
[root@localhost bin]# mysql -uroot -pabc123
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.17 Source distribution
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
9、授权远程登录
mysql> show databases; #查看当前已有的数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> quit #退出数据库
Bye
[root@localhost bin]# mysql -u root -pabc123
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.17 Source distribution
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> grant all privileges on *.* to 'root'@'%' identified by 'abc123';
Query OK, 0 rows affected, 1 warning (0.01 sec)
(有分号,出现ok表示成功)
#授予root用户可以在所有终端远程登录,使用的密码是abc123,并对所有数据库和所有表有操作权限
编译安装PHP 解析环境
1.将安装PHP 所需软件包传到/opt目录下,并且解压
Discuz_X3.4_SC_UTF8.zip
php-7.1.10.tar.bz2
[root@localhost opt]# tar xf php-7.1.10.tar.bz2
2.安装GD库和GD库关联程序,用来处理和生成图片
yum -y install \
gd \
libjpeg libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 libxml2-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel
3.配置软件模块
[root@localhost opt]# tar jxvf php-7.1.10.tar.bz2
[root@localhost opt]# cd /opt/php-7.1.10/
./configure \
--prefix=/usr/local/php7 \
--with-apxs2=/usr/local/httpd/bin/apxs \
--with-mysql-sock=/usr/local/mysql/mysql.sock \
--with-config-file-path=/usr/local/php7 \
--with-mysqli \
--with-zlib \
--with-curl \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-openssl \
--enable-mbstring \
--enable-xml \
--enable-session \
--enable-ftp \
--enable-pdo \
--enable-tokenizer \
--enable-zip
===============================================
./configure \
--prefix=/usr/local/php7 \ 指定将 PHP 程序的安装路径
--with-apxs2=/usr/local/httpd/bin/apxs \ 指定Apache httpd服务提供的apxs 模块支持程序的文件位置
--with-mysql-sock=/usr/local/mysql/mysql.sock \ 指定mysql 数据库连接文件的存储路径
--with-config-file-path=/usr/local/php7 设置 PHP 的配置文件 php.ini 将要存放的位置
--with-mysqli \ 添加 MySQL 扩展支持 #mysqli扩展技术不仅可以调用MySQL的存储过程、处理MySQL事务,而且还可以使访问数据库工作变得更加稳定
--with-zlib \ 支持zlib功能,提供数据压缩
--with-curl \ 开启curl扩展功能,实现HTTP的Get下载和Post请求的方法
--with-gd \ 激活gd 库的支持
--with-jpeg-dir \ 激活jpeg 的支持
--with-png-dir \ 激活png 的支持
--with-freetype-dir \
--with-openssl \
--enable-mbstring \ 启用多字节字符串功能,以便支持中文等代码
--enable-xml \ 开启扩展性标记语言模块
--enable-session \ 会话
--enable-ftp \ 文本传输协议
--enable-pdo \ 函数库
--enable-tokenizer \ 令牌解释器
--enable-zip ZIP压缩格式
[root@localhost php-7.1.10]# cp /opt/php-7.1.10/php.ini-development /usr/local/php.ini
[root@localhost php-7.1.10]# vim /usr/local/php.ini
切到搜索模式esc 输入:set nu开启行号 跳转到1170行
//mysqli.default_socket =后面加入下面这行
/usr/local/mysql/mysql.sock (有空格)
切到搜索模式esc
/data.timezone
在939行去掉 ;
在等号后面添加 Asia/shanghai(有空格)
4.编译及安装
[root@localhost php-7.1.10]# make && make install
5.复制模版文件作为PHP 的主配置文件,并进行修改
[root@localhost php-7.1.10]# cp /opt/php-7.1.10/php.ini-development /usr/local/php7/php.ini
# 在测试环境时使用php.ini-development文件,而在生产环境时使用php.ini-production文件
[root@localhost php-7.1.10]# vim /usr/local/php7/php.ini
6.优化把PHP 的可执行程序文件放入路径环境变量的目录中便于系统识别
[root@localhost php-7.1.10]# ln -s /usr/local/php7/bin/* /usr/local/bin/
[root@localhost php-7.1.10]# php -m #查看PHP 加载了哪些模块
7.修改httpd 服务的配置文件,让apache支持PHP
[root@localhost php-7.1.10]# vim /etc/httpd.conf
AddType application/x-httpd-php .php --393行--插入以下内容(插在下面,原行不删)
AddType application/x-httpd-php-source .phps ##这里的点前面空格一定要加,否则报错
DirectoryIndex index.html index.php --255行--修改首页文件名设置
LoadModule php7_module modules/libphp7.so ---156行 ---检查支持php7的模块是否存在(可以用'/'在文件中查找 )
8.LoadModule php7_module modules/libphp7.so —156行 —检查支持php7的模块是否存在(可以用’/'在文件中查找 )
[root@localhost php-7.1.10]# rm -rf /usr/local/httpd/htdocs/index.html
[root@localhost php-7.1.10]# vim /usr/local/httpd/htdocs/index.php
[root@localhost php-7.1.10]# systemctl restart httpd
[root@localhost php-7.1.10]# systemctl restart httpd.service
===================================
如若不成功,需关闭防火墙
[root@localhost php-7.1.10]# systemctl stop firewalld
[root@localhost php-7.1.10]# systemctl disable firewalld
[root@localhost php-7.1.10]# setenforce 0
打开浏览器,输入当前的ip地址 出现php页面成功
安装论坛
1.创建数据库,并进行授权
[root@localhost php-7.1.10]# mysql -uroot -pabc123
mysql -u root -p)
进入MySQL内,输入完后要记得加”;“
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.17 Source distribution
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> CREATE DATABASE bbs; ##创建一个数据库
Query OK, 1 row affected (0.01 sec)
mysql> GRANT all ON bbs.* TO 'bbsuser'@'%' IDENTIFIED BY 'admin123';
# 把bbs数据库里面所有表的权限授予给bbsuser,并设置密码admin123
mysql> flush privileges; #刷新数据库
Query OK, 0 rows affected (0.01 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| bbs |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
mysql> quit
Bye
2.解压论坛压缩包
[root@localhost php-7.1.10]# cd /opt/
[root@localhost opt]# unzip /opt/Discuz_X3.4_SC_UTF8.zip -d /opt/dis
[root@localhost opt]# cd /opt/dis/dir_SC_UTF8/
[root@localhost dir_SC_UTF8]# cp -r upload/ /usr/local/httpd/htdocs/bbs
# 上传站点更新包
[root@localhost dir_SC_UTF8]# chown -R daemon /usr/local/httpd/htdocs/bbs #更改论坛目录的属主
[root@localhost dir_SC_UTF8]# cd /usr/local/httpd/htdocs/bbs
[root@localhost bbs]# chown -R daemon ./config
[root@localhost bbs]# chown -R daemon ./data
[root@localhost bbs]# chown -R daemon ./uc_client
[root@localhost bbs]# chown -R daemon ./uc_server/data
3.浏览器访问验证
论坛页面访问
数据库服务器:localhost ###本地架设就用localhost,如何不是在在本机上就要填写IP地址和端口号
数据库名字:bbs
数据库用户名:bbsuser
数据库密码:admin123
管理员账号:admin
管理员密码:admin123
论坛后台管理员页面
http://20.0.0.200/bbs/admin.php