Skip to content

Arch Linux httpd/apache with php and the issue that php-cli can write to /usr/share/webapps but php-http (php-fpm) can not

I wanted to install dolibarr on my arch linux machine.

The first steps are simple and I tried to stick to the official but little outdated aur package.

#as root
cd /usr/share/webapps
mkdir dolibarr
cd dolibarr
git clone https://github.com/dolibarr/dolibarr -b 14.0.1 .
cd ..
choown -R http:http dolibarr
sudo -u http touch dolibarr/htdocs/conf/conf.php

cat > /etc/httpd/conf/extra/httpd-dolibarr.conf <<DELIM
Alias /dolibarr "/usr/share/webapps/dolibarr/htdocs"

<Directory "/usr/share/webapps/dolibarr/htdocs">
    AllowOverride All
    Options FollowSymlinks Indexes
    Require all granted
</Directory>

# vim: set ft=apache ts=2 sw=2 et:
DELIM

echo "#dolibar" >> /etc/httpd/conf/httpd.conf
echo "Include conf/extra/httpd-dolibarr.conf" >> /etc/httpd/conf/httpd.conf

systemctl restart httpd.service

After that, I wanted to open my http://<hostname>/dolibarr and it worked out quite well. The build in installation routine started and I was able to click to the next page to check the system.
Almost all went well but it took me hours to figure out why the installation routine complained about the conf.php file. It had the right permissions (u+rw) but the php built in is_writable is returning false for this file.

It wasn't a running selinux, it wasn't a wrong configured php open_basedir or php safemode. It really turned out, that apache http refuesed to allow writing to a file outside than the configured home path of /srv/http.
Even a softlink created in /srv/http linking to /usr/share/webapps/dolibarr was not working.
What was working is to mv /usr/share/webapps/dolibarr /srv/http and to adapt the httpd-dolibarr.conf.

Running Contao 3.x version and upgrading from PHP 5.x to PHP 7 results in a 500 Status?

I had the joy to debug a not working contao system line by line.

Why line by line? Because there was no entry in any logs, even with "log all motherfucker"-php.ini values on.

After parsing the lines, I ended up into this error message.

Fatal error: Cannot use 'String' as class name as it is reserved in ... system/modules/core/library/Contao/String.php on line 28

Well, nice to know the error but where was this triggered? So another round with joy and I ended up with an extension, of course installed "by hand" which means not possible to update by the contao updater and this lovely line.

$this->import('String');

After I've changed that line to the following line, all the gizmos where working again.

$this->import('StringUtils');

So, what should you do when you where faced with a 500 Apache Status Code after a contao installation moved from an PHP 5.x runtime environment to a PHP 7.x runtime environment?

cd <project root> grep -ir "import('String');" *

Replace >>import('String');<< with >>import('StringUtil');<< and that is it.

But all would be better if you are not installing extensions by hand.

determine if an apache process is still running via bash to prevent multiple instances running

Given is the fact that you have some processes (like cronjobs) executed via an webserver like apache. Furthermore you have installed and enables apache server status. To add some re usability benefits, we should divide and conquer the problems into either shell scripts or shell functions. Side note, if I am writing about shell, I am in the bash environment. What are the problems we want to tackle down?:

  • find the correct environment
  • check all available webservers if a process is not running
  • specify which process should not run and start it if possible

We can put the first two problems into shell functions like the following ones. I am referencing to some self written shell functions. The reference is indicated by the "net_bazzline_" prefix.

#!/bin/bash
#find the correct environment

if net_bazzline_string_contains $HOSTNAME 'production';
    NET_BAZZLINE_IS_PRODUCTION_ENVIRONMENT=1
else
    NET_BAZZLINE_IS_PRODUCTION_ENVIRONMENT=0
fi

And the mighty check.

#!/bin/bash
#check all available webservers if a process is not running
####
# @param string <process name>
# @return int (0 if at least one process was found)
####
function local_is_there_at_least_one_apache_process_running()
{
    if [[ $# -lt 1 ]]; then
       echo 'invalid number of arguments'
       echo '    local_is_there_at_least_one_apache_process_running <process name>'

       return 1
    fi

    if [[ $NET_BAZZLINE_IS_PRODUCTION_ENVIRONMENT -eq 1 ]]; then
        LOCAL_ENVIRONMENT='production'
    else
        LOCAL_ENVIRONMENT='staging'
    fi

    #variables are prefixed with LOCAL_ to prevent overwriting system variables
    LOCAL_PROCESS_NAME="$1"

    #declare the array with all available host names
    declare -a LOCAL_HOSTNAMES=("webserver01" "webserver02" "webserver03");

    for LOCAL_HOSTNAME in ${LOCAL_HOSTNAMES[@]}; do
        APACHE_STATUS_URL="http://$LOCAL_HOSTNAME.my.domain/server-status"

        OUTPUT=$(curl -s $APACHE_STATUS_URL | grep -i $LOCAL_PROCESS_NAME)
        EXIT_CODE_OF_LAST_PROCESS="$?"

        if [[ $EXIT_CODE_OF_LAST_PROCESS == "0" ]]; then
            echo "$LOCAL_PROCESS_NAME found on $LOCAL_HOSTNAME"
            return 0
        fi
    done;

    return 1
}

And here is an example how to use it.

#!/bin/bash
#specify which process should not run and start it if possible

source /path/to/your/bash/functions

LOCAL_PROCESS_NAME="my_process"

local_is_there_at_least_one_apache_process_running $LOCAL_PROCESS_NAME

EXIT_CODE_OF_LAST_PROCESS="$?"

if [[ $EXIT_CODE_OF_LAST_PROCESS == "0" ]]; then
    echo "$LOCAL_PROCESS_NAME still running"
    exit 0;
else
    #execute your process
    echo 'started at: '$(date +'%Y-%m-%d %H:%M:%S');
    curl "my.domain/$LOCAL_PROCESS_NAME"
    echo 'started at: '$(date +'%Y-%m-%d %H:%M:%S');
fi

You can put this into a loop by calling it via the cronjob environment or use watch if you only need it from time to time:

watch -n 60 'bash /path/to/your/shell/script'

Enjoy your day :-).

web - The Apache Software Foundation Celebrates 15 Years of Open Source Innovation and Community Leadership

The Apache Software Foundation Celebrates 15 Years of Open Source Innovation and Community Leadership


Apache has been at the forefront of dozens of today's industry-defining technologies and tools; nearly every end-user computing device has been touched by at least one Apache product. Budapest, Hungary –19 November– At ApacheCon Europe, members of the Apache community commemorated The Apache Software Foundation (ASF)'s fifteenth anniversary and congratulated the people, projects, initiatives, and organizations that played a role in its success.

Recognized as the leader in community-led Open Source software development, the ASF was established to shepherd, develop, and incubate Open Source innovations "The Apache Way". Reflections on achievements over the past 15 years include:
ASF @ 15 Statement by Chairman Brett Porter http://s.apache.org/RYD
Sponsorship and Stewardship by President Ross Gardler http://s.apache.org/oLh
Community Over Code by Executive Vice President Rich Bowen http://s.apache.org/AQJ

Source

Thanks for all the fish :-). Fingers crossed the foundation will stay