ownCloud的安装依赖LAMP环境,即 Linux + Apache + MySQL(Mariadb) + PHP,所以在装owncloud前最好先装好这些,并且保证已经可用。
为了方便,本文在运行shell命令时都是以管理员用户身份运行(root权限下运行)!!!
具体步骤:
这里重申一下,为免麻烦,以下命令都是以管理员用户的身份运行的,root权限下执行的!
1. 开放防火墙
setenforce 0
sed -i 's/enforcing/disabled/' /etc/selinux/config
systemctl disable --now firewalld
reboot
2. 安装php 7.2 + apahce 运行环境
yum install centos-release-scl-rh -y
# yum search php
yum install rh-php72 -y
yum install rh-php72 rh-php72-php rh-php72-php-gd rh-php72-php-mbstring rh-php72-php-intl rh-php72-php-pecl-apcu -y
yum install rh-php72-php-mysqlnd -y
scl -l
scl enable rh-php72 "php -v"
scl enable rh-php72 bash
php -v
php -myum install -y httpd
systemctl start httpd
systemctl enabled httpdln -s /opt/rh/httpd24/root/etc/httpd/conf.d/rh-php72-php.conf /etc/httpd/conf.d/
ln -s /opt/rh/httpd24/root/etc/httpd/conf.modules.d/15-rh-php72-php.conf /etc/httpd/conf.modules.d/
ln -s /opt/rh/httpd24/root/etc/httpd/modules/librh-php72-php7.so /etc/httpd/modules/systemctl restart httpd
3. 下载owncloud包
去owncloud官网 https://download.owncloud.org/community/owncloud-10.5.0.tar.bz2 下载包并解压,解压后的包文件夹名称应该也是owncloud
解压安装
yum install bzip2 lrzsz -y
mkdir -p /var/www/html/owncloud
tar -xjvf owncloud-10.5.0.tar.bz2
cd owncloud
yes | cp -r * /var/www/html/owncloud/
chown -R apache:apache /var/www/html/owncloud
chmod -R 777 /var/www/html/owncloud
chcon -v -R -u system_u -r object_r -t httpd_sys_content_t '/var/www/html/owncloud/'
chcon -R -t httpd_sys_rw_content_t '/var/www/html/owncloud/config/'
chcon -R -t httpd_sys_rw_content_t '/var/www/html/owncloud/apps/'
cd /var/www/html/owncloud
mkdir data
chown -R apache:apache /var/www/html/owncloud/
chcon -v -R -u system_u -r object_r -t httpd_sys_content_t '/var/www/html/owncloud/'
chcon -R -t httpd_sys_rw_content_t '/var/www/html/owncloud/data/'
chcon -R -t httpd_sys_rw_content_t '/var/www/html/owncloud/config/'
chcon -R -t httpd_sys_rw_content_t '/var/www/html/owncloud/apps/'
systemctl restart httpd
3,安装mysql数据库
yum -y install wget gcc gcc-c++ ncurses ncurses-devel cmake numactl.x86_64 libaio
wget http://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
tar -zxvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
mv /usr/local/mysql-5.7.24-linux-glibc2.12-x86_64/ /usr/local/mysql
cd /usr/local/mysql/
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
cat >/etc/my.cnf <<EOF
[client]
port=3306
socket=/tmp/mysql.sock
[mysqld]
port=3306
socket=/tmp/mysql.sock
skip-external-locking
key_buffer_size = 38M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
basedir=/usr/local/mysql
datadir=/var/lib/mysql
bind-address=0.0.0.0
innodb_flush_log_at_trx_commit=1
sync_binlog=1
log-bin=/var/lib/mysql/mysql_logbin
log-error=/var/log/mariadb
slow_query_log =1
slow_query_log_file=/tmp/mysql_slow.log
server-id=1
symbolic-links=0
[mysqld_safe]
pid-file=/var/run/mariadb/mariadb.pid
EOFuseradd mysql
mkdir -p /var/lib/mysql
chown mysql:mysql /var/lib/mysql
mkdir -p /var/log/mariadb
chown mysql:mysql /var/log/mariadb/
mkdir -p /var/run/mariadb
chown mysql:mysql /var/run/mariadb/
touch /var/run/mariadb/mariadb.pid
cat >> /etc/profile << EOF
export PATH=\$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib
EOF
source /etc/profile
chmod -R 777 /var/log
mysqld --defaults-file=/etc/my.cnf --user=mysql --initialize-insecure
/etc/init.d/mysql startmysql -u root -p
update mysql.user set authentication_string=password('123456') where user='root';
flush privileges;ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
登录owncloud,创建管理员用户,访问:http://192.168.225.194/owncloud/
【注意!】 图4这步包括以下内容:1. 创建owncloud的管理员用户(Create an admin account)。2. 数据存储文件夹(Data folder)。这里默认文件夹就可以了,不用管。 3. 配置数据库,包括数据库类型的选择,对应的用户、密码、数据库配置。这里默认是SQLite数据库类型,如果要用MySQL或者MariaDB的,这里一定要配置一下。如果忘记配置了,可以参考博文《如何将owncloud的数据库从SQLite迁移到MySQL/MariaDB》迁移数据库。
4 . 本机登录看看
图4. 登录owncloud
8. 配置trusted_domains
在其他电脑上访问服务器(假设IP为198.12.12.6),提示需要配置trusted_domains。
图5. 配置trusted_domains
从图片中的提示可以看出来,需要在服务器上配置/var/www/html/owncloud/config/config.php文件,并且在同一个文件夹下有一个配置的示例文件config.sample.php可供参考。
vim /var/www/html/owncloud/config/config.php
图6. 修改配置文件trusted_domains
前5行都不要动,在第8行 0 => 'c1loud.frankgreg.com', 这一行后面添加如下一句(假设服务器IP为192.12.12.6)
1 => '192.12.12.6',
重启httpd服务,完工。
systemctl restart httpd