Wordpress installation on Nethserver (multiple vhosts)

Don’t worry. Going through the document, you will see almost everything about WordPress and will be a pro.

Michel-André

It seems to be a fault. I think, I will start new with installation in the standard directory and a second within the vhost directory according to chapter XIII.
:unamused:

I tried to install Wordpress in a vhost and the default vhost (/var/www/html/) and got it working.

WARNING! This is just to install Wordpress without any security considerations so please secure Wordpress afterwards with setting permissions and tutorials like this.

General:

Install required packages:

yum -y install nethserver-httpd-virtualhosts nethserver-mysql
yum -y install http://mirror.de-labrusse.fr/NethServer/7/x86_64/nethserver-stephdl-1.1.1-1.ns7.sdl.noarch.rpm
yum -y install http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
yum -y install nethserver-php-scl --enablerepo=stephdl,remi-safe

Get latest wordpress and extract the files:

wget https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz

VHost install:

Create vhost (I used wordpress.local as domain name) with PHP73:

Get virtualhost dir (In my case /var/lib/nethserver/vhost/018e8516e24524b/):

Copy files to virtualhost location and set necessary permission for installing wordpress:

\cp -R wordpress/* /var/lib/nethserver/vhost/018e8516e24524b/
chown apache:apache /var/lib/nethserver/vhost/018e8516e24524b

Create database wordpress1 with user wordpress1 and password SECRET.
You may use phpmyadmin if you like UI.

mysql
create database wordpress1;
create user 'wordpress1'@'localhost' identified by 'SECRET';
grant all privileges on wordpress1.* TO 'wordpress1'@'localhost';
exit

Browse to https://VHOST_DOMAIN_NAME and follow the installer…

/var/www/html / default vhost install:

Go to legacy server manager and enable PHP74 for the default vhost to avoid the blank/white page error.
IIRC there are issues with old server manager because it’s not fully compatible with PHP7+.
If you still use the old server manager, you may use 2 vhosts instead of 1 and the default vhost to avoid problems.

Copy files to /var/www/html and set necessary permission for installing wordpress:

\cp -R wordpress/* /var/www/html/
chown apache:apache /var/www/html

It’s also possible to use the same database for both Wordpress installs, in this case change the Wordpress db_prefix in the installer.

Here we create a separate DB and user:

mysql
create database wordpress2;
create user 'wordpress2'@'localhost' identified by 'SECRET';
grant all privileges on wordpress2.* TO 'wordpress2'@'localhost';
exit

Browse to https://NETH_IP_OR_FQDN and follow the installer.

Reset webroot permissions:

chown root:root /var/www/html
chown ftp:apache /var/lib/nethserver/vhost/018e8516e24524b

As @michelandre mentioned here you need the following to be able to update the wordpress installs:

chown -R apache:apache /var/www/html
chown -R apache:apache /var/lib/nethserver/vhost/018e8516e24524b
3 Likes

Hi Makus,

You have to also chown for the /var/www/html/ to apache:apache or you will have problem updating WordPress. I use chown -R to change also the content of the html directory.
I think WordPress uses its own “FTP” or something else to download files…

I also secure a little bit more the WordPress root directory with an .htaccess file.

Question:
Why there is a number for the vhost directory? (/var/lib/nethserver/vhost/018e8516e24524b/)
It always use the Name I give to the vhost as in the picture in my reply #50 above.

Michel-André

1 Like

I just wanted to provide a way to install it without further thinking about security or updating. Thanks for your inputs. I updated my post.

I think if you do it with old server manager a name is set.
If you use new server manager (cockpit) a secure name is used so the vhost dir is not guessable for bad guys.

1 Like

Hi Markus,

You are right again.

I always use the old Manager (980) for the creation of a vhost.
Easier to see which vhost is which with a name than with a number. :wink:

Michel-André

1 Like

Thank you @mrmarkuz and @stephdl
I combined your howto with Stephans manual and installed Wordpress within my vhost with real FQDN.

my current state:

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| phpmyadmin         |
| wordpress1         |
+--------------------+ 
MariaDB [(none)]> SELECT User FROM mysql.user;
+----------------+
| User           |
+----------------+
| root           |
| root           |
| admin          |
| phpmyadmin     |
| root           |
| wordpressuser1 |
+----------------+
MariaDB [(none)]> SHOW GRANTS FOR 'wordpressuser1'@'localhost';
+-----------------------------------------------------------------------------------------------------------------------+
| Grants for wordpressuser1@localhost                                                                                   |
+-----------------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'wordpressuser1'@'localhost' IDENTIFIED BY PASSWORD '*9D########9E' |
+-----------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

MariaDB [(none)]>


Inside the webserver log I cannot find an entry.

I have no firewall, IPS or such stuff installed, that could block access.

Access to the directory and files should be possible:

[root@ns-srv01 bd0####937d]# ls -alsd /var/lib/nethserver/vhost/bd#####937d
4 drwxr-sr-x 6 apache apache 4096 Oct  8 15:55 /var/lib/nethserver/vhost/bd0####937d

[root@ns-srv01 bd0######937d]# ls -als
total 208
 4 drwxr-sr-x  6 apache apache  4096 Oct  8 15:55 .
 0 drwxr-xr-x  3 root   root      50 Oct  8 15:55 ..
 4 -rw-r-----  1 apache apache   405 Feb  6  2020 index.php
20 -rw-r-----  1 apache apache 19915 Feb 12  2020 license.txt
 8 -rw-r-----  1 apache apache  7278 Jun 26 15:58 readme.html
 0 drwxr-x---  2 apache apache     6 Oct  8 15:54 wordpress
 8 -rw-r-----  1 apache apache  7101 Jul 28 19:20 wp-activate.php
 4 drwxr-x---  9 apache apache  4096 Sep  1 20:54 wp-admin
 4 -rw-r-----  1 apache apache   351 Feb  6  2020 wp-blog-header.php
 4 -rw-r-----  1 apache apache  2332 Jul 23 02:52 wp-comments-post.php
 4 -rw-r-----  1 apache apache  2913 Feb  6  2020 wp-config-sample.php
 0 drwxr-x---  6 apache apache    84 Oct  8 16:17 wp-content
 4 -rw-r-----  1 apache apache  3940 Feb  6  2020 wp-cron.php
12 drwxr-x--- 24 apache apache  8192 Sep  1 20:54 wp-includes
 4 -rw-r-----  1 apache apache  2496 Feb  6  2020 wp-links-opml.php
 4 -rw-r-----  1 apache apache  3300 Feb  6  2020 wp-load.php
48 -rw-r-----  1 apache apache 48761 Jul  7 05:59 wp-login.php
12 -rw-r-----  1 apache apache  8509 Apr 14 13:32 wp-mail.php
20 -rw-r-----  1 apache apache 20181 Jul  6 12:50 wp-settings.php
32 -rw-r-----  1 apache apache 31159 Jul 23 23:11 wp-signup.php
 8 -rw-r-----  1 apache apache  4755 Feb  6  2020 wp-trackback.php
 4 -rw-r-----  1 apache apache  3236 Jun  8 21:55 xmlrpc.php
[root@ns-srv01 bd0######937d]#

What could be happening there?
Best regards Marko

Hi Marko,

Maybe the Datenbank-Host should be 127.0.0.1:port-number.

Michel-André

That doesn’t help.

Hi Marko,

Which port number you used ?

Michel-André

if I manually edit the wp-config.php

Error establishing a database connection

because possible typos I changed the user password --> same behavior

[root@ns-srv01 bd0###937d]# config show rh-mariadb102-mariadb
rh-mariadb102-mariadb=configuration
LocalNetworkingOnly=no
MaxAllowedPacket=16M
TCPPort=3312
access=private
status=enabled

Hi Marko,

The error is from MariaDB.

It looks that you used standard MariaDB for your DB.
You have to use mysql102 to enter the MariaDB console and to create the DB etc…

Then, in the wp-config.php, you have to specify 127.0.0.1:3312

Michel-André

1 Like

great - that solves that problem!

here the next one:

Can’t select database

We were able to connect to the database server (which means your username and password is okay) but not able to select the wordpress1 database.

  • Are you sure it exists?
  • Does the user wordpressuser1 have permission to use the wordpress1 database?
  • On some systems the name of your database is prefixed with your username, so it would be like username_wordpress1 . Could that be the problem?

But I granted the user

MariaDB [(none)]> SHOW GRANTS FOR 'wordpressuser1'@'localhost';
+-----------------------------------------------------------------------------------------------------------------------+
| Grants for wordpressuser1@localhost                                                                                   |
+-----------------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'wordpressuser1'@'localhost' IDENTIFIED BY PASSWORD '*00A###0C9' |
+-----------------------------------------------------------------------------------------------------------------------+

I can use the user worpress1 to get access via PHPmyAdmin.

edit:
oh sorry, that’s wrong… I have access but cannot see the datdabase in the list
image

Hi Marko,

It still looks like you are in the standard Mariadb console, it should display Server version: 10.2.22-MariaDB MariaDB Server.

I will start my WordPress VM and check the MariaDB prompt in the console.

Michel-André

I used mysql102
image
This is wrong?

Please have a look at my editing in my previous posting.

Hi Marko,

EDITED:

# mysqladmin102 CREATE wordpress1

################################################################

# mysql102

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.2.8-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

################################################################

MariaDB [(none)]> show databases;

+--------------------+
| Database           |
+--------------------+
| wordpress1         |
| information_schema |
| mysql              |
| performance_schema |
| phpmyadmin         |
+--------------------+
5 rows in set (0.02 sec)

################################################################

MariaDB [(none)]> grant all on wordpress1.* to wordpressuser1@localhost identified by 'Password';

Query OK, 0 rows affected (0.00 sec)

################################################################

MariaDB [(none)]> show grants for wordpressuser1@localhost;

+------------------------------------------------------------------------------------------+
| Grants for wordpressuser1@localhost                                                                                   |
+------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'wordpressuser1'@'localhost' IDENTIFIED BY PASSWORD '*BEB075ED0A4C05AB21866C4BAA23F5284D8CF90B' |
| GRANT ALL PRIVILEGES ON `wordpress1`.* TO 'wordpressuser1'@'localhost'                                                      |
+------------------------------------------------------------------------------------------+
2 rows in set (0,00 sec)

################################################################

...
/** Nom de la base de données de WordPress. */
define('DB_NAME', 'wordpress1');

