Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

apache2.4 + php-fpm + phpmyadmin in debian

I have this setup in a debian: apache 2.4 proxy_fcgi and php-fpm (v5.5). In my virtualhost file i have:

<VirtualHost *:80>
DocumentRoot /var/www/html
ProxyPassMatch ^/(.*\.php(/.*)?)$ unix:/var/run/php5-fpm.sock|fcgi://./var/www/html
CustomLog ${APACHE_LOG_DIR}/access.log combined
ErrorLog ${APACHE_LOG_DIR}/error.log
</VirtualHost>

and everything works fine, i can see phpinfo() and every php file i request under /var/www/html/.

I continue with the phpmyadmin installation from the debian repo but when i browse to http://MY.IP/phpmyadmin i get a "File not found" error and in the apache error log

"[proxy_fcgi:error] AH01071: Got error 'Primary script unknown\n'"

Debian phpmyadmin package dumps the contents into /usr/share/phpmyadmin. If i create a test.html file under /usr/share/phpmyadmin i can see its contents from http://MY.IP/phpmyadmin/test.html

The problem is that php files under /usr/share/phpmyadmin are not being processed. The phpmyadmin apache configuration is this:

# phpMyAdmin default Apache configuration

Alias /phpmyadmin /usr/share/phpmyadmin

<Directory /usr/share/phpmyadmin>
        Options FollowSymLinks
        DirectoryIndex index.php

        <IfModule mod_php5.c>
                AddType application/x-httpd-php .php
                <FilesMatch ".+\.php$">
                    SetHandler application/x-httpd-php
                </FilesMatch>

                php_flag magic_quotes_gpc Off
                php_flag track_vars On
                php_flag register_globals Off
                php_admin_flag allow_url_fopen Off
                php_value include_path .
                php_admin_value upload_tmp_dir /var/lib/phpmyadmin/tmp
                php_admin_value open_basedir /usr/share/phpmyadmin/:/etc/phpmyadmin/:/var/lib/phpmyadmin/:/usr/share/php/php-gettext/:/usr/share/javascript/:/usr/share/php/tcpdf/
        </IfModule>

</Directory>
...

and is loaded in apache configuration file.

Since there is no mod_php installed there is no processing for the php files. How can i tell apache to use proxy_fcgi to process php files under /usr/share/phpmyadmin directory ?

>>update<< I added a proxypassmatch directive in phpmyadmin apache's conf

ProxyPassMatch ^/phpmyadmin/(.*\.php(/.*)?)$ unix:/var/run/php5-fpm.sock|fcgi:///usr/share/phpmyadmin/

expecting to work but i keep getting the same error.

>>update 2<< I replaced the php-fpm unix socket with network (127.1:9000) and replaced the virthualhost file's ProxyPassmatch with:

ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/html/$1

and in phpmyadmin's apache conf:

ProxyPassMatch ^/phpmyadmin/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/usr/share/phpmyadmin/$1
ProxyPassMatch ^/phpmyadmin/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/usr/share/phpmyadmin$1index.php

and everything works.. when i go to MY.IP/phpinfo.php i get the phpinfo from /var/www/html/phpinfo.php and when i visit MY.IP/phpmyadmin/phpinfo.php i get the processed contents of /usr/share/phpmyadmin/phpinfo.php.

My problem is solved but i still don't understand why the network connection with php-fpm works but the unix socket doesn't.

like image 898
papasj Avatar asked Apr 18 '14 21:04

papasj


2 Answers

I was struggling with this exact same issue and I could not get phpmyadmin to work. I was still getting the "File not found" mentioned above. My issue was I had to put mine in my ProxyPassMatch inside of my 000-default.conf file inside of my ./sites-available folder and I had to put these entries BEFORE my default one. This was outline at the very bottom of this page where I found the solution: http://jordanconway.com/set-up-apache-2-4-with-php-fpm-on-ubuntu-13-10/

Here is the way I have mine setup for reference.

<VirtualHost *:80>
   ...
    DocumentRoot /var/www/html
   ...
    ProxyPassMatch ^/phpmyadmin/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/usr/share/phpmyadmin/$1
    ProxyPassMatch ^/phpmyadmin/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/usr/share/phpmyadmin$1index.php
    ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/html/$1
</VirtualHost>
like image 83
Russell Griffith Avatar answered Sep 23 '22 06:09

Russell Griffith


Could this be due to a fact that sockets are being supported from Apache 2.4.9 and you used some earlier build of 2.4 perhaps?

like image 43
dzhi Avatar answered Sep 20 '22 06:09

dzhi