• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

PEAR open_basedir

L

l-case

Guest
I need pear on our server with plesk 7.5.3, but once installed i get the basedir not set.

In wich file can i set the basedir, so that all virtual hosts can use them?

Bye Peter
 
The safest place to put them would be in each domain's vhost.conf and vhost_ssl.conf files, since the httpd.conf and httpd.include files can (and will) be overwritten by Plesk at various times.
 
Is there an way to tell plesk it should include this open_basedir every time it creates an new domain ?

Bye Peter
 
Yes there is, you will need root ssh access to your server, and follow these instructions.

1. Create The File.

# cd /usr/local/psa/bin/
# vi addpear2php.sh

Add the following code to the addpear2php.sh file:
#!/bin/bash
cat > /home/httpd/vhosts/$1/conf/vhost.conf <<EOF
<Directory /home/httpd/vhosts/$1/httpdocs>
php_admin_value open_basedir /home/httpd/vhosts/$1/httpdocs:/tmp:/usr/share/pear
</Directory>
EOF

Save the file
# :wq!

2. Add To Plesk

Login to the plesk admin console and go to the server section.
Locate Event Manager and click on Add New Event.

Select Physical hosting created from the dropdown, normal in the priority list and root as the user and paste the follwing line into the Command text box:
/usr/local/psa/bin/addpear2php.sh <new_domain_name> <new_system_user>

Click OK to save the event.

3. Test It Out.

Select a client, preferably your default client which holds your website(s).

Add a new domain.

Login to SSH again, or go back to SSH if you still have it open.

# vi /home/httpd/vhosts/test-domain.com/conf/vhost.conf

Confirm the line has been added.

Your good to go, all new domains will have the pear open_basedir restriction removed.
 
enable PEAR on opened domain

Hi there,

I did follow ur instructions on enabling by default open_base dir and that seems to be ok... but how do i permit the open base dir on an account -domain that is already up and running and was before i run ur command ? This might seem a silly question but i'm a little confused. i did add on the include path in the php.ini the directory of PEAR and restarted apache but that didnt seem to work for my client domain..
 
You can either manually add the statements to the existing domain's vhost.conf file, or SSH into the server and do:

cd /usr/local/psa/bin/
addpear2php.sh name_of_existing_domain

If you want to manually add to vhost.conf:

cd /home/httpd/vhosts/name_of_existing_domain/conf/
vi vhost.conf

(add the following to the file)
<Directory /home/httpd/vhosts/name_of_existing_domain/httpdocs>
php_admin_value open_basedir /home/httpd/vhosts/name_of_existing_domain/httpdocs:/tmp:/usr/share/pear
</Directory>
(now save and quit)
:wq!

(restart apache either from control panel, or use following at shell prompt)
service httpd restart

