Detailed guide to installing and configuring PHP 7.4 on aaPanel with Apache: Optimal solution for Ubuntu 24.04

Operating legacy websites running on PHP 7.4 is becoming increasingly challenging as modern operating systems like Ubuntu 24.04 emerge. Ubuntu 24.04 (Noble Numbat) brings many security and performance improvements, but it also removes old libraries required by PHP 7.4 to function. This article delves into the most complex technical issues when using aaPanel, from installing dependencies to optimizing Apache configuration and handling redirect loop errors.

htaccess and wp-config configuration tips

1. Why is PHP 7.4 difficult to install on Ubuntu 24.04?

The main reason lies in the changes to the OpenSSL library. Ubuntu 24.04 uses OpenSSL 3.0, while PHP 7.4 is designed to be compatible with OpenSSL 1.1. Additionally, the default software repositories of the new Ubuntu no longer support PHP versions that have reached end-of-life (EOL) like 7.4. To overcome this barrier, we cannot use the “Fast” installation method (installing from prebuilt binaries) in aaPanel because these packages are often incompatible with Ubuntu 24.04's new library structure.

aaPanel provides two ways to install software: Fast (RPM/DEB) and Compiled (built from source). For PHP 7.4 on Ubuntu 24.04, the only option is Compiled. During compilation, the system automatically searches for available header files and libraries on the server to create the most compatible executable. This eliminates errors related to “shared library not found” commonly encountered with prebuilt packages.

2. Step 1: Install Legacy Dependencies

Before starting PHP installation in the aaPanel interface, you must prepare the system environment. The most important library is libssl1.1. Follow these commands to manually download and install it from the Ubuntu Focal security repository (an older version but still safely compatible):

# Download libssl1.1 package
wget http://security.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2.24_amd64.deb

# Install the package into the system
sudo dpkg -i libssl1.1_1.1.1f-1ubuntu2.24_amd64.deb

Installing libssl1.1 is completely safe and does not conflict with the existing OpenSSL 3.0. These two libraries exist independently as separate `.so` files (libssl.so.1.1 and libssl.so.3). Modern system applications will continue using version 3.0, while PHP 7.4 will find the required 1.1 version.

Additionally, installing compilation tools is mandatory for aaPanel to build PHP from source:

sudo apt update
sudo apt install -y build-essential libxml2-dev libssl-dev libsqlite3-dev libcurl4-openssl-dev libpng-dev libjpeg-dev libonig-dev libzip-dev

3. Step 2: Install PHP 7.4 from aaPanel App Store

Once the necessary libraries are available, access the aaPanel App Store. Search for PHP 7.4 and click Install. A popup will appear asking you to choose the installation method. Select “Compiled” instead of “Fast”.

The compilation process will take about 15-30 minutes depending on your server's CPU power. This method ensures PHP automatically links to the libraries available on your Ubuntu 24.04 accurately. Don't forget to open the task manager (the spinning arrow icon at the top right) to monitor progress.

4. Advanced .htaccess configuration for WordPress subfolders

Many users encounter 500 Internal Server Error when running WordPress in subfolders on Apache. This is often due to the file .htaccess missing parameter RewriteBase. Apache needs to know the base path of the subfolder to handle URL requests. Without this configuration, Apache will attempt to find files index.php in the root directory of the domain, causing not found errors or internal redirect loops.

Here is an optimal configuration example for a subfolder:

# BEGIN WordPress

RewriteEngine On
RewriteBase /your-subfolder/
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /your-subfolder/index.php [L]

# END WordPress

Important note: You must replace /your-subfolder/ with the actual folder name where WordPress is installed (e.g., /mywordpressfolder/). Also, ensure the folder ownership (Owner) is set to www and access permissions are 755 so Apache can read the files.

5. Fixing ERR_TOO_MANY_REDIRECTS

This error most commonly occurs in aaPanel's “Multi Webserver” setup (Nginx frontend acting as Reverse Proxy and Apache backend). Nginx receives HTTPS connections from the user's browser and forwards requests to Apache over HTTP (port 80 or internal port). WordPress on the backend does not recognize the original HTTPS connection, causing it to repeatedly issue HTTPS redirects, creating an endless loop and triggering `Too Many Redirects` in the browser.

To fix this thoroughly, you need to enforce protocol recognition in the WordPress configuration file. Open the file wp-config.php in your installation directory and insert the following header detection code X-Forwarded-Proto right above the line `/* That’s all, stop editing! */`:

/* Detect HTTPS from Reverse Proxy (Nginx) */
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
    $_SERVER['HTTPS'] = 'on';
}

/* Force correct URL to prevent loops */
define('WP_HOME', 'https://yourdomain.com/subfolder');
define('WP_SITEURL', 'https://yourdomain.com/subfolder');

Usage define('WP_HOME', ...) and define('WP_SITEURL', ...) in the config file takes priority over database settings, quickly resolving URL misconfiguration errors when you cannot access the Admin panel.

6. Conclusion and recommendations

Although PHP 7.4 has officially reached the end of its security lifecycle, the need to maintain legacy WordPress applications remains significant. By using aaPanel on Ubuntu 24.04 combined with Apache compilation techniques and Proxy Header configuration, you can create a stable and professional environment. However, always plan to upgrade your applications to newer PHP versions (such as 8.1 or 8.3) in the near future for maximum security.

Wishing you success in mastering your server!

DPS.MEDIA