From f428c4de48c246f4305324e7816995204827125b Mon Sep 17 00:00:00 2001 From: pareenaverma Date: Thu, 16 Oct 2025 16:10:38 +0000 Subject: [PATCH] Tech review of PHP LP --- .../php-on-gcp/_index.md | 4 +- .../php-on-gcp/background.md | 4 +- .../php-on-gcp/baseline.md | 102 +++++++++++++----- .../php-on-gcp/benchmarking.md | 93 ++++++++++------ .../php-on-gcp/installation.md | 52 ++++++--- .../php-on-gcp/instance.md | 6 +- 6 files changed, 181 insertions(+), 80 deletions(-) diff --git a/content/learning-paths/servers-and-cloud-computing/php-on-gcp/_index.md b/content/learning-paths/servers-and-cloud-computing/php-on-gcp/_index.md index b3a9439e3c..f421de80f2 100644 --- a/content/learning-paths/servers-and-cloud-computing/php-on-gcp/_index.md +++ b/content/learning-paths/servers-and-cloud-computing/php-on-gcp/_index.md @@ -11,10 +11,10 @@ who_is_this_for: This is an introductory topic for software developers migrating learning_objectives: - - Provision an Arm-based SUSE SLES virtual machine on Google Cloud (C4A with Axion processors) + - Provision a SUSE SLES virtual machine on Google Cloud C4A (Arm-based Axion VM) - Install PHP on a SUSE Arm64 (C4A) instance - Validate PHP functionality with baseline HTTP server tests - - Benchmark PHP performance using PHPBench on Arm64 (Aarch64) architecture + - Benchmark PHP performance using PHPBench on Arm64 architecture prerequisites: diff --git a/content/learning-paths/servers-and-cloud-computing/php-on-gcp/background.md b/content/learning-paths/servers-and-cloud-computing/php-on-gcp/background.md index 5ef0914ba1..8bbb374d12 100644 --- a/content/learning-paths/servers-and-cloud-computing/php-on-gcp/background.md +++ b/content/learning-paths/servers-and-cloud-computing/php-on-gcp/background.md @@ -1,5 +1,5 @@ --- -title: Getting started with PHP on Google Axion C4A (Arm Neoverse-V2) +title: Get started with PHP on Google Axion C4A (Arm Neoverse V2) weight: 2 @@ -8,7 +8,7 @@ layout: "learningpathall" ## Google Axion C4A Arm instances in Google Cloud -Google Axion C4A is a family of Arm-based virtual machines built on Google’s custom Axion CPU, which is based on Arm Neoverse-V2 cores. Designed for high-performance and energy-efficient computing, these virtual machines offer strong performance for modern cloud workloads such as CI/CD pipelines, microservices, media processing, and general-purpose applications. +Google Axion C4A is a family of Arm-based virtual machines built on Google’s custom Axion CPU, which is based on Arm Neoverse V2 cores. Designed for high-performance and energy-efficient computing, these virtual machines offer strong performance for modern cloud workloads such as CI/CD pipelines, microservices, media processing, and general-purpose applications. The C4A series provides a cost-effective alternative to x86 virtual machines while leveraging the scalability and performance benefits of the Arm architecture in Google Cloud. diff --git a/content/learning-paths/servers-and-cloud-computing/php-on-gcp/baseline.md b/content/learning-paths/servers-and-cloud-computing/php-on-gcp/baseline.md index 82b19f8194..e72b143540 100644 --- a/content/learning-paths/servers-and-cloud-computing/php-on-gcp/baseline.md +++ b/content/learning-paths/servers-and-cloud-computing/php-on-gcp/baseline.md @@ -8,75 +8,127 @@ layout: learningpathall ## Baseline Setup for PHP-FPM -This section covers the installation and configuration of **PHP and Apache** on a SUSE Arm-based GCP VM. It includes setting up **PHP-FPM** with a Unix socket, verifying PHP functionality via a test page, and ensuring Apache and PHP-FPM work together correctly. +This section guides you through configuring PHP-FPM (FastCGI Process Manager) on a SUSE Arm-based Google Cloud C4A virtual machine. You will prepare the PHP-FPM pool configuration, verify PHP's FastCGI setup, and later connect it to Apache to confirm end-to-end functionality. ### Configure the PHP-FPM Pool -**PHP-FPM:** A FastCGI Process Manager that runs PHP scripts efficiently, handling multiple requests separately from the web server for better performance and security. +PHP-FPM (FastCGI Process Manager) runs PHP scripts in dedicated worker processes that are independent of the web server. +This design improves performance, security, and fault isolation — especially useful on multi-core Arm-based processors like Google Cloud’s Axion C4A VMs. -A **pool** is basically a set of PHP worker processes that handle requests. +A pool defines a group of PHP worker processes, each serving incoming FastCGI requests. Different applications or virtual hosts can use separate pools for better resource control. ### Copy the Default Configuration (if missing) -Run this command to create a working config file: +If your PHP-FPM configuration files don't exist yet (for example, after a minimal installation in this Learning Path), copy the defaults into place using the commands below: ```console sudo cp /etc/php8/fpm/php-fpm.d/www.conf.default /etc/php8/fpm/php-fpm.d/www.conf +sudo cp /etc/php8/fpm/php-fpm.conf.default /etc/php8/fpm/php-fpm.conf ``` +These commands: +Create a default pool configuration (www.conf) that controls how PHP-FPM spawns and manages worker processes. +Restore the main FPM service configuration (php-fpm.conf) if it's missing. ### Edit the Configuration -Open the config file in a text editor: +Open the PHP-FPM pool configuration file in a text editor: ```console sudo vi /etc/php8/fpm/php-fpm.d/www.conf ``` -Update the file to use a Unix socket: +Locate the following line: -Find this line `; listen = 127.0.0.1:9000`. Replace it with these lines. +```output +listen = 127.0.0.1:9000 +``` +Replace it with the following configuration to use a Unix socket instead of a TCP port: -```ini +```console listen = /run/php-fpm/www.sock listen.owner = wwwrun listen.group = www listen.mode = 0660 ``` -- `listen = /run/php-fpm/www.sock` → PHP will talk to Apache using a local “socket file” instead of a network port. -- `listen.owner = wwwrun` → `wwwrun` is Apache’s default user on SUSE, so Apache can access the socket. -- `listen.group = www` → sets the group to match Apache’s group. -- `listen.mode = 0660` → gives read/write permission to both Apache and PHP-FPM. + +Explanation of each directive: +| Directive | Description | +| ----------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| listen = /run/php-fpm/[www.sock](http://www.sock) | Configures PHP-FPM to communicate with Apache using a local Unix socket instead of a TCP port (`127.0.0.1:9000`). This reduces network overhead and improves performance. | +| listen.owner = wwwrun | Sets the owner of the socket file to `wwwrun`, which is the default user that Apache runs as on SUSE systems. This ensures Apache has access to the socket. | +| listen.group = www | Assigns the group ownership of the socket to `www`, aligning with Apache’s default process group for proper access control. | +| listen.mode = 0660 | Defines file permissions so that both the owner (`wwwrun`) and group (`www`) can read and write to the socket. This enables smooth communication between Apache and PHP-FPM. | + ### Start and Enable PHP-FPM -Restart PHP-FPM so it picks up the changes: +After updating the configuration, restart the PHP-FPM service so it picks up the new settings: ```console sudo systemctl restart php-fpm ``` +Then, verify that PHP-FPM is running: + +```console +sudo systemctl status php-fpm +``` + +You should see output similar to: + +```output +● php-fpm.service - The PHP FastCGI Process Manager + Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; disabled; vendor preset: disabled) + Active: active (running) since Thu 2025-10-16 13:56:44 UTC; 7s ago + Main PID: 19606 (php-fpm) + Status: "Ready to handle connections" + Tasks: 3 + CPU: 29ms + CGroup: /system.slice/php-fpm.service + ├─ 19606 "php-fpm: master process (/etc/php8/fpm/php-fpm.conf)" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" + ├─ 19607 "php-fpm: pool www" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""> + └─ 19608 "php-fpm: pool www" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""> + +Oct 16 13:56:44 pareena-php-test systemd[1]: Starting The PHP FastCGI Process Manager... +Oct 16 13:56:44 pareena-php-test systemd[1]: Started The PHP FastCGI Process Manager. +``` +PHP-FPM is now active and ready to process requests via its Unix socket (/run/php-fpm/www.sock). +Next, you will configure Apache to communicate with PHP-FPM, allowing your server to process and serve dynamic PHP pages. + +## Install the Apache PHP8 module +If you prefer to have Apache handle PHP execution directly (instead of using PHP-FPM), you can install the Apache PHP 8 module, which integrates PHP into Apache using the `mod_php` interface: + +```console +sudo zypper install apache2-mod_php8 +``` +Once the module is installed, restart Apache to load the new configuration: + +```console +sudo systemctl restart apache2 +``` +Next, you will test PHP execution by creating a simple PHP page and verifying that Apache can correctly render dynamic content. ## Test PHP -Now that PHP and Apache are installed, let’s verify that everything is working correctly. +Now that PHP and Apache are installed, you can verify that everything is working correctly. ### Create a Test Page -We will make a simple PHP file that shows details about the PHP setup. +Create a simple PHP file that displays detailed information about your PHP installation: ```console echo "" | sudo tee /srv/www/htdocs/info.php ``` -This creates a file named **info.php** inside Apache’s web root directory `(/srv/www/htdocs/)`. When you open this file in a browser, it will display the PHP configuration page. +This creates a file named `info.php` inside Apache's web root directory `(/srv/www/htdocs/)`. When you open this file in a browser, it will display the PHP configuration page. ### Test from Inside the VM -Run the following command: +You can verify that PHP and Apache are communicating correctly by testing the web server locally using curl: ```console curl http://localhost/info.php ``` - `curl` fetches the page from the local Apache server. -- If PHP is working, you’ll see a large block of HTML code as output. -- This confirms that PHP is correctly connected with Apache. +- If PHP is working, you will see a large block of HTML code as output. This is the rendered output of the phpinfo() function. +- This confirms that Apache successfully passed the request to the PHP interpreter and returned the generated HTML response. -You should see an output similar to: +You should see output similar to: ```output @@ -96,18 +148,20 @@ h1 {font-size: 150%;} h2 {font-size: 125%;} h2 a:link, h2 a:visited{color: inherit; background: inherit;} ``` -Basically, it is the HTML output that confirms PHP is working. +This long HTML output represents the PHP configuration page content. ### Test from Your Browser -Now, let’s test it from outside the VM. Open a web browser on your local machine (Chrome, Firefox, Edge, etc.) and enter the following URL in the address bar: +Now, let's verify that your PHP setup works correctly from outside the VM. +Open a web browser on your local machine (such as Chrome, Firefox, or Edge) and enter the following URL in the address bar: ```console http:///info.php ``` -- Replace `` with the public IP of your GCP VM. +- Replace `` with the public IP of your Google Cloud Axion VM. If everything is set up correctly, you will see a PHP Info page in your browser. It looks like this: ![PHP-info page alt-text#center](images/php-web.png "Figure 1: PHP info") -This verifies the basic functionality of the PHP installation before proceeding to the benchmarking. +Successfully loading the PHP Info page in your browser confirms that your PHP and Apache environment on Google Cloud C4A is configured and functioning properly. +You are now ready to proceed to the benchmarking and performance testing phase. diff --git a/content/learning-paths/servers-and-cloud-computing/php-on-gcp/benchmarking.md b/content/learning-paths/servers-and-cloud-computing/php-on-gcp/benchmarking.md index ab818ca17b..e9a72f8111 100644 --- a/content/learning-paths/servers-and-cloud-computing/php-on-gcp/benchmarking.md +++ b/content/learning-paths/servers-and-cloud-computing/php-on-gcp/benchmarking.md @@ -9,48 +9,64 @@ layout: learningpathall ## PHP Benchmarking using PHPBench -In this section, we will be focussing on PHP benchmarking using PHPBench, running sample benchmarks, interpreting key metrics like mode time and variation, and analyzing performance results for string and array operations on the GCP Arm VM. +In this section, you will learn how to benchmark PHP performance using PHPBench, a modern and extensible benchmarking framework for PHP applications. You will install PHPBench, run sample tests, and interpret key metrics such as mode time, variance, and throughput. +You will then analyze the results to understand how your Google Cloud C4A (Axion Arm64) virtual machine performs on common operations like string manipulation and array processing. -PHPBench is a powerful benchmarking framework for PHP, designed to measure the performance of PHP code and functions. It helps developers identify bottlenecks, compare execution times, and optimize code efficiency by running repeatable, accurate benchmarks. Using PHPBench, you can track performance changes over time and ensure consistent PHP application performance. +PHPBench is a flexible micro-benchmarking tool designed to measure PHP code performance precisely and repeatably. It allows developers to: + * Measure the execution time of PHP functions or code blocks. + * Identify performance regressions between versions. + * Automate performance testing across CI/CD pipelines. + * Track results over time to detect optimizations or slowdowns. ### Download Composer Installer -Composer is a tool for managing PHP packages. First, download the installer: +Before installing PHPBench, you need Composer, which is PHP's dependency manager. Composer handles library installations, versioning, and autoloading, ensuring tools like PHPBench run consistently across environments. +Download the Composer installer script using PHP: ```console sudo php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" ``` -This command downloads a PHP script called composer-setup.php, which will install Composer. +This command downloads a PHP script called `composer-setup.php`, which will install Composer. ### Install the phar extension -Composer requires PHP’s phar extension. You need to install it using following command: +Composer requires PHP's phar (PHP Archive) extension to run. This extension allows PHP to execute .phar archive files, self-contained PHP applications like Composer and PHPBench are distributed in this format. +Install the extension with: ```console sudo zypper install -y php8-phar ``` -`phar` allows PHP to run archive files (.phar) like Composer. - ### Install Composer system-wide -Run the installer to make Composer available for all users: +Now, install Composer globally so it is available for all users and can be executed from any directory: ```console sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer ``` +The output should look like: + +```output +All settings correct for using Composer +Downloading... -This installs Composer to /usr/local/bin/composer. +Composer (version 2.8.12) successfully installed to: /usr/local/bin/composer +Use it: php /usr/local/bin/composer +``` +Composer is now installed system-wide at /usr/local/bin/composer and ready to manage PHP dependencies. ### Remove the installer script +After successfully installing Composer, remove the installer file to keep your environment clean: + ```console sudo php -r "unlink('composer-setup.php');" ``` -Delete the installer file after successful installation. +Since Composer is now installed system-wide, the installer file is no longer needed. ### Verify Composer installation +To confirm that Composer was installed correctly and is accessible globally, run: ```console composer --version @@ -62,29 +78,29 @@ PHP version 8.0.30 (/usr/bin/php) Run the "diagnose" command to get more detailed diagnostics output. ``` +Composer is now successfully installed and you can proceed to installing PHPBench. + ### Install PHPBench globally -PHPBench is a benchmarking tool for PHP. Install it globally via Composer: +PHPBench is a powerful benchmarking tool for measuring the performance of PHP code. Install it globally using Composer so you can access it from any directory: ```console composer global require phpbench/phpbench ``` -This installs `phpbench` in your user’s Composer folder. +This installs `phpbench` in your user's global Composer directory, typically located under `$HOME/.config/composer/` ### Add Composer global bin to PATH -Make sure PHPBench is accessible: - +To make `phpbench` accessible from any terminal session, add Composer's global binary path to your system's environment PATH: ```console export PATH="$HOME/.config/composer/vendor/bin:$PATH" echo 'export PATH=$HOME/.config/composer/vendor/bin:$PATH' >> ~/.bashrc source ~/.bashrc ``` -This ensures the `phpbench` command works whenever you open a terminal. ### Verify PHPBench installation - +Once installed, verify that PHPBench is working correctly: ```console phpbench --version ``` @@ -93,10 +109,11 @@ You should see output similar to: ```output phpbench 1.2.14 ``` +PHPBench is now installed and ready to run. ### Create a Benchmark Directory -Create a folder to hold all your benchmark scripts: +Create a new PHP benchmark file using your preferred text editor: ```console mkdir ~/phpbench-tests @@ -109,7 +126,8 @@ Create a new PHP benchmark file using your preferred editor: ```console vi ExampleBenchmark.php ``` -Then, add the following content to define your benchmark tests: +Add the following code to define your benchmark tests: + ```php + ├─ 4225 /usr/sbin/httpd-prefork -DSYSCONFIG -C "PidFile /run/httpd.pid" -C "Include /etc/apache2/> + ├─ 4226 /usr/sbin/httpd-prefork -DSYSCONFIG -C "PidFile /run/httpd.pid" -C "Include /etc/apache2/> + ├─ 4227 /usr/sbin/httpd-prefork -DSYSCONFIG -C "PidFile /run/httpd.pid" -C "Include /etc/apache2/> + ├─ 4228 /usr/sbin/httpd-prefork -DSYSCONFIG -C "PidFile /run/httpd.pid" -C "Include /etc/apache2/> + └─ 4229 /usr/sbin/httpd-prefork -DSYSCONFIG -C "PidFile /run/httpd.pid" -C "Include /etc/apache2/> + +Oct 15 18:55:30 pareena-php-test systemd[1]: Starting The Apache Webserver... +Oct 15 18:55:30 pareena-php-test systemd[1]: Started The Apache Webserver. +``` ### Verify PHP installation -Check if PHP is installed correctly and see the version installed. +After installation, verify that PHP is installed correctly and view the installed version: ```console php -v @@ -54,4 +78,4 @@ Copyright (c) The PHP Group Zend Engine v4.0.30, Copyright (c) Zend Technologies with Zend OPcache v8.0.30, Copyright (c), by Zend Technologies ``` -PHP installation is complete. You can now proceed with the baseline testing. +You can now proceed to the baseline testing section, where you’ll create and load a simple PHP web page to confirm that Apache and PHP are working together on your SUSE Arm-based virtual machine. diff --git a/content/learning-paths/servers-and-cloud-computing/php-on-gcp/instance.md b/content/learning-paths/servers-and-cloud-computing/php-on-gcp/instance.md index 2b93bc950d..21d515ef80 100644 --- a/content/learning-paths/servers-and-cloud-computing/php-on-gcp/instance.md +++ b/content/learning-paths/servers-and-cloud-computing/php-on-gcp/instance.md @@ -18,9 +18,9 @@ For support on GCP setup, see the Learning Path [Getting started with Google Clo To create a virtual machine based on the C4A instance type: - Navigate to the [Google Cloud Console](https://console.cloud.google.com/). -- Go to **Compute Engine > VM Instances** and select **Create Instance**. -- Under **Machine configuration**: - - Populate fields such as **Instance name**, **Region**, and **Zone**. +- Go to Compute Engine > VM Instances and select Create Instance. +- Under Machine configuration: + - Populate fields such as Instance name, Region, and Zone. - Set **Series** to `C4A`. - Select `c4a-standard-4` for machine type.