If you need the same for SSL sites (https://) then you will have to do the same procedure for the vhost_ssl.conf file, as well as make a new script as traged1, but replace all occurences of 'httpdocs' with 'httpsdocs'
 
thanks jamesyeeoc

it seems to work with your sh script, but to point out some other issues for others to see.

before u posted it me i did find the solution to manually add to the conf file ymself the directive

<Directory /home/httpd/vhosts/<my_domain>/httpdocs>
php_admin_value open_basedir "/home/httpd/vhosts/<my_domain>/home/httpd/vhosts/<my_domain>/httpdocs/:/home/httpd/vhosts/<my_domain>/httpdocs/lib:/usr/share/pear/"
</Directory>

and also did the reconfiguration of the web server with

/usr/local/psa/admin/bin/websrvmng -u --vhost-name=<my_domain>

and restarted server from the control panel

but it always failed and it seemed that it did not include the .conf file at all, although i checked to see if the syntax was right...thats a little bit strange and still dont know why didnt work wihtout executing the script described above.. :/

Also while i tried to execute the .sh script that jamesyeeoc described above i did get a permission error, so i had to cmod the script to 777 and then execute it and then by magic everything worked fine after restarting the service from ssh

i dont know if creating the script of jamesyeeoc had to do anything with the manual overide of the conf file, but for me it seems to work now...

many thanks for ur time....
 
Actually the script posted was by Traged1, not by me. Any script file would have to be chmodded to +x (which would happen using 777) before it can be executed directly.

Certain things like:
and also did the reconfiguration of the web server with

/usr/local/psa/admin/bin/websrvmng -u --vhost-name=<my_domain>

according to Plesk 'must' be run, but personally I've never had to do it when making changes to my vhost files.

Restarting apache, that's a given and often we forget to state that.

The script just automates the insertion of the code into any new vhost.conf file for newly created domains, but is the same as manually editing an existing domain's vhost file.
 
Also keep in mind that the paths used in my example above are for Linux versions or the RPM based PLESK implementations. If you use BSD your paths may be different.
 
help

Can anyone guess why I am having difficulty executing the addpear2php.sh script?

permissions seem to be ok.

I get
-bash: addpear2php.sh: command not found

I apoligize if this is a stupid question I'm new at this.
 
Do you have the correct path set?

IE: /usr/local/psa/bin/addpear2php.sh

What OS are you using?
 
if you are using freebsd its likely that you will need the first line of the script to be

#!/usr/local/bin/bash

Of course you actually need to install the bash shell as well if you dont use that as norm.
 
I'm sorry I'm a complete noob.

I'm on Redhat.
I do have the correct path.

I'm not sure whether I have the bash shell.
I'll look into that now.

thanks for all the help so far.
 
If you're running RedHat, then you should have bash already installed.

If you did as he instructed
# cd /usr/local/psa/bin/
# vi addpear2php.sh
and the rest, then the correct path would be:

/usr/local/psa/bin/addpear2php.sh

Try doing one of the following at the shell prompt:
Method 1:
cd /usr/local/psa/bin
chmod 755 addpear2php.sh

then

./addpear2php.sh <nameofdomain.com> <==notice the period at the beginning.

Method 2:

cd /usr/local/psa/bin
bash addpear2php.sh
 
php_mailer

Hi I'm trying to do the same thing, but I can't seem to figure out or understand how the vhost.conf file is created and where exactly it is placed.

Using Fedora with Pleask and Qmail

Dutch
 
The vhost.conf file is not normally created for a domain. You would have to SSH into the server and create it from a command prompt editor such as nano, pico, or vi.

Normal location for RH type systems is:

/home/httpd/vhosts/yourdomain.com/conf/

There are actually 2 files you could create, depending on if you wish to affect the SSL or non-SSL website:

non-SSL = vhost.conf

SSL = vhost_ssl.conf

To add the open_basedir which includes what you need for such as osCommerce, you would put the following into the vhost.conf or vhost_ssl.conf file:

This is what I would normally put in for an osCommerce type site:

<Directory /home/httpd/vhosts/yourdomain.com/httpdocs>
php_admin_flag engine on
php_admin_value register_globals 1
php_admin_value safe_mode 0
php_admin_value open_basedir /home/httpd/vhosts/yourdomain.com/httpdocs:/tmp:/usr/share/pear
</Directory>

1=on, 0=off (had to do this with current PHP on RH), if the numbers don't work, then use on and off. Also if you are doing an SSL site, then change the 'httpdocs' to 'httpsdocs' in the lines above.
 
Here's a modification of /usr/local/psa/bin/addpear2php.sh that only adds the pear line if it hasn't already, and doesn't clobber an existing vhost.conf. Also does the same with vhost_ssl.conf

It's a drop-in replacement for the previosu posting, but you can also use it with 'modify physical hosting'.

You can also run it manually for existing domain names.

Code:
#!/bin/bash
if [ -f /home/httpd/vhosts/$1/conf/vhost.conf ];
then
        grep -q pear /home/httpd/vhosts/$1/conf/vhost.conf
        if [ $? -eq 1 ];
        then

                cat >> /home/httpd/vhosts/$1/conf/vhost.conf <<EOF
<Directory /home/httpd/vhosts/$1/httpdocs>
        php_admin_value open_basedir /home/httpd/vhosts/$1/httpdocs:/tmp:/usr/share/pear
</Directory>
EOF

        fi

else

        cat > /home/httpd/vhosts/$1/conf/vhost.conf <<EOF
<Directory /home/httpd/vhosts/$1/httpdocs>
        php_admin_value open_basedir /home/httpd/vhosts/$1/httpdocs:/tmp:/usr/share/pear
</Directory>
EOF


fi



if [ -f /home/httpd/vhosts/$1/conf/vhost_ssl.conf ];
then
        grep -q pear /home/httpd/vhosts/$1/conf/vhost_ssl.conf
        if [ $? -eq 1 ];
        then

                cat >> /home/httpd/vhosts/$1/conf/vhost_ssl.conf <<EOF
<Directory /home/httpd/vhosts/$1/httpsdocs>
        php_admin_value open_basedir /home/httpd/vhosts/$1/httpsdocs:/tmp:/usr/share/pear
</Directory>
EOF

        fi

else

        cat > /home/httpd/vhosts/$1/conf/vhost_ssl.conf <<EOF
<Directory /home/httpd/vhosts/$1/httpsdocs>
        php_admin_value open_basedir /home/httpd/vhosts/$1/httpsdocs:/tmp:/usr/share/pear
</Directory>
EOF


fi
 
Almost forgot to mention, you'll also need to edit /etc/php.ini, and add

safe_mode_include_dir = /usr/share/pear

Otherwise you'll get "the script whose UID is xxxx is not allowed to access /usr/share/pear/whatever whose UID is 0" errors.

This change will let your users access a global pear repository with safe_mode on.
 
Is vhost.conf included?

Are you *sure* vhost.conf is included in the apache configuration settings?

I have read through the default Plesk Apache configuration, starting with /etc/httpd/conf/httpd.conf and reading through most of the files it includes, and I cannot find an Include statement that would include the vhost.conf file for a given virtual domain.

I have created this vhost.conf file in the /var/www/vhosts/domain.com/conf directory:

<Directory /var/www/vhosts/domain.com/httpdocs>
php_admin_value open_basedir "/var/www/vhosts/domain.com:/usr/share/pear:/tmp"
</Directory>

However, according to the output of phpinfo.php, the open_basedir has not changed at all.
:confused:

We are using PSA: psa v7.5.4_build75051014.16 os_FedoraCore 3
 
Back
Top