NextCloud:Install di LAMP Stack
1. Download NextCloud on Ubuntu 20.04
Log into your Ubuntu 20.04 server. Then download the NextCloud zip archive onto your server. The latest stable version is 21.0.1 at time of this writing. You may need to change the version number. Go to https://nextcloud.com/install and click the download for server button to see the latest version.
You can run the following command to download it on your server.
wget https://download.nextcloud.com/server/releases/nextcloud-21.0.1.zip
Once downloaded, extract the archive with unzip.
sudo apt install unzip
sudo unzip nextcloud-21.0.1.zip -d /var/www/
The -d option specifies the target directory. NextCloud web files will be extracted to /var/www/nextcloud/. Then we need to change the owner of this directory to www-data so that the web server (Apache) can write to this directory.
sudo chown www-data:www-data /var/www/nextcloud/ -R
2. Create a Database and User for Nextcloud in MariaDB Database Server
Log into MariaDB database server with the following command. Since MariaDB is now using unix_socket plugin to authentication user login, there’s no need to enter MariaDB root password. We just need to prefix the mysql command with sudo.
sudo mysql
Then create a database for Nextcloud. This tutorial name the database nextcloud. You can use whatever name you like.
create database nextcloud;
Create the database user. Again, you can use your preferred name for this user. Replace your-password with your preferred password.
create user nextclouduser@localhost identified by 'your-password';
Grant this user all privileges on the nextcloud database.
grant all privileges on nextcloud.* to nextclouduser@localhost identified by 'your-password';
Flush privileges and exit.
flush privileges;
exit;
3. Create an Apache Virtual Host for Nextcloud
Create a nextcloud.conf file in /etc/apache2/sites-available/ directory, with a command-line text editor like Vim.
sudo vim /etc/apache2/sites-available/nextcloud.conf
Copy and paste the following text into the file. Replace nextcloud.example.com with your own preferred sub-domain. Don’t forget to create DNS A record for this sub-domain in your DNS zone editor. If you don’t have a real domain name, I recommend going to NameCheap to buy one. The price is low and they give whois privacy protection free for life.
<VirtualHost *:80>
DocumentRoot "/var/www/nextcloud"
ServerName nextcloud.example.com
ErrorLog ${APACHE_LOG_DIR}/nextcloud.error
CustomLog ${APACHE_LOG_DIR}/nextcloud.access combined
<Directory /var/www/nextcloud/>
Require all granted
Options FollowSymlinks MultiViews
AllowOverride All
<IfModule mod_dav.c>
Dav off
</IfModule>
SetEnv HOME /var/www/nextcloud
SetEnv HTTP_HOME /var/www/nextcloud
Satisfy Any
</Directory>
</VirtualHost>
Save and close the file.
Then enable this virtual host.
sudo a2ensite nextcloud.conf
Run the following command to enable required Apache modules.
sudo a2enmod rewrite headers env dir mime setenvif ssl
Then test Apache configuration.
sudo apache2ctl -t
If the syntax is OK, reload Apache for the changes to take effect.
sudo systemctl restart apache2
4. Install and Enable PHP Modules
Run the following commands to install PHP modules required or recommended by NextCloud.
sudo apt install imagemagick php-imagick libapache2-mod-php7.4 php7.4-common php7.4-mysql php7.4-fpm php7.4-gd php7.4-json php7.4-curl php7.4-zip php7.4-xml php7.4-mbstring php7.4-bz2 php7.4-intl php7.4-bcmath php7.4-gmp
Reload Apache to use these modules.
sudo systemctl reload apache2
5. Enable HTTPS
Before entering any sensitive information, we should enable secure HTTPS connection on Nextcloud. We can obtain a free TLS certificate from Let’s Encrypt. Install Let’s Encrypt client (certbot) from Ubuntu 20.04 repository.
sudo apt install certbot python3-certbot-apache
Python3-certbot-apache is the Apache plugin. Next, run the following command to obtain a free TLS certificate using the Apache plugin.
sudo certbot --apache --agree-tos --redirect --staple-ocsp --email you@example.com -d nextcloud.example.com
sudo systemctl reload apache2