centos7 LAMP部署owncloud

时间:2024-01-25 08:49:02

部署LAMP

1.安装 Apache

[root@localhost ~]# yum install httpd -y

2、启动 Apache 并设置为开机自启动

## 启动Apache

[root@localhost ~]# systemctl start httpd

\## 设置开机自启

[root@localhost ~]# systemctl enable httpd

Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to

/usr/lib/systemd/system/httpd.service.

3、查看Apache当前端口

## 安装netstat命令用于查看端口

[root@localhost ~]# yum install net-tools -y

[root@localhost ~]# netstat -antlupe | grep httpd

tcp6 0 0 :::80 :::* LISTEN 0

24654 2008/httpd

4、防火墙配置

[root@localhost ~]# firewall-cmd --permanent --add-service=http
success
## 允许80号端口永久通过防火墙
[root@localhost ~]# firewall-cmd --permanent --add-port=80/tcp
success
## 重新加载防火墙
[root@localhost ~]# firewall-cmd --reload
success

5、测试

浏览器中输入 http://IP地址:端口号

出现这个页面就代表服务部署成功


部署MySQL

这里我用MariaDB来替代

检查环境有没有旧版Mariadb旧版本

[root@localhost ~]# rpm -qa | grep -i mariadb
mariadb-libs-5.5.56-2.el7.x86_64
## 有的话删除旧版本Mariadb
[root@localhost ~]# yum remove mariadb-libs -y
1、配置阿里云mariadb YUM仓库

[root@localhost ~]# cd /etc/yum.repos.d

[root@localhost yum.repos.d]# vi mariadb.repo

# MariaDB 10.11 CentOS repository list - created 2023-11-01 09:12 UTC

# https://mariadb.org/download/

[mariadb]

name = MariaDB

# rpm.mariadb.org is a dynamic mirror if your preferred mirror goes offline. See

https://mariadb.org/mirrorbits/ for details.

# baseurl = https://rpm.mariadb.org/10.11/centos/$releasever/$basearch

baseurl = https://mirrors.aliyun.com/mariadb/yum/10.11/centos/$releasever/$basearch

module_hotfixes = 1

\# gpgkey = https://rpm.mariadb.org/RPM-GPG-KEY-MariaDB

gpgkey = https://mirrors.aliyun.com/mariadb/yum/RPM-GPG-KEY-MariaDB

gpgcheck = 1

更新yum缓存

[root@localhost yum.repos.d]# yum makecache

2、安装mariadb

[root@localhost yum.repos.d]# yum install MariaDB-server MariaDB-client -y
## 安装过程中可能会报错出现报错
## 使用下面这条命令进行安装
[root@localhost yum.repos.d]# yum install epel-release -y

[root@localhost yum.repos.d]# yum install pv -y

[root@localhost yum.repos.d]# yum install mariadb mariadb-server -y

3、启动mariadb服务

[root@localhost yum.repos.d]# systemctl start mariadb.service

## 设置开机自启

[root@localhost yum.repos.d]# systemctl enable mariadb.service

Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to

/usr/lib/systemd/system/mariadb.service.

## 验证mariadbd数据库3306端口是否开启

[root@localhost yum.repos.d]# netstat -antlupe | grep mariadbd

tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 997

25388 2463/mariadbd

tcp6 0 0 :::3306 :::* LISTEN 997

25389 2463/mariadbd

4、安全初始化

[root@localhost yum.repos.d]# mariadb-secure-installation

Enter current password for root (enter for none):    ## 回车即可

Switch to unix_socket authentication [Y/n] n ##选择n

Change the root password? [Y/n] y ##设置mariadb服务root新密码

New password:000000

Re-enter new password:000000

Remove anonymous users? [Y/n] y ## 选择y

... Success!

Disallow root login remotely? [Y/n] n ##选择n 后面会进行配置

... skipping

Remove test database and access to it? [Y/n] y ##选择y

