mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 01:25:55 +02:00
Improved docs for MySQL database
This commit is contained in:
parent
cde5fbb94b
commit
50e8529889
2 changed files with 80 additions and 12 deletions
|
@ -86,6 +86,10 @@ The docker image uses a SQLite database and all data (database, uploads and othe
|
|||
|
||||
If you want to use MySQL as a database, you can use the following docker-compose.yaml, and follow the steps from above:
|
||||
|
||||
{: .warning }
|
||||
> You have to replace the values for MYSQL_ROOT_PASSWORD and MYSQL_PASSWORD with your own passwords!!
|
||||
> You have to change MYSQL_PASSWORD in the database section and for the DATABASE_URL in the partdb section.
|
||||
|
||||
```yaml
|
||||
version: '3.3'
|
||||
services:
|
||||
|
@ -104,7 +108,7 @@ services:
|
|||
depends_on:
|
||||
- database
|
||||
environment:
|
||||
# Put SQLite database in our mapped folder. You can configure some other kind of database here too.
|
||||
# Replace SECRET_USER_PASSWORD with the value of MYSQL_PASSWORD from below
|
||||
- DATABASE_URL=mysql://partdb:SECRET_USER_PASSWORD@database:3306/partdb
|
||||
# In docker env logs will be redirected to stderr
|
||||
- APP_ENV=docker
|
||||
|
@ -151,6 +155,15 @@ services:
|
|||
|
||||
```
|
||||
|
||||
### Update Part-DB
|
||||
You can update Part-DB by pulling the latest image and restarting the container.
|
||||
Then you have to run the database migrations again
|
||||
```bash
|
||||
docker-compose pull
|
||||
docker-compose up -d
|
||||
docker exec --user=www-data partdb php bin/console doctrine:migrations:migrate
|
||||
```
|
||||
|
||||
## Direct use of docker image
|
||||
You can use the `jbtronics/part-db1:master` image directly. You have to expose the port 80 to a host port and configure volumes for `/var/www/html/uploads` and `/var/www/html/public/media`.
|
||||
|
||||
|
|
|
@ -13,14 +13,15 @@ Depending on what you want to do, using the prebuilt docker images may be a bett
|
|||
> The methods described here, configure PHP without HTTPS and therefore should only be used locally in a trusted network.
|
||||
> If you want to expose Part-DB to the internet, you HAVE to configure an SSL connection!
|
||||
|
||||
## Installation with SQLite database
|
||||
|
||||
## Install prerequisites
|
||||
### Install prerequisites
|
||||
For the installation of Part-DB, we need some prerequisites. They can be installed by running the following command:
|
||||
```bash
|
||||
sudo apt install git curl zip ca-certificates software-properties-common apt-transport-https lsb-release nano wget
|
||||
```
|
||||
|
||||
## Install PHP and apache2
|
||||
### Install PHP and apache2
|
||||
Part-DB is written in [PHP](https://php.net) and therefore needs an PHP interpreter to run. Part-DB needs PHP 7.3 or higher, however it is recommended to use the most recent version of PHP for performance reasons and future compatibility.
|
||||
|
||||
As Debian 11 does not ship PHP 8.1 in it's default repositories, we have to add a repository for it. You can skip this step if your distribution is shipping a recent version of PHP or you want to use the built-in PHP version.
|
||||
|
@ -37,7 +38,7 @@ sudo apt install php8.1 libapache2-mod-php8.1 php8.1-opcache php8.1-curl php8.1-
|
|||
```
|
||||
The apache2 webserver should be already installed with this command and configured basically.
|
||||
|
||||
## Install composer
|
||||
### Install composer
|
||||
Part-DB uses [composer](https://getcomposer.org/) to install required PHP libraries. As the versions shipped in the repositories is pretty old we install it manually:
|
||||
```bash
|
||||
# Download composer installer script
|
||||
|
@ -48,7 +49,7 @@ php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer
|
|||
chmod +x /usr/local/bin/composer
|
||||
```
|
||||
|
||||
## Install yarn and nodejs
|
||||
### Install yarn and nodejs
|
||||
To build the frontend (the user interface) Part-DB uses [yarn](https://yarnpkg.com/). As it dependens on nodejs and the shipped versions are pretty old, we install new versions from offical nodejs repository:
|
||||
```bash
|
||||
# Add recent node repository (nodejs 18 is supported until 2025)
|
||||
|
@ -66,7 +67,7 @@ echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/deb
|
|||
sudo apt update && sudo apt install yarn
|
||||
```
|
||||
|
||||
## Create a folder for Part-DB and download it
|
||||
### Create a folder for Part-DB and download it
|
||||
We now have all prerequisites installed and can start to install Part-DB. We will create a folder for Part-DB in a webfolder of apache2 and download it to this folder. The downloading is done via git, which allows you to update easily later.
|
||||
```bash
|
||||
# Download Part-DB into the new folder /var/www/partdb
|
||||
|
@ -83,7 +84,7 @@ For the next steps we should be in the Part-DB folder, so move into it:
|
|||
cd /var/www/partdb
|
||||
```
|
||||
|
||||
## Create configuration for Part-DB
|
||||
### Create configuration for Part-DB
|
||||
The basic configuration of Part-DB is done by a `.env.local` file in the main directory. Create on by from the default configuration:
|
||||
```bash
|
||||
cp .env .env.local
|
||||
|
@ -94,7 +95,7 @@ Other configuration options like the default language or default currency can be
|
|||
|
||||
Please check that the `partdb.default_currency` value in `config/parameters.yaml` matches your mainly used currency, as this can not be changed after creating price informations.
|
||||
|
||||
## Install dependencies for Part-DB and build frontend
|
||||
### Install dependencies for Part-DB and build frontend
|
||||
Part-DB depends on several other libraries and components. Install them by running the following commands:
|
||||
```bash
|
||||
# Install composer dependencies (please note the sudo command, to run it under the web server user)
|
||||
|
@ -107,6 +108,7 @@ sudo yarn build
|
|||
```
|
||||
|
||||
### Clear cache
|
||||
|
||||
To ensure everything is working, clear the cache:
|
||||
```bash
|
||||
sudo -u www-data php bin/console cache:clear
|
||||
|
@ -119,7 +121,7 @@ sudo -u www-data php bin/console partdb:check-requirements
|
|||
```
|
||||
The most things should be green, and no red ones. Yellow messages means optional dependencies which are not important but can improve performance and functionality.
|
||||
|
||||
## Create a database for Part-DB
|
||||
### Create a database for Part-DB
|
||||
Part-DB by default uses a file based sqlite database to store the data. Use the following command to create the database. The database will normally created at `/var/www/partdb/var/app.db`.
|
||||
```bash
|
||||
sudo -u www-data php bin/console doctrine:migrations:migrate
|
||||
|
@ -128,7 +130,7 @@ The command will warn you about schema changes and potential data loss. Continue
|
|||
|
||||
The command will output several lines of informations. Somewhere should be a a yellow background message like `The initial password for the "admin" user is: f502481134`. Write down this password as you will need it later for inital login.
|
||||
|
||||
## Configure apache2 to show Part-DB
|
||||
### Configure apache2 to show Part-DB
|
||||
Part-DB is now configured, but we have to say apache2 to serve Part-DB as web application. This is done by creating a new apache site:
|
||||
```bash
|
||||
sudo nano /etc/apache2/sites-available/partdb.conf
|
||||
|
@ -172,7 +174,7 @@ sudo service apache2 restart
|
|||
|
||||
and Part-DB should now be available under `http://YourServerIP` (or `http://partdb.lan` if you configured DNS in your network to point on the server).
|
||||
|
||||
## Login to Part-DB
|
||||
### Login to Part-DB
|
||||
Navigate to the Part-DB web interface and login via the user icon in the top right corner. You can login using the username `admin` and the password you have written down earlier.
|
||||
|
||||
## Update Part-DB
|
||||
|
@ -199,3 +201,56 @@ sudo -u www-data php bin/console doctrine:migrations:migrate
|
|||
# Clear Part-DB cache
|
||||
sudo u www-data php bin/console cache:clear
|
||||
```
|
||||
|
||||
## MySQL/MariaDB database
|
||||
To use a MySQL database, follow the steps from above (except the creation of database, we will do this later).
|
||||
Debian 11 does not ship MySQL in its repositories anymore, so we use the compatible MariaDB instead:
|
||||
|
||||
1. Install maria-db with:
|
||||
|
||||
```bash
|
||||
sudo apt update && sudo apt install mariadb-server
|
||||
```
|
||||
|
||||
2. Configure maria-db with:
|
||||
```bash
|
||||
sudo mysql_secure_installation
|
||||
```
|
||||
When asked for the root password, just press enter, as we have not set a root password yet.
|
||||
In the next steps you are asked if you want to switch to unix_socket authentication, answer with `n` and press enter.
|
||||
Then you are asked if you want to remove anonymous users, answer with `y` and press enter.
|
||||
Then you are asked if you want to disallow root login remotely, answer with `y` and press enter.
|
||||
Then you are asked if you want to remove the test database and access to it, answer with `y` and press enter.
|
||||
Then you are asked if you want to reload the privilege tables now, answer with `y` and press enter.
|
||||
|
||||
3. Create a new database and user for Part-DB: Run the following commands:
|
||||
```bash
|
||||
sudo mariadb
|
||||
```
|
||||
A SQL shell will open, in which you can run the following commands to create a new database and user for Part-DB.
|
||||
Replace 'YOUR_SECRET_PASSWORD' with a secure password.
|
||||
```sql
|
||||
CREATE DATABASE partdb;
|
||||
GRANT ALL PRIVILEGES ON partdb.* TO 'partdb'@'localhost' IDENTIFIED BY 'YOUR_SECRET_PASSWORD';
|
||||
```
|
||||
Finally save the changes with:
|
||||
```sql
|
||||
FLUSH PRIVILEGES;
|
||||
```
|
||||
and exit the SQL shell with:
|
||||
```sql
|
||||
exit
|
||||
```
|
||||
|
||||
4. Configure Part-DB to use the new database. Open your `.env.local` file and search the line `DATABASE_URL`.
|
||||
Change it to the following (you have to replace `YOUR_SECRET_PASSWORD` with the password you have choosen in step 3):
|
||||
```
|
||||
DATABASE_URL=DATABASE_URL=mysql://partdb:YOUR_SECRET_PASSWORD@127.0.0.1:3306/partdb
|
||||
```
|
||||
|
||||
5. Create the database schema with:
|
||||
```bash
|
||||
sudo -u www-data php bin/console doctrine:migrations:migrate
|
||||
```
|
||||
|
||||
6. The migration step should have shown you a password for the admin user, which you can use now to login to Part-DB.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue