Magento 2 requires a properly configured PHP environment to run smoothly. The latest stable PHP release, PHP 8.3, is supported and offers significant performance and security improvements. In this guide, you’ll learn how to install PHP 8.3 for Apache2 on Ubuntu 24.04 and configure it with recommended settings for Magento 2.
Prerequisites Before Installing PHP 8.3
Before you proceed, make sure you already have Apache2 installed and configured for Magento 2. PHP runs as a module inside Apache, so it depends on Apache being active first.
👉 If you don’t have Apache2 set up yet, follow our step-by-step guide here:
How to Install and Configure Apache2 on Ubuntu 24.04 for Magento 2
Once Apache is installed, you can continue with the PHP installation.
Updating Ubuntu 24.04 and Adding the PHP Repository
First, update your system package list:
sudo apt update
Then add the Ondřej Surý PHP repository, which provides the latest stable PHP versions:
sudo add-apt-repository ppa:ondrej/php
Update again to include the new repository:
sudo apt update
Installing PHP 8.3 and Required Extensions
Magento 2 needs multiple PHP extensions to work properly. Install PHP 8.3 along with all required modules:
sudo apt install -y php8.3 php8.3-mcrypt php8.3-gd php8.3-curl php8.3-mysql php8.3-zip php8.3-xml php8.3-soap php8.3-intl php8.3-mbstring php8.3-bcmath
This ensures your Magento environment has support for images, encryption, database connections, XML, SOAP, internationalization, and more.
Configuring PHP for Magento 2
Open the main PHP configuration file for Apache:
sudo nano /etc/php/8.3/apache2/php.ini
Update the following recommended values:
memory_limit = 2048M max_input_vars = 10000 max_execution_time = 3600 max_input_time = 3600 display_errors = On error_reporting = E_ALL post_max_size = 2024M
These settings give Magento enough resources to handle large imports, complex requests, and heavy workloads.
Restarting Apache2 to Apply PHP 8.3 Settings
Once your PHP configuration is updated, restart Apache to apply the changes:
sudo service apache2 restart
You can confirm PHP is working with:
php -v
It should display PHP 8.3 as the active version.
Conclusion: PHP 8.3 Ready for Magento 2
By installing and configuring PHP 8.3 with Apache2 on Ubuntu 24.04 for Magento 2, you’ve set up a secure and optimized PHP environment. With the correct extensions installed and performance settings tuned, your server is ready for the next step—installing and running Magento 2 successfully.
Leave a Reply