Reload privilege tables now? [Y/n] y ##选择y
5、测试登录mariadb

[root@localhost yum.repos.d]# mysql -uroot -p000000

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

MariaDB [(none)]>

6、Mariadb用户授权

root账号@添加远程登录权限及操作所有数据库的权限

MariaDB [(none)]> create user 'root'@'%' identified by '000000';

MariaDB [(none)]> grant all privileges on *.* to 'root'@'%' ;

MariaDB [(none)]> exit

Bye

[root@localhost yum.repos.d]# cd

[root@localhost ~]#

部署PHP

1,依次执行以下命令

[root@localhost ~]# yum install epel-release -y
[root@localhost ~]# yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm -y

[root@localhost ~]# yum -y install yum-utils
[root@localhost ~]# yum repolist all |grep php
[root@localhost ~]# yum-config-manager --enable remi-php74
[root@localhost ~]# yum install php  php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json php-redis

2,修改 Apache 配置文件

[root@localhost ~]# vi /etc/httpd/conf/httpd.conf
3,进入配置文件按esc切换到末行模式输入set number可以显示行数

在96行插入  ServerName localhost:80

将104行的 Require all denied 修改为 Require all granted

将164行的 Directorylndex index.html改为DirectoryIndex index.php index.html

在285和286行中分别插入AddType application/x-httpd-php .php

AddType application/x-httpd-php-source .phps

按esc,输入wq 保存退出

执行以下命令,重启 Apache 服务

[root@localhost ~]# systemctl restart httpd

验证环境

[root@localhost ~]# echo "" >> /var/www/html/index.php 在浏览器中访问地址

http://192.168.220.233/index.php

出现以下即可


部署owncloud

安装上传软件包

[root@localhost ~]# yum install lrzsz unzip -y

用rz上传owncloud软件包

[root@yuchunle ~]# rz

[root@yuchunle ~]# ls

owncloud-complete-20231121.zip

解压压缩包并 复制到web端应用程序的存放目录

[root@yuchunle ~]# ls

owncloud-complete-20231121.zip

[root@yuchunle ~]# unzip owncloud-complete-20231121.zip

[root@yuchunle ~]# ls

owncloud owncloud-complete-20231121.zip

## 将目录 复制进web端存放目录

[root@yuchunle ~]# cp -r owncloud/ /var/www/html/

[root@yuchunle ~]# ls /var/www/html/

index.php owncloud

给目录进行权限赋值

[root@yuchunle ~]# chmod -R 755 /var/www/html/owncloud

[root@yuchunle ~]# ll /var/www/html/

总用量 8

-rw-r--r--. 1 root root 21 12月 5 23:03 index.php

. 12 root root 4096 12月 5 23:58 owncloud

创建owncloud数据库和授权

[root@yuchunle ~]# mysql -uroot -p000000  \## 进入数据库

MariaDB [(none)]> show databases; ## 查询所有数据库

## 创建owncloud数据库

MariaDB [(none)]> create database owncloud;

Query OK, 1 row affected (0.00 sec)

## 查询是否创建成功

MariaDB [(none)]> show databases;

创建wordpress数据库账户&&设置密码

MariaDB [(none)]> create user 'yu'@'%' identified by '000000';

MariaDB [(none)]> grant all privileges on *.* to 'yu'@'%';

MariaDB [(none)]> grant all privileges on wordpress.* to 'user'@'localhost';

MariaDB [(none)]> flush privileges;
## 退出数据库
MariaDB [(none)]> exit
Bye

配置selinux规则

[root@localhost ~]# setsebool -P httpd_unified 1

[root@localhost ~]# setsebool -P httpd_execmem 1

[root@localhost ~]# systemctl restart httpd

访问owncloud页面

\# 重启apache服务

systemctl restart httpd

\# 访问如下页面

http://192.168.220.233/owncloud/index.php

在浏览器访问出现以下页面即可