/** Utilisateur de la base de données MySQL. */
define('DB_USER', 'wordpressuser1');

/** Mot de passe de la base de données MySQL. */
define('DB_PASSWORD', 'Password');
/** Adresse de l’hébergement MySQL. */
define('DB_HOST', '127.0.0.1:3312');
...

Michel-André

Ok… next try
I dropped wordpress1 / user-dropping was not possible

MariaDB [(none)]> DROP USER wordpress1@localhost;
ERROR 1396 (HY000): Operation DROP USER failed for 'wordpress1'@'localhost'

New datebase and user:
[root@ns-srv01 bd##937d]# mysqladmin102 CREATE wordpress2
[root@ns-srv01 bd##937d]# mysql102
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 60
Server version: 10.2.22-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| phpmyadmin         |
| wordpress2         |
+--------------------+
5 rows in set (0.00 sec)

MariaDB [(none)]> grant all on wordpress2.* to wordpressuser2@localhost identified by '12345';
Query OK, 0 rows affected (0.00 sec)

HURRA!

Can you please explain me the difference?
I don’t really understand your comment

It still looks like you are in the standard Mariadb console, it should display MariaDB102

Because I started my database creating process also with

mysql102

Hi Marko,

My memory is like yours, sometime if forgets :slight_smile:

My error, it should be MariaDB [(none)]>.

The show databases; should have displayed also your first DB, i.e. wordpress1.
If you try mysql and then show databases; the old DB should be there and not the new one i.e. wordpress2.

Also, I usually create the DB outside the MariaDB console using:
mysqladmin102 CREATE database-name

Then, I enter the MariaDB console wiht mysql102, then show databases; for verification.
But you can also create the DB inside the MariaDB console.
Just a matter of choice.

The standard MariaDB is:

# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.65-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

Note the version number.

For MariaDB-102:

# mysql102
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.2.22-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

Michel-André

1 Like