The Blog

Uncategorized

Ubuntu 22.04 LTS + Plesk 18 + PHP 8.1 + Symfony 6.1 and so on

Posted on

First issue after installing all of that was symfony-cli could not find Plesk’s PHP, this fixed it.

sudo ln -s /opt/plesk/php/8.0/bin/php /usr/local/bin/php

Next issue was “KnpMenuBundle” in 6.1 it needs to be used as a service, see here. Also if you want custom template the path needs to be set this way; if your template is in “templates/Menu/knp_menu.html.twig”

#config/packages/knp_menu.yaml

knp_menu:
    # use 'twig: false' to disable the Twig extension and the TwigRenderer
    twig:
        template: Menu/knp_menu.html.twig
    #  if true, enables the helper for PHP templates
    templating: false
    # the renderer to use, list is also available by default
    default_renderer: twig

Another issue was, how to use raw SQL in symfony 6, very simple thanks to auto-wiring.

https://symfonycasts.com/screencast/doctrine-queries/raw-sql-queries


Posted in Symfony 6, Uncategorized Leave a comment

Running multiple instances of MySQL on the same server.

Posted on

Starting point.

Below is another alternative, but this one seems to be a better way to go.

https://www.percona.com/blog/2014/08/26/mysqld_multi-how-to-run-multiple-instances-of-mysql/

Above needs to be done in my.cnf and not the “.d” folders.

Copy /etc/mysql/my.cnf to /etc/mysql/my2.cnf
Also copy conf.d and mysql.conf.d to conf2.d and mysql.conf2.d
Update all the files in them to point to new data location and lock file needs to be in the /tmp/ location.

Pointing to the New Data Location

MySQL has several ways to override configuration values. By default, the datadir is set to /var/lib/mysql in the /etc/mysql/mysql.conf.d/mysqld.cnf file. Edit this file to reflect the new data directory:

sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf 

Find the line that begins with datadir= and change the path which follows to reflect the new location.

In our case, the updated file looks like the output below:/etc/mysql/mysql.conf.d/mysqld.cnf

. . .
datadir=/var/lib/mysql2
. . .

This seems like the right time to bring up MySQL again, but there’s one more thing to configure before we can do that successfully.

Step 3 — Configuring AppArmor Access Control Rules

We’ll need to tell AppArmor to let MySQL write to the new directory by creating an alias between the default directory and the new location. To do this, edit the AppArmor alias file:

sudo nano /etc/apparmor.d/tunables/alias

At the bottom of the file, add the following alias rule:/etc/apparmor.d/tunables/alias

. . .
alias /var/lib/mysql/ -> /var/lib/mysql2/,
. . .

For the changes to take effect, restart AppArmor:

sudo systemctl restart apparmor

Now we can start new MySQL

shell> mysqld_safe --defaults-file=/etc/mysql/mysql2.cnf &

Posted in Uncategorized Leave a comment

MySQL replication and IP address change

Posted on

In the recent past, for a variety of reasons, I occasionally had to change the IP address of a MySQL master in a replicated environment.

It was a major annoyance that it was not sufficient to just change the IP address in the MySQL configuration file for slaves and then restart the server. Instead, I basically had to start from scratch, setting up replication anew. There had to be an easier way.

Well, there is. What you basically need to do is ensure that the slave is fully caught up (to the point when it was disconnected from the master). Then, stop the slave, adjust slave parameters, and restart.

Which parameters, you ask? Well, the address of the master, the name of the master log file, and the position within the file. The latter two can be obtained by viewing the slave status:

mysql> SHOW SLAVE STATUS\G
*************************** 1. row ***************************
             Slave_IO_State: Reconnecting after a failed master event read
                Master_Host: 10.0.0.1
                Master_User: replicate
                Master_Port: 3306
              Connect_Retry: 60
            Master_Log_File: mysql-bin.000005
        Read_Master_Log_Pos: 11622542
             Relay_Log_File: mysqld-relay-bin.000074
              Relay_Log_Pos: 11622679
      Relay_Master_Log_File: mysql-bin.000005
           Slave_IO_Running: No
          Slave_SQL_Running: Yes
            Replicate_Do_DB:
        Replicate_Ignore_DB: mythconverg
         Replicate_Do_Table:
     Replicate_Ignore_Table:
    Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
                 Last_Errno: 0
                 Last_Error:
               Skip_Counter: 0
        Exec_Master_Log_Pos: 11622542
            Relay_Log_Space: 11622679
            Until_Condition: None
             Until_Log_File:
              Until_Log_Pos: 0
         Master_SSL_Allowed: No
         Master_SSL_CA_File:
         Master_SSL_CA_Path:
            Master_SSL_Cert:
          Master_SSL_Cipher:
             Master_SSL_Key:
      Seconds_Behind_Master: NULL
1 row in set (0.00 sec)

The next step is to stop the slave:

mysql> STOP SLAVE;

Next comes the aforementioned change of replication parameters, which can be accomplished by issuing the following command:

mysql> CHANGE MASTER TO MASTER_HOST='192.168.1.1',
MASTER_LOG_FILE='mysql-bin.000005', MASTER_LOG_POS=11622542;

The value of MASTER_HOST is, of course, the new IP address of the master. The MASTER_LOG_FILE and MASTER_LOG_POS values come from the output SHOW SLAVE STATUS command above.

Finally, restart the slave:

mysql> START SLAVE;

That’s it. Do verify though that the slave is working properly by reissuing the SHOW SLAVE STATUS command a few times, watching as the slave catches up with the master.

Posted in Uncategorized Leave a comment
Next Page »