Installing Debian 10 (Buster) LAMP Server v1.0 (page 3)

botond published 2019/11/19, k - 14:30 time

Content

  1. page: Installing and configuring MariaDB, Apache and PHP7.3
  2. page: Manually install, configure, and test phpMyAdmin
  3. page: Creating and configuring a PHP-FPM pool for phpMyAdmin (optional)

 

3. page content

 

Continuation

The description on the first page we installed the MariaDB-t, Apache web server, and PHP 7.3 at. Then a second page installed and configured aa phpMyAdmin web database management interface, and this page optionally creates and configures a separate PHP-FPM pool for PMA.

 

 

phpMyAdmin Fine-tune PHP-FPM (Optional)

During the installation of the LAMP server, we were talking about a complete migration to PHP-FPM, which means that mod_php-based Virtual hostingand global configurations will be redirected to PHP-FPM due to php7.3-fpm configuration enabled, if mod_php is not available. If we didn't turn off mod_php at first, we have nothing more to do with it, as our instance of phpMyAdmin runs with settings similar to the above Apache configuration, which has some useful flag and PHP variables that we can modify or add at any time.

However, if you have disabled mod_php at the beginning (as I did), or have not installed these modules at all, the redirection will take place, so the Apache config shown on the previous page IfModule mod_php7.c parts of the block will not be evaluated, but will be replaced with the (default) settings of the PHP-FPM default 'www' pool, because our phpMyAdmin will run in this FPM pool. Therefore, a closer look at the runtime environment of our recent collection (with the help of phpinfo in your library) will reveal a few small things:

A file displaying phpinfo in the phpMyAdmin directory

This is where PHP-FPM (redirected) works, even though the Apache configuration above is configured with mod_php7. So if you look at a few more things, it also shows that things configured in the previous configuration are invalid here because they run in a different PHP environment. For example:

phpMyAdmin phpinfo - No open_basedir

nincs open_basedir value of this environment, or

phpMyAdmin phpinfo - No upload_tmp_dir

nincs upload_tmp_dir value (even though they were previously set), and so on.

If your system is not behaving as expected, or you suddenly need to set something up in a live environment, for example, I would like to raise the factory 2MB file upload limit only in phpMyAdmin so that we can import larger SQL files, then indeed, we are confronted with the problem, because suddenly we do not know why our settings do not apply.

Therefore, if we are still nervous and want to set everything up really precisely, I suggest that if our phpMyAdmin is already running PHP-FPM, we create a pool of our own, in which we can conveniently set up everything we need individually, which will only be valid in this pool. This way, we can individually control all the settings of our favorite database management interface at any time, regardless of other PHP things running on the server.

Of course, we could also adjust the settings of the default 'www' pool to suit our needs, but this would not be a wise solution, because if another website or configuration is added to this default pool later, the settings would be valid for all of them. Thus, it is advisable to run each virtualhost and configuration in a separate pool so that we can control each one individually according to the given needs.

 

 

Set up your own pool

A PHP-FPM pools have been mentioned before, so now I will not go into the details of these, but let's start with creating and configuring our phpMyAdmin pool.

Create a Pool

Unless it is several PHP versions installed, then Debian 10 (Buster) has the default PHP 7.3. Go to the PHP-FPM pool directory for this:

cd /etc/php/7.3/fpm/pool.d

Create a file for phpMyAdmin:

nano phpmyadmin.conf

And let's put the following settings:

; Pool-unk neve
[phpmyadmin]

; Futtató felhasználó
user = www-data
group = www-data

; Socket fájl
listen = /run/php/php7.3-phpmyadmin-fpm.sock

; Socket fájl tulajdonosa és módja
listen.owner = www-data
listen.group = www-data
listen.mode = 0660

; Process management beállítások
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.max_requests = 0

; log fájl
access.log = /var/log/phpmyadmin/php-fpm-access.log
access.format = "Log: %t \"%m %r%Q%q\" %s time:%{mili}dm mem:%{kilo}MKB cpu:%C%%"

