PHP sends mail as anonymous@servername

The from address is not enforced.  This can cause some PHP formmail script emails to be treated as spam.  Fix:

1) add a -f(sender address) parameter:

mail($to, $subject, $message, $headers, ‘-fsomeone@somewhere.com’);

2) add a Return-Path header:

mail($to, $subject, $message, ‘Return-Path:
someone@somewhere.com\r\nFrom: someone@somewhere.com’);

Qmail is *meant* to check for the from address field in Sender, From, Reply-To, Return-Path, Return-Receipt-To, Errors-To, Resent-Sender etc.
etc. *but* only Return-Path will actually set the address.

i.e
<?
$headers = “From: \”mydomain.com\” <webmaster@mydomain.com>\r\n” .
“Return-Path: <webmaster@mydomain.com>\r\n” .
“X-Mailer: PHP/” . phpversion();

mail(‘support@testy.com’,’test’,’test email from mydomain.com’, $headers,’-fwebmaster@mydomain.com’);

?>

PHP IMAP SSL error

if you are getting a certificate error when using the PHP IMAP function, add the /notls flag:

ie:

$mbox = imap_open (“{localhost:995/pop3/notls}”, “user_id”, “password”);

PHP file manager not working after upgrading to PHP 5.2

posix is not included with php 5.2 and above
do a yum install php-process

osCommerce broken after PHP/MySQL 5upgrade

osCommerce doesn’t seem to be very compatible with MySQL 5 and will most likely generate a load of errors from its SQL statements. Upgrading to the latest version is recommended and should fix this.  For heavily modified versions this may not be posible and will require some hacking to fix:

add () to from tables in all queries in all code (usually in includes includes/???) i.e from table1,table2 becomes from (table1,table2)
add auto_increment to tables where it is not entered on the primary key i.e banner_history

register_long_arrays and register_globals need to be enabled in php.ini

openssl unable to write random state

openssl genrsa -out test.pem 1024 -rand $HOME/httpdocs/cert/.rnd
Generating RSA private key, 1024 bit long modulus
…………………….++++++
…………………..++++++
unable to write ‘random state’
e is 65537 (0x10001)

Causing non-random keys to be generated
This is because openssl tries to create a .rnd file in the users home directory by default to create the random file.  The home directory in plesk is owned by root so the user does not have permission to write the file.  You can specify a new file by:

cd httpdocs/cert
touch .rnd
export RANDFILE=”/var/www/vhosts/c4fc.net/httpdocs/cert/.rnd

Plesk PHP open_basedir changes

To make a change to PHP for a site in Plesk, such as opening open_basedir, edit /var/www/vhosts/$domain/conf/vhost.conf. You would then add :

<Directory /var/www/vhosts/domain.com/httpdocs>
php_admin_value open_basedir “/var/www/vhosts/domain.com/httpdocs:/tmp:/THE_PATH_PHP_SCRIPT_TRIES_TO_ACCESS_TO”
</Directory>

After that, you will need to rebuild the apache configuration with the following command:

/usr/local/psa/admin/sbin/websrvmng -v -a

MySQL Replication over SSL

##Tutorial for MySQL Replication over SSL (one-way)##
#####################################################

##Check that SSL has been compiled in SSL on both the master and the client:

SHOW VARIABLES LIKE ‘have_openssl';
or
mysql –ssl –help
If it says disabled or yes then its fine.  If it says no then an SSL enabled version of MySQL needs to be installed.

##Create the SSL certificates on the master

Change to the mysql ssl directory (you may need to create it)
mkdir /etc/mysql/ssl
cd /etc/mysql/ssl/
Create your own Certification Authority (CA) if you do not already have one (e.g. for signing web or mail server certificates)

openssl req -x509 -new -days 9999 -newkey rsa:2048 -nodes \
-keyout ca-key.pem -out ca-cert.pem

MySQL repair corruption

for db:

mysqlcheck -uadmin -p$(cat /etc/psa/.psa.shadow ) –databases databasename –repair

for table:

check table tablename;

repair table tablename;

repair can lose data so a restore from backup may be necessary.

MySQL Log slow queries

edit /etc/my.cnf:

log-slow-queries=/var/log/mysql-slow.log
set-variable=long_query_time=6

restart mysqld

MySQL Log queries not using indexes

# Edit /etc/my.cnf
log-queries-not-using-indexes = /var/log/mysql-indexes.log