PHP Version 8.0.20
This article describes how to install a Web server with application back-end PHP and database back-end MySQL using MariaDB. In continuing the same topic, but with different software from the previous article – How To Install Linux, Nginx, MySQL (MariaDB), PHP-FPM (LEMP) Stack on CentOS Stream 9, where the Web server is Nginx with application back-end PHP-FPM, which is a sort of CGI (FastCGI). In this article, the Web server is Apache and the application is again PHP-FPM, because since the CentOS 8 the Apache mod_php is deprecated.
All the software installed throughout this article is from the CentOS Stream 9 official repositories including the EPEL repository. The machine is installed with a minimal installation of CentOS Stream 9 and there is a how-to here – Network installation of CentOS Stream 9 (20220606.0) – minimal server installation.
Here are the steps to perform:
STEP 1) Install, configure and start the database MariaDB.
First, install the MariaDB server by:
dnf install -y mariadb-server
To configure the MariaDB server, the main file is /etc/my.cnf, which just includes all files under the folder /etc/my.cnf.d/
[root@srv ~]# cat /etc/my.cnf
#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
[root@srv ~]# ls -altr /etc/my.cnf.d/
total 32
-rw-r--r--. 1 root root 295 Mar 25 2022 client.cnf
-rw-r--r--. 1 root root 120 May 18 07:55 spider.cnf
-rw-r--r--. 1 root root 232 May 18 07:55 mysql-clients.cnf
-rw-r--r--. 1 root root 763 May 18 07:55 enable_encryption.preset
-rw-r--r--. 1 root root 1458 Jun 13 13:24 mariadb-server.cnf
-rw-r--r--. 1 root root 42 Jun 13 13:29 auth_gssapi.cnf
drwxr-xr-x. 2 root root 4096 Oct 6 06:34 .
drwxr-xr-x. 81 root root 4096 Oct 6 06:34 ..
The most important file for the MariaDB server is /etc/my.cnf.d/mariadb-server.cnf, where all the server options are included. Under section “[mysqld]” add options to tune the MariaDB server. Supported options could be found here: https://mariadb.com/kb/en/mysqld-options/
Add the following options under “[mysqld]” in /etc/my.cnf.d/mariadb-server.cnf Keep on reading!
dnf mariadb
This article presents how to install a Web server with application back-end PHP and database back-end MySQL using MariaDB. All the software installed throughout this article is from the CentOS Stream 9 official repositories including the EPEL repository. The machine is installed with a minimal installation of CentOS Stream 9 and there is a how-to here – Network installation of CentOS Stream 9 (20220606.0) – minimal server installation.
Here are the steps to perform:
STEP 1) Install, configure and start the database MariaDB.
First, install the MariaDB server by:
dnf install -y mariadb-server
To configure the MariaDB server, the main file is /etc/my.cnf, which just includes all files under the folder /etc/my.cnf.d/
[root@srv ~]# cat /etc/my.cnf
#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
[root@srv ~]# ls -altr /etc/my.cnf.d/
total 32
-rw-r--r--. 1 root root 295 Mar 25 2022 client.cnf
-rw-r--r--. 1 root root 120 May 18 07:55 spider.cnf
-rw-r--r--. 1 root root 232 May 18 07:55 mysql-clients.cnf
-rw-r--r--. 1 root root 763 May 18 07:55 enable_encryption.preset
-rw-r--r--. 1 root root 1458 Jun 13 13:24 mariadb-server.cnf
-rw-r--r--. 1 root root 42 Jun 13 13:29 auth_gssapi.cnf
drwxr-xr-x. 2 root root 4096 Oct 6 06:34 .
drwxr-xr-x. 81 root root 4096 Oct 6 06:34 ..
The most important file for the MariaDB server is /etc/my.cnf.d/mariadb-server.cnf, where all the server options are included. Under section “[mysqld]” add options to tune the MariaDB server. Supported options could be found here: https://mariadb.com/kb/en/mysqld-options/
Add the following options under “[mysqld]” in /etc/my.cnf.d/mariadb-server.cnf Keep on reading!
As the web grows and the technology advances the page size of the web sites also grows or just some times you might want to output a big chunk of data from your application server – PHP-FPM (but it could be any of another ruby, python, C, Django and more), for example.
Here is a fast configuration tip (note this is not the proxy-related warning!):
The default nginx buffers per CGI connection are too small
Here is what to do in your nginx configuration file: First, look for a line “include /etc/nginx/fastcgi_params;” or similar and add or edit if they exist after this line:
fastcgi_buffer_size 16k;
fastcgi_buffers 32 16k;
Check out more for the buffers here http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_buffers
The warning should stop if it does not stop you can try raising them. It could consume more memory but could lower the IO usage of your disks and improve the performance of your site or whatever backend works!
Here is the warning in our nginx error logs. We got this warning when using php-fpm and the php output size was 325965 bytes (~320K).
2019/04/04 09:56:05 [warn] 24451#24451: *44269838 an upstream response is buffered to a temporary file /var/cache/nginx/fastcgi_temp/0/12/0019966120 while reading upstream, client: 10.10.10.10, server: srv17.srv.en, request: "GET /api/20140102/product HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "srv17.srv.en"
2019/04/04 09:56:07 [warn] 24451#24451: *44269849 an upstream response is buffered to a temporary file /var/cache/nginx/fastcgi_temp/2/12/0019966122 while reading upstream, client: 10.10.10.11, server: srv17.srv.en, request: "GET /api/20140102/product HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "srv17.srv.en"
2019/04/04 09:56:09 [warn] 24450#24450: *44269856 an upstream response is buffered to a temporary file /var/cache/nginx/fastcgi_temp/7/12/0019966127 while reading upstream, client: 10.10.10.12, server: srv17.srv.en, request: "GET /api/20140102/product HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "srv17.srv.en"
[22-Mar-2019 21:35:20 Africa/Tunis] PHP Warning: Unknown: Failed to write session data (memcached). Please verify that the current setting of session.save_path is correct (PERSISTENT=2 10.10.10.10:11211) in Unknown on line 0
[22-Mar-2019 21:35:21 Africa/Lagos] PHP Warning: Unknown: Failed to write session data (memcached). Please verify that the current setting of session.save_path is correct (PERSISTENT=2 10.10.10.10:11211) in Unknown on line 0
[22-Mar-2019 13:35:21 America/Los_Angeles] PHP Warning: Unknown: Failed to write session data (memcached). Please verify that the current setting of session.save_path is correct (PERSISTENT=2 10.10.10.10:11211) in Unknown on line 0
But no real solutions worked for us. Here is our setup:
Several web servers servers (using php-fpm – fastcgi) connect to a single memcached server to share sessions.
The PHP configuration (php.ini) is as simple as that:
This is how you can enable PHP sessions to be stored in the memcached server with IP 10.10.10.10 and tell the driver to use persistent connections. Note we use the binary PHP module memcached, not memcache, which is the old driver.
The persistence is handled by the PHP module, not the library, which it wraps and it is per process not per all PHP fpm (fastcgi) processes.
Apparently, sometimes this functionality just get corrupted and many of those errors begin to appear in the logs – most of the time a reload of the php-fpm after a long period of time. Even a restart did not help, so the real solution, which always works for us is
1) all active connections; 2) requests per second to nginx Nginx Graphs
CHART 2) Nginx Graphs 2
1) nginx active connections by their status – reading (from client), writing (from client), idle (doing nothing, but opened to the client); 2) connections rate – accepted and handled Nginx Graphs 2
1) active connections – active (executing PHP code on the CPU right now – “php running”), max active, idle; 2) requests; 3) performance – max children reached or slow requests (it depends on your version of netdata). PHP-FPM – FastCGI PHP performance metrics
CHART 4) PHP-FPM – request information
1) reuqest duration – minimum, maximum, avarage – how much time do a request take time – very useful to see how fast is your backend application. 2) request CPU in procentages; 3) request memory – reuested memory by your php fpm processes. PHP-FPM – request information
CHART 5) MySQL – performance metrics
1) bandwidth – The amount of data sent to mysql clients (out) and received from mysql clients (in); 2) queries – The number of statements executed by the server. To see a slow queries the slow query log should be enabled. MySQL – performance metrics
CHART 6) MySQL – handlers and locks
1) handlers – netdata Quotation: “Usage of the internal handlers of mysql. This chart provides very good insights of what the mysql server is actually doing. – commit, the number of internal COMMIT statements; delete, the number of times that rows have been deleted from tables; prepare, a counter for the prepare phase of two-phase commit operations; read first, the number of times the first entry in an index was read. A high value suggests that the server is doing a lot of full index scans; e.g. SELECT col1 FROM foo, with col1 indexed; read key, the number of requests to read a row based on a key. If this value is high, it is a good indication that your tables are properly indexed for your queries; read next, the number of requests to read the next row in key order. This value is incremented if you are querying an index column with a range constraint or if you are doing an index scan; read prev, the number of requests to read the previous row in key order. This read method is mainly used to optimize ORDER BY … DESC; read rnd, the number of requests to read a row based on a fixed position. A high value indicates you are doing a lot of queries that require sorting of the result. You probably have a lot of queries that require MySQL to scan entire tables or you have joins that do not use keys properly; read rnd next, the number of requests to read the next row in the data file. This value is high if you are doing a lot of table scans. Generally this suggests that your tables are not properly indexed or that your queries are not written to take advantage of the indexes you have; rollback, the number of requests for a storage engine to perform a rollback operation; savepoint, the number of requests for a storage engine to place a savepoint; savepoint rollback, the number of requests for a storage engine to roll back to a savepoint; update, the number of requests to update a row in a table; write, the number of requests to insert a row in a table.” 2) MySQL table locks counters, netdata Quotation: ” immediate, the number of times that a request for a table lock could be granted immediately – waited, the number of times that a request for a table lock could not be granted immediately and a wait was needed. If this is high and you have performance problems, you should first optimize your queries, and then either split your table or tables or use replication.” MySQL – handlers and locks
CHART 7) MySQL – sorts, selects and temporaries
1) mysql SELECT JOIN – full range, range, scan; 2) mysql sorts – range and scan; 3) temporaries – disk tables (writing to the disk is slow and should be avoided!!!) and tables. MySQL – sorts, selects and temporaries
CHART 8) MySQL – connections and binlog
1) connections in seconds – all and aborted – if you are using persistent connections to MySQL you can see a busy MySQL server could have 2-3 new connections in a minute, because all the application backend uses the pool of already opened connections to the server. 2) connection errors – accepted, internal, max, peer_addr, select, tcpwrap; 3) binlog transactions per second MySQL – connections and binlog
CHART 9) MySQL – binlog and threads
1) binlog statement cache; 2) MySQL threads – connected, cached, running; 3) threads cache misses MySQL – binlog and threads
CHART 10) MySQL – Innodb engine infromation
1) Innodb I/O bandwidth – reads and writes; 2) Innodb I/O Operations – reads, writes and fsyncs; 3) Innodb Pending I/O Operations – reads and fsyncs; 4) Innodb Log Operations – write requests and writes. MySQL – Innodb engine infromation
CHART 11) MySQL – Innodb engine infromation 2
1) Innodb OS Log Operations – fsyncs; 2) Innodb OS Log bandwidth – write (megabytes/s); 3) Innodb current row locks – current_waits; 4) Innodb row operations – inserted, read, updated and deleted. MySQL – Innodb engine infromation 2
CHART 12) MySQL – Innodb engine infromation 3
1) Innodb buffer pool pages – data, dirty, free, flushed, misc, total; 2) Innodb buffer pool bytes – data and dirty; 3) Innodb buffer pool read ahaed – all, evicted, random; 4) Innodb buffer pool requests – reads and writes per second. MySQL – Innodb engine infromation 3
CHART 13) MySQL – Innodb engine infromation 4
1) Innodb buffer pool operations – disk reads – operations per second. MySQL – Innodb engine infromation 4
CHART 14) MySQL – query cache (qcache)
1) query cache operations – hits, low memory prunes, inserts, not cached; 2) queries in the cache; 3) query cache free memory; 4) query cache memory blocks – free and total. MySQL – query cache (qcache)
CHART 15) MySQL – myisam engine information
This server does not uses MyISAM engine, so you can see almost everything is zero – 1) MyISAM key cache blocks – unused and used; 2) MyISAM key cache requests – reads and writes; 3) MyISAM key cache disk operation – reads and writes. MySQL – myisam engine information
CHART 16) MySQL – files
1) open files – how many files are opened at the moment; 2) opened file rate – files per second. MySQL – files
1) cache size – available and used; 2) network – in and out megabytes per second. Memcached – distributed memory caching system. A key-value memory storage.
CHART 18) Memcached – connections and items
1) connections – current and total. Persistent connections are used, so no new connections often; 2) items cached – current and total. 3) items – evicted (forced removed – be careful here, this means your cached items are forcedly removed by the server because of lack of memory?) and reclaims (expired items). Memcached – connections and items
CHART 19) Memcached – get and set operations
1) get operation requests – hits and misses; 2) get operations rate – requests per second; 3) set operation requests – requests per second. Memcached – get and set operations
CHART 20) Memcached – check and set ops, delete ops, increment ops
1) check and set operation requests – hits, misses, bad value; 2) delete operation requests – hits and misses; increment operation requests – hits and misses Memcached – check and set ops, delete ops, increment ops
1) Postfix Queue Emails – the emails in the queue of the mail transfer agent, these mails are in transfer state; 2) Postfix Queue Emails size – size. Postfix – mail service
CHART 23) Redis – performance metrics for in-memory data structure store, used as a database, cache and message broker.
1) operations – commands and operations per second; 2) hit rate – persentage, the effectiveness of the cache. Redis – performance metrics for in-memory data structure store, used as a database, cache and message broker.
CHART 24) Redis – memory, keys, network
1) Redis memory utilization – total and lua; 2) keys – how many keys does each database have – keys per database name; 3) network – Redis network bandwidth – in and out in megabytes per second. Redis – memory, keys, network
CHART 25) Redis – connections and replication
1) Redis connections – received per second – it’s like new connections and if you use persistent connections no new connections are opened often; 2) Redis clients – connected processes to the redis server; 3) replication – connected slave servers. Redis – connections and replication
CHART 26) Redis – persistence (save the databases to the disks)
1) Persistence changes since last save – changes – how many changed items have been there since last save of the databases to the disks. 2) Duration of the RDB Save operation – rdb save in time; 3) Status of the last RDB Save Operation – rdb status. Redis – persistence (save the databases to the disks)
CHART 27) Web server access logs information
Live parsing of the access logs – be careful here, because this could take a good deal of CPU and I/O of your busy server. Here we included only the default nginx log, which does not save many records. netdata Quotation: “Information extracted from a server log file. web_log plugin incrementally parses the server log file to provide, in real-time, a break down of key server performance metrics. For web servers, an extended log file format may optionally be used (for nginx and apache) offering timing information and bandwidth for both requests and responses. web_log plugin may also be configured to provide a break down of requests per URL pattern (check /etc/netdata/python.d/web_log.conf).” – 1) responses – success and bad requests per second; 2) Response codes – 1xx and 4xx and more if any in the logs. Web server access logs information
CHART 28) Web server access logs information – detailed response code, bandwidth, http methods
1) detailed response code – requests per second; 2) bandwidth of the requests and reponses; 3) Requests per HTTP Method – GET, POST, PUT, DELETE and so on if they present in the logs. Web server access logs information – detailed response code, bandwidth, http methods
CHART 29) Web server access logs information – http versions, ip protocols, clients
1) Requests per HTTP Version – 1.0, 1.1 and 2.0 if any in the logs; 2) Requests per IP protocol – IPv4 and IPv6 (if used); 3) clients – unique client IPs per data collection. Web server access logs information – http versions, ip protocols, clients
CHART 30) Web server access logs information – unique client IPs
Unique client IPs since last restart of netdata Web server access logs information – unique client IPs
Manage Cookie Consent
We use technologies like cookies to store and/or access device information. We do this to improve browsing experience and to show personalized ads. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional
Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.