; Ezekben a fájltípusokban futhatnak php kódok
security.limit_extensions = .php .html

; Környezeti változók
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /var/lib/phpmyadmin/tmp
env[TMPDIR] = /var/lib/phpmyadmin/tmp
env[TEMP] = /var/lib/phpmyadmin/tmp

; PHP beállítások
php_admin_flag[log_errors] = on
php_flag[display_errors] = off
php_admin_value[session.gc_maxlifetime] = 3600
php_admin_value[error_log] = /var/log/phpmyadmin/php-errors.log
php_admin_value[memory_limit] = 128M
php_admin_value[upload_max_filesize] = 256M


; További PHP beállítások, amiket a 'gyári' phpMyAdmin Apache konfigból vettünk át
php_flag[magic_quotes_gpc] = off
php_flag[track_vars] = on
php_flag[register_globals] = off
php_value[include_path] = .
php_admin_value[upload_tmp_dir] = /var/lib/phpmyadmin/tmp
php_admin_value[open_basedir] = /usr/share/phpmyadmin/:/etc/phpmyadmin/:/var/lib/phpmyadmin/:/usr/share/php/php-gettext/:/usr/share/php/php-php-gettext/:/usr/share/javascript/
php_admin_value[mbstring.func_overload] = 0

A quick run through will set up the following:

  • We set the user of the web pages or configurations running in the pool to www-data. We could have created any user here, but needless to say, the only point here is to have a separate pool for phpMyAdmin with custom configuration options.
  • Socket File: This file communicates between Apache and PHP-FPM. We also set the owner of this file here.
  • Process management settings: Here you can control the process management of this pool, ie how many children to run processes, servers, backup servers, etc. I have copied these from the default settings, there is no need for scribbling here as this is an admin interface that is good for up to 1-2 people at a time. But if, for example, a large company had this server, where 50 employees would be phinging phpMyAdmin at a time, it would be a good idea to raise values ​​carefully. Or, for example, if it was a busy website with thousands of visitors ...
  • Then we set the access.log file access and collection format.
  • security.limit_extensions: These allow PHP-FPM to execute PHP code. This list must be in sync with your Apache configuration FilesMatch Part ...
  • Environment Variables: Here we pass the variables of the Linux system environment to the PHP environment. Here, among other things, we set the phpMyAdmin tmp directory to several variables.
  • PHP Settings: Here you can configure standard PHP flags and variables. Eg logging: on, displaying errors: off, session length: 1 hours, error log path, etc.
  • Additional PHP settings: And here I just transferred the phpMyAdmin settings from the factory Apache configuration to make everything work properly in this environment as well. All you have to do is pay attention to the fact that the syntax in this setting is a bit different, here we give values ​​to array elements, so the labels are placed in square brackets, and then we enter the values ​​with equal signs.

Configuring Apache

Open our previously created Apache config file:

nano /etc/apache2/conf-available/phpmyadmin.conf

And under the IfModule block, put a few serial parts, as shown below:

<Directory /usr/share/phpmyadmin>
	Options SymLinksIfOwnerMatch
	DirectoryIndex index.php

	<IfModule mod_php7.c>
		AddType application/x-httpd-php .php

		php_flag magic_quotes_gpc Off
		php_flag track_vars On
		php_flag register_globals Off
		php_value include_path .
		php_admin_value upload_tmp_dir /var/lib/phpmyadmin/tmp
		php_admin_value open_basedir /usr/share/phpmyadmin/:/etc/phpmyadmin/:/var/lib/phpmyadmin/:/usr/share/php/php-gettext/:/usr/share/php/php-php-gettext/:/usr/share/javascript/
		php_admin_value mbstring.func_overload 0
	</IfModule>
	
	# PHP-FPM beállítása a saját phpmyadmin pool-hoz
	<IfModule mod_proxy_fcgi.c>
		<FilesMatch "\.(php|html)$">
			SetHandler "proxy:unix:/run/php/php7.3-phpmyadmin-fpm.sock|fcgi://localhost"
		</FilesMatch>		
	</IfModule>
	# PHP-FPM beállítás vége

