++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Running ownCloud on a Raspberry Pi
sudo apt update && sudo apt upgrade -y
Install Dependencies
======================================================================================
sudo apt install -y apache2 libapache2-mod-php mariadb-server openssl php-imagick php-common php-curl php-gd php-imap php-intl php-json php-mbstring php-mysql php-ssh2 php-xml php-zip php-apcu php-redis redis-server wget
sudo apt install -y ssh bzip2 rsync curl jq inetutils-ping smbclient coreutils php-ldap
sudo sed -i 's/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf
PHP Error Correction
To successfully install PHP 7.4 on your Debian Server, you will need to download and save the PPA repository along with the GPG key. To accomplish this, execute the provided commands:
sudo apt -y install lsb-release apt-transport-https ca-certificates
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
After completing this step, proceed to include the repository.
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
sudo apt update
sudo apt -y install php7.4
sudo apt install php7.4-xml php7.4-dev php7.4-curl php7.4-gd php7.4-fpm php7.4-zip php7.4-intl php7.4-mbstring php7.4-cli php7.4-mysql php7.4-common php7.4-cgi php7.4-apcu php7.4-redis redis-server php-pear curl libapr1 libtool libcurl4-openssl-dev
Enable php7.4
sudo a2enmod php7.4
Disable php8.x
sudo a2dismod php8.2
sudo apt-get purge php8.*
Generate SSl Certificate
sudo -i
cd /root
##in this way we will create the server.key in a folder only the root user can access##
openssl genrsa -out server.key 4096
openssl req -new -key server.key -out server.csr
openssl x509 -req -days 1825 -in server.csr -signkey server.key -out server.crt -sha256
chmod 400 server.key
a2ensite default-ssl.conf
systemctl reload apache2
a2enmod ssl
#systemctl restart apache2
It will ask you some information to generate the SSL certificate, that is because this is supposed to identify you as a trusted identity for the final user. Feel free to fill them as you want, it will not matter. It will generate two files on your /root (or whetever you where when you run the commands)
sudo mousepad /etc/apache2/sites-available/default-ssl.conf
look for this section and add the path where the ssl keys are
<VirtualHost _default_:443>
ServerAdmin webmaster@localhost
ServerName IP-SERVER:443
DocumentRoot /var/www/html/owncloud
SSLCertificateFile /root/server.crt
SSLCertificateKeyFile /root/server.key
now edit /etc/apache2/sites-available/000-default.conf
DocumentRoot /var/www/owncloud
sudo sed -i ‘s/AllowOverride None/AllowOverride All/’ /etc/apache2/apache2.conf
sudo systemctl restart apache2
Configure the Apache web server for ownCloud. This setups ownCloud as the default thing to go to when you point your web browser at your rPi. More advanced users out there may choose to set this part up a bit different.
sudo sed -i "s#html#owncloud#" /etc/apache2/sites-available/000-default.conf
sudo service apache2 restart
Setup the ownCloud web server configuration. This command will open the Nano text editor. Feel free to use any text editor you like.
sudo nano /etc/apache2/sites-available/owncloud.conf
Enter this text into the file and save.
Alias /owncloud "/var/www/owncloud/"
<Directory /var/www/owncloud/>
Options +FollowSymlinks
AllowOverride All
<IfModule mod_dav.c>
Dav off
<IfModule>
SetEnv HOME /var/www/owncloud
SetEnv HTTP_HOME /var/www/owncloud
</Directory>
Setup a database for ownCloud. We’re using MariaDB here, which is pretty much MySQL for #reasons. As this is running on a server on my network, I decided to run the secure setup as detailed here.
sudo mysql_secure_installation
You’ll be asked a short series of questions:
Press enter to continue (no password by default)
Then type “Y” to set a new password, and enter the password of your choice
Now, press “Y” three times to:
Remove anonymous users
Disallow root login remotely
Remove the test database
And finally, press “Y” again to reload the privileges
That’s it, this time MariaDB is ready to use with to root login. Or so you’d think!
At this point we run into another one of those issues created by juggling so many slightly different open source projects run by different people while we are working to rig up our own slightly special thing. The ownCloud will not be able to log into the database server at this point for reasons, but we’ll follow these instructions to fix that.
sudo mysql -u root -p
Now you’ll be at the command line of the MariaDB (MySQL) server. The next series of commands are in that syntax, and you’ll notice that it doesn’t process a command until it ends with a “;” character. First we’re going to switch to the mysql database itself and set the plugin to mysql_native_password for the root user.
USE mysql;
UPDATE user SET plugin='mysql_native_password' WHERE User='root';
FLUSH PRIVILEGES;
We need to change the root password for this to work. You can use the same one if you’d like.
ALTER USER 'root'@'localhost' IDENTIFIED BY 'YOUR-PASSWORD-HERE';
Ok, now we can exit MariaDB by pressing control-d or typing exit.
Next we restart the database server:
sudo systemctl restart mysql
Ok, now we log back into MariaDB and continue the database setup.
sudo mysql -u root -p
It will ask for the root password you set above. Now we’re going to create the ownCloud database and database user. NOTE: we are just setting this machine up for ownCloud. Down the line if you want other services and users on this machine you may want to fiddle with the users and permissions.
create database owncloud;
grant usage on *.* to owncloud@localhost identified by 'YOUR-PASSWORD-HERE';
grant all privileges on owncloud.* to owncloud@localhost ;
If you did that properly and didn’t generate any error messages you should be ready to go. Let’s test it by pressing control-d or typing exit to exit MariaDB and try logging in to the database:
mysql -u owncloud -p'YOUR-PASSWORD-HERE' owncloud
No error messages? Excellent! Now exit the database server by pressing control-d or typing exit.
Enable Apache modules. The second command there restarts Apache.
sudo a2enmod dir env headers mime rewrite setenvif
sudo service apache2 reload
Install/configure ownCloud.
Next, we need to add the www-data user to the www-data group.
sudo usermod -a -G www-data www-data
cd /var/www/
sudo wget https://download.owncloud.com/server/stable/owncloud-10.13.4.tar.bz2
sudo tar -xvf owncloud-10.13.4.tar.bz2
sudo chown -R www-data:www-data owncloud
Setup an ownCloud admin account. We are here! OwnCloud should now be running! On the rPi desktop go: http://localhost
the admin user name you’d like
an admin user password
you can leave the ownCloud file data folder as-is for now and fool with it later if you feel the need
database user: owncloud
database password: YOUR-PASSWORD-YOU-SET-EARLIER
database name: owncloud
host: localhost
Now you can log into the ownCloud web UI with the account you just set up! Go ahead and poke around. Personally, I like to setup user accounts separate from the “admin” accounts, but you don’t have to if you don’t want to. Next:
Generate letsEncrypt Certficate:
sudo apt install certbot
sudo certbot certonly --manual --preferred-challenges dns -d *.DOMAIN
Edit certificate path
sudo mousepad /etc/apache2/sites-available/default-ssl.conf
Restart Apache
sudo systemctl restart apache2
Add Cronjob for www-data
sudo crontab -u www-data -e
* * * * * /usr/bin/php -f /var/www/owncloud/occ system:cron
ctrl+X, Y
Thats it
===================================================================================
Errors Handling
The "Strict-Transport-Security" HTTP header is not configured to at least "15552000" seconds
sudo mousepad /etc/apache2/sites-available/default-ssl.conf
Add to bottom
<IfModule mod_headers.c>
Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"
</IfModule>
sudo systemctl restart apache2
Memory Error
Install APCu
sudo apt install php-apcu
sudo mousepad /var/www/owncloud/config/config.php
Within this file, find the following line and add the block of text below it.
Find
'installed' => true,
Add Below
'files_external_allow_create_new_local' => true,
'memcache.local' => '\OC\Memcache\APCu',
'memcache.locking' => '\OC\Memcache\Redis',
'redis' => [
'host' => 'localhost',
'port' => 6379,
],
sudo systemctl restart apache2
===================================================================================
Owncloud opens in php script:
To fix this, open up /etc/apache2/mods-enabled/php7.2.conf. You must comment or delete the tag block at the bottom that reads
<IfModule mod_userdir.c>
<Directory /home/*/public_html>
php_admin_flag engine Off
</Directory>
</IfModule>
sudo nano /etc/php/php7.4/apache2/php.ini
Then change:
short_open_tag = Off
to
short_open_tag = On
Then save and then restart apache2:
sudo systemctl restart apache2