Monday 10 December 2012

Upload files in PHP when running plesk

  1. Log into Plesk and enable CGI/FastCGI support. Go to Tools and Settings>Apache Modules> Check fcgid
  2. Enable fcgid for your domain : /usr/local/psa/bin/domain -u example.com -php_handler_type fastcgi -fastcgi true
  3. Log into your server as root or sudoer account via SSH.
     
  4. Make a local copy of the PHP CGI binary program for your domain:
    cp /usr/bin/php5-cgi /var/www/vhosts/example.com/bin/
  5. Change the ownership of the bin directory and your new local copy of PHP:
    chown -R domainuser:psacln /var/www/vhosts/example.com/bin/
  6. Modify or create your local Apache configuration file, vhost.conf:
    vim /var/www/vhosts/example.com/conf/vhost.conf
    Add the following lines to the file: (may need to be created first)
    vhost.conf
    AddHandler fcgid-script .php
    SuexecUserGroup domainuser psacln
    <Directory /var/www/vhosts/example.com/httpdocs> FcgidWrapper /var/www/vhosts/example.com/bin/php5-cgi .php Options +ExecCGI +FollowSymLinks allow from all </Directory>
  7. Enable shared memory for FCGID:  echo "SharememPath /var/run/fcgid_shm" >> /etc/apache2/apache2.conf
  8. Reload your Apache configuration settings:
    /usr/local/psa/admin/bin/httpdmng  --reconfigure-domain example.com
  9. Restart Apache:
    /etc/init.d/apache2 graceful
PHP will now be running as FastCGI as the same user and group that owns your website files.
Adjust your sessions directory:

Since PHP will now be running as the script's user rather than apache, the permissions for the session folder need adjusted to account for this.

chmod 777 /var/lib/php5
Adjust permissions:

If you have already modified permissions, or your site has been running for a while on your server, you may need to correct file ownership and permissions. You can use the following commands to reset permissions and ownership to a "standard" state. You probably don't need to run these commands if you're configuring a new domain or have just installed your CMS.

cd /var/www/vhosts/example.com/httpdocs && \
chown -R domainuser:psacln * &&\
find . -type f -exec chmod 644 {} \; &&\
find . -type d -exec chmod 755 {} \;


You should consider adjusting the number of simultaneous FastCGI processes allowed for each domain and for the server overall, based on the number of domains that you have running FastCGI. The default configuration allows 64 total processes and 8 per domain. Edit your configuration file:
vim /etc/httpd/conf.d/fcgid.conf
Update the following variables, if desired:

fcgid.conf
MaxProcessCount 64
DefaultMaxClassProcessCount 8


You should set the DefaultMaxClassProcessCount to the number of processes you want a single domain to be able to run simultaneously. Multiply that number by the number of domains that are running FastCGI, and use that number for the MaxProcessCount. For example, if you have 4 domains using FastCGI, and you want them to run a maximum of 10 simultaneous processes each, you can set the following values:

fcgid.conf
MaxProcessCount 40
DefaultMaxClassProcessCount 10


Do not set these values arbitrarily high, as this may interfere with your server's memory usage. Alternately, you can pick a server maximum first for the MaxProcessCount, and then divide by the number of your domains to set the DefaultMaxClassProcessCount value.

Sunday 21 October 2012

MariaDB

Inspired by KP's post, here's how to install MariaDB on Centos.

For those interested, MariaDB is an alternative to MySQL that is (supposedly) 100% compatible with MySQL.

Considering the uncertain future of the MySQL project and the general attitude of Oracle, it's definitely worth a shot to give a try and test it out in your dev/test environment.

First, let's assume you use yum (if you're installing from source, I don't think you really need any help there).

Create a new repo in /etc/yum.repos.d/ (in my example it's for mariadb 5.5 and centos 6 64bits)

cat << EOF > /etc/yum.repos.d/mariadb.repo [mariadb] name = MariaDB baseurl = http://yum.mariadb.org/5.5/centos6-amd64 gpgcheck=1 EOF
import the GPG keys:

rpm --import http://yum.mariadb.org/RPM-GPG-KEY-MariaDB

then just install it by running:

yum install MariaDB-Server

Tuesday 24 July 2012

Why, aunic, why?

com.com.au is apparently an existing domain now (and has been for a while).

That makes DNS troubleshooting that much more interesting (especially when it's 2AM and you forget the trailing dot in your dns queries)