skip to Main Content

I have compiled Apache2 2.4.57 with a custom OpenSSL version, then installed php8.2. It is a test web server I used locally on localhost:8080. The server works with the test page of Apache.

Apache2 is installed under /usr/local/apache2

I used sudo a2enmod php8.2 to enable PHP.

I created a test.php page and copied it under htdocs:

<?php
    phpinfo();
?>

to test the PHP install but it doesn’t work. When I type localhost:8080/test.php in Chrome it only shows the page’s code.

I’m not a web dev at all. I followed the following tutorial https://computingforgeeks.com/how-to-install-php-8-2-on-ubuntu/

Is there anything else to do in the httpd.conf to enable PHP?
Is it normal that after running sudo a2enmod php8.2 I see no modification in httpd.conf?

I have also tried to use php8.2-fpm but it doesn’t work either.
I’m just planning to stream a simple video to a video player (ffplay) using https with my custom version of OpenSSL.

I thought that Apache+php was simple to install but it seems impossible to configure 🙁

Anyone could help?
Thanks

2

Answers


  1. Chosen as BEST ANSWER

    Thanks Yeung

    I followed your advice and managed to compile php8.2 with my Apache version.

    I followed the following information: https://gist.github.com/z2z/3bf4c60b7f0c0171d410d54bad088e6e

    However, I found out that there were a couple of differences once PHP was compiled. For my purpose, I didn't need any DB so I removed the DB dependencies.

    My apache is installed there: /usr/local/apache2/ I have a customed version of openssl there: /usr/local/bin/openssl

    Apache compilation is configured in the following way:

    ./configure --with-ssl=/usr/local/bin/openssl --with-expat=/usr/local/include --enable-so --enable-mime-magic
    

    php8.5 compilation is configured in the following way:

    ./configure --with-apxs2=/usr/local/apache2/bin/apxs --prefix=/usr/local/apache2/php --with-config-file-path=/usr/local/apache2/php --disable-cgi --with-zlib --with-gettext --without-pdo-sqlite --without-sqlite3
    

    Both compiled and installed with:

    make
    sudo make install
    

    The installation requires running (I don't know why...):

    /usr/local/apache2/build/libtool --finish /home/youruser/Desktop/apache/php-8.2.5/libs
    

    Once compiled php8.2 creates the module: php_module for apache2. It can be verified using:

    /usr/local/apache2/bin/httpd -M
    

    It also creates the library libphp.so under modules.

    To activate php I added the following to httdp.conf

    LoadModule php_module modules/libphp.so
    
    <FilesMatch ".+.ph(?:ar|p|tml)$">
        SetHandler application/x-httpd-php
    </FilesMatch>
    <FilesMatch ".+.phps$">
        SetHandler application/x-httpd-php-source
        # Deny access to raw php sources by default
        # To re-enable it's recommended to enable access to the files
        # only in specific virtual host or directory
        Require all denied
    </FilesMatch>
    # Deny access to files without filename (e.g. '.php')
    <FilesMatch "^.ph(?:ar|p|ps|tml)$">
        Require all denied
    </FilesMatch>
    
    # Running PHP scripts in user directories is disabled by default
    # 
    # To re-enable PHP in user directories comment the following lines
    # (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
    # prevents .htaccess files from disabling it.
    <IfModule mod_userdir.c>
        <Directory /home/*/public_html>
            php_admin_flag engine Off
        </Directory>
    </IfModule>
    

    Then I created a php file in htdocs with:

    <?php
        phpinfo();
    ?>
    

    to verify that PHP works!

    Fortunately, all this would only be required if you need to use PHP with a custom compilation of Apache2!


  2. a2enmod is a command tools by Debian / Ubuntu written specifically to support their apache2 package. It is NOT a tool to support custom compiled Apache2. To use PHP with it, you need to manually compile PHP from source code against your compiled copy of Apache2.

    This is not recommended because you’d have to manually patch and update your Apache to avoid vulnerability of old version being exploit.

    If you do not have a preference to PHP version, you should try to install PHP in one of 2 ways:

    1. Apache with mod_php; or
    2. Apache with mod_fastcgi + php-fpm

    The first method should be more straight forward:

    sudo apt install php libapache2-mod-php
    sudo systemctl restart apache2
    

    If you need PHP 8.2 on your Ubuntu server but still want to use stock Apache package, then you should install PHP 8.2 with PPA:

    LC_ALL=C.UTF-8 sudo add-apt-repository ppa:ondrej/php
    sudo apt update -y
    sudo apt install php8.2 libapache2-mod-php8.2 php8.2-mysql
    sudo systemctl restart apache2
    

    P.S. PHP-FPM is very flexible if you need to run multiple PHP versions in parallel. But that would take you a lot more understanding in what you’re doing.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search