Use files from another virtual host

1
  

Summary

I need that from a virtual host, you can access the php files of another virtual host.

  

Environment

  • CentOS 7
  • Plesk Onyx
  • PHP 7.2
  

Scenario

I have the following scenario (real data is replaced):

  • api.dominio1.com (Core of the API, classes and operation of the API)
  • api.domain2.com (Serves the API to both domain2.com and the mobile APP)
  • dominio2.com (Frontal web)

In the api.dominio1.com I have what is the basic engine of the API and I need to be able to upload files from this site in api.dominio2.com

This I do so, because in the future open more domains that pull api.dominio1.com, this way I will not have to repeat code every time a new service is generated, always pulling api.domain1. com also, if the code is modified I will not have to go then updating it in all other domains.

  

Problem

When I do a require_once of the index.php of api.domain1.com from api.domain2.com it throws the following error:

AH01071: Got error 'PHP message: PHP Warning: require_once(): open_basedir restriction in effect. File(/var/www/vhosts/dominio1.com/api.dominio1.com/index.php) is not within the allowed path(s): (/var/www/vhosts/dominio2.com/:/tmp/) in /var/www/vhosts/dominio2.com/api.dominio2.com/index.php on line 4\nPHP message: PHP Warning: require_once(/var/www/vhosts/dominio1.com/api.dominio1.com/index.php): failed to open stream: Operation not permitted in /var/www/vhosts/dominio2.com/api.dominio2.com/index.php on line 4\nPHP message: PHP Fatal error: require_once(): Failed opening required '/var/www/vhosts/dominio1.com/api.dominio1.com/index.php' (include_path='.:/opt/plesk/php/7.2/share/pear') in /var/www/vhosts/dominio2.com/api.dominio2.com/index.php on line 4\n'

I understand that the problem is the openbasedir directive, which I would like to keep for the whole server and add an exception to this domain.

  

Current code

I have the following code in a file vhost.conf:

<Directory /var/www/vhosts/dominio1.com/api.dominio1.com>
php_admin_value open_basedir "/var/www/vhosts/dominio1.com/api.dominio1.com:/tmp:/var/www/vhosts/dominio1.com/api.dominio1.com"
</Directory>

After entering the vhost.conf using SSH I take the necessary steps to reconfigure and reload apache.

The server is our own and we only host our projects, so the simplest solution would be to disable the openbasedir for the entire hosting, although I would not like that option at all.

    
asked by jonilgz 27.11.2018 в 13:21
source

1 answer

0

What you want to do goes against the philosophy of virtual hosts. I recommend one of these two solutions:

  • Publish the API in api.dominio1.com, with access codes that will only be in the source code of the other domains that use the API.

  • If you want to have the source code of the API in each project (I do not recommend it), you can create a library and publish it in Github and Packagist. In each project you require the library with Composer and then it is a matter of doing composer update when you update the library.

  • answered by 27.11.2018 в 15:02