LAMP部署owncloud程序
一、AWS平台部署owncloud
1、创建VPC
VPC、子网、internet网关、安全组、路由
2、创建EC2
选规格、选系统、安全组、外网IP、下载好秘钥
连接EC2:ssh -i "hqs01.pem" ec2-user@52.80.131.140
3、安装LAMP并启动相应服务
# 1、检查系统更新:
sudo yum update -y
# 2、安装 lamp-mariadb10.2-php7.2 和 php7.2 Amazon LinuxExtras 存储库:
sudo rpm -qa| grep php
# 删除所有查出来的php服务
sudo rpm -e --nodeps php72w-mysql-7.2.34-1.w7.x86_64
sudo amazon-linux-extras install -y lamp-mariadb10.2-php7.2 php7.2
# 3、安装 Apache Web 服务器、MariaDB 和 PHP 软件包:
sudo yum install -y httpd mariadb-server
# 4、开启httpd服务
sudo systemctl start httpd
# 5、设置apache http服务开机启动:
sudo systemctl enable httpd
# 6、查看http服务状态:
sudo systemctl status httpd
# 7、修改httpd服务端口(80端口访问不了)
vim /etc/httpd/conf/httpd.conf
Listen 80 ---》改为Listen 81
sudo systemctl restart httpd
# 8、启动数据库
sudo systemctl restart mariadb
# 9、验证:在浏览器中键入EC2实例的IP地址
http://xxxxx:81
4、ownclound软件包上传至ChinaSkill-node-1实例中并解压
sudo yum install -y lrzsz # 上传下载工具
rz
sudo unzip owncloud-complete-20200731.zip # 解压
sudo cp -r owncloud /var/www/html/
sudo chown -R apache:apache /var/www/html/owncloud/
5、修改Apache服务的权限(root用户可跳过)
Amazon Linux Apache 文档根目录为 /var/www/html,默认情况下归根用户所有。
# 1、设置文件权限,将ec2-user添加到apache中:
sudo usermod -a -G apache ec2-user
# 2、退出并重新登陆,再验证成员资格:
exit
# 3、重新连接实例,运行以下命令:
groups
以下为反馈内容:
ec2-user adm wheel apache systemd-journal
# 4、将 /var/www 及其内容的组所有权更改到 apache 组:
sudo chown -R ec2-user:apache /var/www
# 5、要添加组写入权限以及设置未来子目录上的组 ID,更改 /var/www 及其子目录的目录权限:
sudo chmod 2775 /var/www && find /var/www -type d -exec sudo chmod 2775 {} \;
# 6、添加组写入权限,递归地更改 /var/www 及其子目录的文件权限:
find /var/www -type f -exec sudo chmod 0664 {} \;
以上操作适用于EC2-user,ec2-user (和 apache 组的任何未来成员) 可以添加、删除和编辑 Apache 文档根目录中的文件,允许您添加内容,如静态网站或 PHP 应用程序。
6、创建数据库
[root@ip-172-16-44-44 owncloud]# mysqladmin -u root password '12345678'
[root@ip-172-16-44-44 owncloud]# mysql -uroot -p12345678
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 10.2.10-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create database owncloud;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all privileges on *.* to root@'%' identified by "12345678";
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> grant all privileges on *.* to root@'localhost' identified by "12345678";
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> exit
Bye
修改密码的方式(有需要再使用):
[root@ip-172-16-44-44 owncloud]# mysqladmin -u root -p12345678 password Abc@1234
[root@ip-172-16-44-44 owncloud]# mysql -uroot -pAbc@1234
MariaDB [(none)]> grant all privileges on *.* to root@'%' identified by "Abc@1234";
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> grant all privileges on *.* to root@'localhost' identified by "Abc@1234";
Query OK, 0 rows affected (0.00 sec)
7、重启服务
systemctl restart httpd && systemctl restart php-fpm;
8、初始化owncloud
使用浏览器访问 http://xxxxxx:81/owncloud/index.php 初始化owncloud。
# 提示要更新各种库,解决办法:
yum provides php #自带的只有5.4版本
rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm #更新源
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum remove php-common -y #移除系统自带的php-common
yum install -y php72w php72w-opcache php72w-xml php72w-mcrypt php72w-gd php72w-devel php72w-mysql php72w-intl php72w-mbstring #安装依赖包
php -v #版本变为7.2
二、非aws服务部署
1、安装Apache服务
# 1.更换阿里的yum:
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all && yum makecache;
# 2.安装httpd(Apache)
yum install -y httpd
# 安装相关开发工具
yum install -y httpd-devel
# 3.启动httpd
systemctl start httpd
systemctl enable httpd
# 4.关闭和禁用防火墙(另外记得关闭selinux)
systemctl stop firewalld
systemctl disable firewalld
# 5.安装网络工具包
yum -y install net-tools
# 6.关闭selinux
vi /etc/selinux/config
SELINUX=disabled
# 执行以下命令让配置生效
setenforce 0
# 7.端口的信息
[root@localhost yum.repos.d]# netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1081/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1236/master
tcp6 0 0 :::80 :::* LISTEN 1951/httpd
tcp6 0 0 :::22 :::* LISTEN 1081/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1236/master
# 7.访问页面查看apache首页
http://192.168.88.101/
2、安装mariadb
# 1.安装数据库相关组件
yum install -y mariadb mariadb-server mariadb-libs mariadb-devel
mariadb-server:数据库服务
mariadb-libs:数据库相关的库文件
mariadb-devel:数据库工具包
# 2.启动数据库
systemctl start mariadb
systemctl enable mariadb
# 3.数据库安全设置
[root@localhost yum.repos.d]# mysql_secure_installation
Enter current password for root (enter for none): 《——输入当前root密码,直接回车
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y 《——确定要设置密码
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
Remove anonymous users? [Y/n] 《——删除默认用户,后面都是默认YES,直接回车即可
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n]
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n]
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n]
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
# 3.登录数据库验证
mysql -uroot -p12345678
3、安装php服务
# 安装php
yum -y install php
# 安装PHP与MySQL数据库环境交互的组件
yum -y install php-mysql
# 安装PHP相关的组件,以便适配不同的WEB项目应用程序
yum -y install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel php-bcmath
# 切换到WEB端应用程序的存放目录
# phpinfo()方法--->作用:显示php相关的属性信息
cd /var/www/html/
# 创建php文件
vi info.php
<?php
phpinfo();
?>
# 重启apache,浏览网页
systemctl restart httpd
浏览如下地址:
http://192.168.88.101/info.php
4、owncloud包安装部署
# 安装上传下载工具包
yum install -y lrzsz
# 上传软件包
[root@localhost ~]# rz
z waiting to receive.**B0100000023be50
[root@localhost ~]# ls
anaconda-ks.cfg ddd owncloud-complete-20200731.zip
# 安装解压包
yum install unzip
# 解压
[root@localhost ~]# unzip owncloud-complete-20200731.zip
[root@localhost ~]# ls
anaconda-ks.cfg owncloud owncloud-complete-20200731.zip
# 复制到WEB端应用程序的存放目录
[root@localhost ~]# cp -r owncloud/ /var/www/html/
[root@localhost ~]# ls /var/www/html/
info.php owncloud
# 修改用户和用户组
chown -R apache:apache /var/www/html/owncloud/
5、创建owncloud数据库和授权
# 连接数据库
[root@localhost ~]# mysql -uroot -p12345678
# 创建数据库和授权本地和远程访问
MariaDB [(none)]> create database owncloud;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all privileges on *.* to root@'%' identified by "12345678";
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> grant all privileges on *.* to root@'localhost' identified by "12345678";
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> exit
Bye
6、访问owncloud页面
# 重启apache
systemctl restart httpd
# 访问如下页面
http://192.168.88.101/owncloud/index.php
# 报错如下:
This version of ownCloud requires at least PHP 7.2.0
You are currently running PHP 5.4.16. Please update your PHP version.
# 更新为7.2的方法:
yum provides php #自带的只有5.4版本
#更新源
rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
#移除系统自带的php-common
yum remove php-common -y
yum install -y php72w php72w-opcache php72w-xml php72w-mcrypt php72w-gd php72w-devel php72w-mysql php72w-intl php72w-mbstring #安装依赖包
php -v #版本变为7.2
# 再次访问页面依然报错:
Can't write into config directory!
This can usually be fixed by <a href="https://doc.owncloud.org/server/10.5/go.php?to=admin-dir_permissions" target="_blank" rel="noreferrer">giving the webserver write access to the config directory</a>.
# 解决方法(关闭selinux即可):
[root@localhost html]# setsebool -P httpd_unified 1
[root@localhost html]# setsebool -P httpd_execmem 1