Allows using localhost to connect to MySQL in lxc
Add 'php_conf_mysql_default_socket' variable to lxc-php role that configure both the lxc containers and PHP so that a local MySQL database may be used through localhost. The PHP containers will automount /var/run/mysqld/mysqld.sock (the default path to the mysql socket) to the path defined by the variable 'php_conf_mysql_default_socket' which will be the path used by php to contact MySQL both with mysqli and PDO_MYSQL.
This commit is contained in:
parent
977c28c720
commit
1d9ab0f1f3
Notes:
Mathieu Trossevin
2021-04-07 16:11:33 +02:00
I am not dealing with php's mysql_ extension as it has been removed in php 7.0.0 and I would rather not create a difference between the default config for php5 and php7[03].
|
@ -7,6 +7,9 @@ php_conf_html_errors: "Off"
|
|||
php_conf_allow_url_fopen: "Off"
|
||||
php_conf_disable_functions: "exec,shell-exec,system,passthru,popen"
|
||||
|
||||
# Allows accessing a local mysql database using localhost
|
||||
php_conf_mysql_default_socket: Null
|
||||
|
||||
lxc_php_version: Null
|
||||
|
||||
lxc_php_container_releases:
|
||||
|
|
|
@ -18,8 +18,15 @@
|
|||
dest: "/var/lib/lxc/{{ lxc_php_version }}/rootfs/etc/mailname"
|
||||
notify: "Restart opensmtpd"
|
||||
|
||||
|
||||
- name: "{{ lxc_php_version }} - Install misc packages"
|
||||
lxc_container:
|
||||
name: "{{ lxc_php_version }}"
|
||||
container_command: "DEBIAN_FRONTEND=noninteractive apt install -y cron logrotate git zip unzip"
|
||||
|
||||
- name: "{{ lxc_php_version }} - Add MySQL socket to container default mounts"
|
||||
lxc_container:
|
||||
name: "{{ lxc_php_version }}"
|
||||
container_config:
|
||||
- "lxc.mount.entry = /var/run/mysqld/mysqld {{ php_conf_mysql_default_socket | replace('/', '', 1) }} none bind,create=file 0 0"
|
||||
state: restarted
|
||||
when: php_conf_mysql_default_socket is string
|
||||
|
|
|
@ -6,3 +6,11 @@ log_errors = {{ php_conf_log_errors }}
|
|||
html_errors = {{ php_conf_html_errors }}
|
||||
allow_url_fopen = {{ php_conf_allow_url_fopen }}
|
||||
disable_functions = {{ php_conf_disable_functions }}
|
||||
|
||||
{% if php_conf_mysql_default_socket %}
|
||||
[Pdo_mysql]
|
||||
pdo_mysql.default_socket = {{ php_conf_mysql_default_socket }}
|
||||
|
||||
[MySQLi]
|
||||
mysqli.default_socket = {{ php_conf_mysql_default_socket }}
|
||||
{% endif %}
|
||||
|
|
Loading…
Reference in New Issue