Installing Wordpress on virtualhost

NethServer Version: NS8B2

Hi,

  • I am trying to install Wordpress on a virtual host, so I have a virtual host sub.domain.com
  • I have installed NGINX and MariaDB. I created db, user and password with grants to the db via phpmyadmin.
  • I unzip Wordpress in the root of the virtual host and Wordpress
  • I adjusted wp-config.php to have the correct credentials
  • When accessing sub.domain.com I am greeted by Wordpress admin pages asking me for the db and credentials
  • I enter all the correct details and as the host ‘localhost’

The Wordpress complains it can not establish a db connection. I double checked names and credentials, all ok

Is using ‘localhost’ as a hostname the correct thing to do in container world? Or did I Make another mistake? (most likely :slight_smile: )

TIA

welcome to the world of container, you cannot use localhost here, localhost is not good, a container is like another VM somewhere, use the IP and also please take into account that your user of mariadb cannot be be restricted to localhost, use ``

 migrate web data and mariadb mysql database to ns8



https://www.comparitech.com/net-admin/sftp-commands-cheat-sheet/



how to create a user inside mariadb container, first on the node ssh to the userLinux

# connect to mariadb1 (module_id)
ssh mariadb1@localhost
# connect to the mysql container as root
podman exec -ti mariadb-app mysql
# create the database and grant user to all from any IP (external port is closed to 127.0.0.1)
MariaDB [(none)]> CREATE DATABASE IF NOT EXISTS mydatabase;
MariaDB [(none)]> grant all privileges on mydatabase.* to username identified by 'password';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit
add data to the database from a mysql dump
podman exec -i mariadb-app mysql < toto.sql

the example content of toto.mysql, like you can see the user is able to connect from any host, this is a mandatory because we connect from outside the container, but the tcp port random is restricted to localhost

 CREATE DATABASE if not exists foo;
CREATE USER if not exists 'foo' IDENTIFIED BY "foo";
GRANT ALL PRIVILEGES ON foo.* TO 'foo';
FLUSH PRIVILEGES;

use foo;
CREATE TABLE IF NOT EXISTS pages (
  id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
  title VARCHAR(30),
  content TEXT,
  INDEX(title)
) engine=InnoDB;

INSERT IGNORE INTO pages VALUES (1, 'Bienvenue', 'Bienvenue ');
then on the remote host running the web server send all local files by scp (login 9001 password 9001 for the first vhost you have created inside the ns8-webserver )

the default port is tcp 3092, think to enable the external access, the 9001 is the login of the first vhost

sftp -P 3092 9001@r1.rocky9.org
# move to you local web folder and cp everything to the vhost of NS8
lcd Téléchargements/wordpress-6.2.2-fr_FR/wordpress/
sftp> put -r *
4 Likes

Better to use the fqdn of the server and the random port

Sub.domain.com:20009

For instance

I don’t get it.

When I am going to the vhost, I see the before getting started page, telling I need all credentials of the db and user. I do

Then I enter all details and I get Ă©rror in your wp-config.php file, and if I creat the config file with correct credentials I get wp-config exists.

Looping here


Take care about the mariadb user it must be able to connect from any host

Without the error that you can find in journald we cannot help you

Thanks, dizzy about it. Will try again bit later :slight_smile:

But first, do I, or do I not create manually the wp-config.php (copy from the sample and adjust)?

Hi @LayLow

Use PhpMyAdmin to make sure the db user has a % with his name so he can connect from anywhere.
Also, give him all the rights to the DB.

Michel-André

the webinstaller should write for you the config file, just a matter to be able to connect

I recall that creating manually the user and the database works better than with phpmyadmin, I do not recall what

maybe

grant all privileges on mydatabase.* to username identified by ‘password’;

is different

grant all privileges on mydatabase.* to username@% identified by ‘password’;

phpmyadmin does not like the @% part. This is a pain for such simple task.

Use the command line with my example :slight_smile:

Ok, I’ve tried many things, but now the install is satisfied (typo, command? who knows)

But now I get a http error (mixed content)

Salut @LayLow

https://ns8.debian.toto-dev.org/phpmyadmin/.

image

.

‘usagerwpbd’@‘%’ <====== ‘%’

Michel-André

2 Likes

Merci!

Is there a way to ‘solve’ the infamous ‘Mixed content’. issue with WP by means of htaccess, thus not via an extra WP module? Examples that I found on the net did not work for me yet, maybe because these examples are not ‘container’ aware?

Salut @LayLow

What do you mean by “Mixed content” ?

Michel-André

https and http. scripts are called over http and will not load due to enforced https. It seems to be a common problem, but I do not want to solve it at application level but at webserver level.

Salut @LayLow,

Replace https with http, but I do not know if that will do what you want.

How to change a WordPress URL step-by-step - IONOS CA.
Change WordPress site URL in the admin dashboard.
The most common and easiest way to change the WordPress URL is to enter it directly in the admin dashboard. To do this, navigate to “Settings” > “General” in the admin area. There you will find the input fields where you can change the WordPress site URL or the website URL.

Michel-André

Yes, that is the case and I did change it already by advise of @stephdl in an old thread (directly in db tables). But still the mixed content, scripts are pulled in via http and thus blocked. I am the only one? (Rocky Linux)

Salut @LayLow

I run Debian-12.

Is the port 443 blocked by something ?

I remember commenting all the long keys in wp-config.php.
I do not know if it is related.

To allow the reading of all the .htaccess files (AllowOverride ALL), I am more familiar with Apache in NS-7 than with Nginx in NS8.

There is a directive in the conf file to pass the header as is, with no change, from the requesting URL, but I cannot find it anymore :frowning: . @mrmarkuz should remember and know how to use it with Nginx.

Michel-André

2 Likes

I remember the mixed content issue in combination with reverse proxy. I’m going to test it asap


3 Likes