</Directory>

So there is so much going on in these few lines that if php vagy html file hits encountered by Apache then mod_proxy_fcgi in the presence of - and using it - redirects the request to PHP-FPM, but so now this config will no longer run in the default '' www 'pool (as before), but in our new pool, which has socket file is specified. The settings above in the pool take effect when phpMyAdmin is run.

We are not rebooting now, we still have to fix the log files ...

 

 

Manage log files

Above the pool settings, we have specified two log file access a / Var / log / phpmyadmin / in the directory: a php-fpm-access.log and the php errors.log of files. The first one collects access information about PHP-FPM and tells us the FPM here, for example, if one needs to upgrade a Process Management setting, and the second file accepts traditional PHP bugs. They are designed to be in one place in the / var / log structure, so you can conveniently access it whenever you want to look at it. To do this, create the directory above:

mkdir /var/log/phpmyadmin

Then, change your permission to www-data as this user will run this pool so the log files will be modified on that name as well:

chown -R www-data:www-data /var/log/phpmyadmin

We are almost done, we still need to set up the rotation of these log files, because over time a lot of data accumulates in php-fpm-access.log, for example. All this a logrotate system, which has already been mentioned.

Create a logrotate file for phpMyAdmin:

nano /etc/logrotate.d/phpmyadmin

And let's put these a few lines of setup:

/var/log/phpmyadmin/php-fpm-access.log
/var/log/phpmyadmin/php-errors.log
{
	rotate 7
	daily
	copytruncate
	compress
	delaycompress
	missingok
	notifempty
}

Then save it. You can find out more about the settings at the link above.

Restart systems

Finally, restart PHP-FPM and Apache:

systemctl restart php7.3-fpm.service
systemctl restart apache2.service

Testing phpMyAdmin pool

Everything is ready, all we have to do is try our luck. If you have not already placed a test file in your phpMyAdmin directory, you can now:

nano /usr/share/phpmyadmin/my_phpinfo.php

there is already a file called phpinfo.php that PMA uses for another, so we need to create it under a different name. Let's put in the usual:

<?php
    phpinfo();
?>

And load it into the browser using the server's IP address:

http://192.168.1.130/phpmyadmin/my_phpinfo.php

phpMyAdmin Pool Review - phpinfo

So far, there is no difference from the previous state, but if you scroll down and search for the parameters you have set, the operation becomes visible. Here are some random ones:

check phpMyAdmin pool - phpinfo - memory_limit and open_basedir

memory_limit and open_basedir: They are all set and their value is visible.

phpMyAdmin pool check - phpinfo - upload_max_filesize and upload_tmp_dir

upload_max_filesize and upload_tmp_dir: They also have a set value.

And so on, the other settings are all there.

Now we can say that our phpMyAdmin installation is perfect. :)

 

Download server

The server made here download page can be found here.

 

 

Conclusion

This created our Debian 10 (Buster) based LAMP server, which was a little longer than before, as the phpMyAdmin web database management interface had to be installed and configured manually. This server has also been given a stronger configuration here and there, as it will later be the basis for the perfect Debian 10 server, so this version has become a bit more powerful than previous LAMPs. But until you get the perfect server setup description from this, give it a try, use it with health!

There are many LAMP installer descriptions on the net, so I tried to add some plus now so that I can not only offer you the template install commands, but also provide additional useful information. I hope this will keep you in the mood for further installations.

 

What's next?

Once you have created this LAMP server, you may find it useful install additional PHP versions on itto make it compatible with older websites. Also, if you want to run multiple web pages on this server at the same time, then here's how to set up additional virtual hostsso that websites can run on it in parallel. But if you want to improve the server further, I recommend Perfect server: Debian 10 (Buster) V1.0 which is an excellent solution for running a live server.

 

 

Navigation

This description consists of several pages: