I have the following issue when I try to pass a shapefile to PostGIS. When I run this part of code through the terminal:

shp2pgsql -s 2100 -d /var/www/dkar/MarCO/Code/python/output/cluster/clusterNodes_.shp | psql -h localhost  -p **** -d ****** -U *******

It works perfectly and a new table in PostGIS is created, but when I try to do the same through a PHP script which I execute on a submit button then I get an error. I can not say for sure what's the error why I run the whole process through PHP exec so I just get an error code 2.

Also when I do the process through the terminal, I am asked for entering the db password. I also tried to include the password in the command like:

     `... -W password`

but it didn't make any difference.

The whole thing runs smoothly locally but it doesn't work in the remote server.

Any ideas what I might miss here?

Perhaps the path to the shapefile should be different in each case?

  • 1
    Try to run you php file on terminal with /path/to/php -f your-file.php, it can be related to which user is being used. – Jonatas Walker Sep 9 '15 at 11:25

The problem was related with the security authentication of PostgreSQL. After adjusting this in the configuration of the database I was able to login automatically using this:

shp2pgsql -s 2100 -d /var/www/dkar/MarCO/Code/python/output/cluster/clusterNodes_.shp | psql -U username -d databaseName

Hope this helps someone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.