TR

NXRADIFY BLOG

Published August 27, 2024- 8 min read

Nextcloud PHP8.3 MySQL/MariaDB Apache

Linux Software PHP MySQL MariaDB Apache
nextcloud

Introduction

Here is a detailed guide to installing Nextcloud with PHP 8.3 on a Linux server, using Ubuntu Server and MariaDB as the database.

Step 1: Update the Server

Start by updating your system:

sudo apt update && sudo apt upgrade -y

Step 2: Install PHP 8.3 and Required Extensions

To run Nextcloud, you need PHP 8.3 and several extensions:

Adding the PHP 8.3 Repository

First, add the `ppa:ondrej/php` repository to get PHP 8.3:

sudo add-apt-repository ppa:ondrej/php
sudo apt update

Installing PHP 8.3 and Extensions

Install PHP 8.3 and the necessary extensions:

sudo apt install Apache libapache2-mod-php8.3 -y
sudo apt install php8.3 php8.3-gd php8.3-mysql php8.3-curl php8.3-mbstring php8.3-intl php8.3-imagick php8.3-xml php8.3-zip php8.3-bz2 php8.3-apcu -y

PHP extensions functionalities:

Each of these PHP extensions is required for different Nextcloud functionalities:

- `php8.3-gd`: Image processing library.

- `php8.3-mysql`: MySQL/MariaDB connection.

- `php8.3-curl`: URL transfer library.

- `php8.3-mbstring`: Multi-byte string handling.

- `php8.3-intl`: Internationalization functions.

- `php8.3-imagick`: Image processing.

- `php8.3-xml`: XML processing.

- `php8.3-zip`: ZIP archiving.

- `php8.3-bz2`: Bzip2 compression support.

- `php8.3-apcu`: APCu caching support.

Verify PHP Version

Check that PHP 8.3 was installed correctly:

php -v

Step 3: Install and Configure MariaDB Database

Install MariaDB:

sudo apt install mariadb-server -y

Secure MariaDB Installation

Secure the MariaDB installation:

sudo mysql_secure_installation

This wizard helps you set the root password, remove anonymous users, disable remote root login, and delete the test database.

Create a Database for Nextcloud

Log into MariaDB and create a database and user for Nextcloud:

sudo mysql -u root -p

Run the following SQL commands:

CREATE DATABASE nextcloud;
CREATE USER 'nextclouduser'@'localhost' IDENTIFIED BY 'your_password';

Replace `your_password` with a strong password.

GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextclouduser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Step 4: Download and Install Nextcloud

Download Nextcloud

Download and unzip the latest Nextcloud release:

wget https://download.nextcloud.com/server/releases/nextcloud-29.0.5.zip
unzip nextcloud-29.0.5.zip
sudo mv nextcloud /var/www/

Set File Permissions

Set the appropriate permissions for Apache to access the Nextcloud files:

sudo chown -R www-data:www-data /var/www/nextcloud/
sudo chmod -R 755 /var/www/nextcloud/

Step 5: Configure Apache Web Server

To run Nextcloud on Apache, create a configuration file:

Apache Nextcloud Configuration File

Create a new virtual host file for Nextcloud:

sudo nano /etc/Apache/sites-available/nextcloud.conf

Paste the following content:

<VirtualHost *:80>
    DocumentRoot /var/www/nextcloud/
    ServerName your-domain.com

    <Directory /var/www/nextcloud/>
        Options +FollowSymlinks
        AllowOverride All

        <IfModule mod_dav.c>
            Dav off
        </IfModule>

        SetEnv HOME /var/www/nextcloud
        SetEnv HTTP_HOME /var/www/nextcloud
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/nextcloud_error.log
    CustomLog ${APACHE_LOG_DIR}/nextcloud_access.log combined
</VirtualHost>

Enable Apache Modules

Enable the necessary Apache modules:

sudo a2ensite nextcloud.conf
sudo a2enmod rewrite headers env dir mime

Restart Apache:

sudo systemctl restart Apache

Step 6: SSL Setup (Optional)

For security, enable HTTPS using an SSL certificate from Let's Encrypt or another provider.

Install Let's Encrypt SSL Certificate

You can install a free SSL certificate from Let's Encrypt:

sudo apt install certbot python3-certbot-apache -y
sudo certbot --apache

Step 7: Complete Nextcloud Setup via Web Interface

Open your web browser and navigate to `http://your-domain.com`. The Nextcloud setup wizard should appear.

Database Configuration


- **Database user**: `nextclouduser`
- **Database password**: `your_password`
- **Database name**: `nextcloud`
- **Database host**: `localhost`
            

Complete the setup to start using Nextcloud.

Step 8: Security and Performance Improvements (Optional)

You can take some additional steps to secure your Nextcloud installation and improve performance:

1. Security Improvements

Review the security settings recommended by Nextcloud:

  • Protect `.htaccess` files: Ensure that the `.htaccess` files in the Nextcloud root directory are working correctly by making sure the `AllowOverride All` setting is enabled in your Apache configuration.
  • Review security and setup warnings: Apply the recommended security settings in the Nextcloud admin interface.

2. Performance Improvements

To enhance the performance of Nextcloud, follow these steps:

  • Enable APCu Caching: Install the `php8.3-apcu` package to enable APCu caching.
  • Install Redis: You can use Redis for file locking and caching by installing it:
  • sudo apt install redis-server php8.3-redis -y

    Edit the `config.php` file to add Redis to Nextcloud:

    'memcache.locking' => '\\OC\\Memcache\\Redis',
            'redis' => [
              'host' => 'localhost',
              'port' => 6379,
              ],

3. Scheduled Tasks (Cron Jobs)

Set up a cron job to ensure that Nextcloud performs maintenance tasks on time:

sudo crontab -u www-data -e

Add the following line:

*/5 * * * * php -f /var/www/nextcloud/cron.php

Conclusion

Following these steps, you will have a fully functional Nextcloud instance running with PHP 8.3.

This website uses cookies to ensure you get the best experience on our website. By continuing to browse, you consent to the use of cookies.
Cookie Settings

Cookie Preferences

You can choose which types of cookies to allow: