zend_mm_heap corrupted messages in apache logs

zend_mm_heap corrupted
if php5.2. google for patch
if php5.3 increase apc memory size in apc.ini

Posted in Linux | Leave a comment

Access Control Lists

Add ACL for apache user:

First see what ACLs exist already:

root@server1 mysite.org]# getfacl /var/www/vhosts/mysite.org/uploads
getfacl: Removing leading ‘/’ from absolute path names
# file: var/www/vhosts/mysite.org/uploads
# owner: user1
# group: user1
user::rwx
group::rwx
mask::rwx
other::r-x
default:user::rwx
default:group::rwx
default:mask::rwx
default:other::r-x

If apache user isn’t listed, do this:

setfacl -R -m u:apache:rwx /var/www/vhosts/mysite.org
setfacl -R -m d:u:apache:rwx /var/www/vhosts/mysite.org

Once you have them working as you want, back them up for safe keeping:
getfacl -R –absolute-names /foo/bar > /home/user/faclbackup

Posted in Linux | Leave a comment

Tune MySQL

wget http://www.day32.com/MySQL/tuning-primer.sh

sh tuning-primer.sh

Posted in Linux | Leave a comment

Common rewrite rules

The easiest way to redirect one site to another is by adding the following to the Virtualhost:

Redirect 301 / http://newsite.com/

Note: When AllowOverride is set to allow the use of .htaccess files, Apache will look in every directory for .htaccess files. Permitting .htaccess files causes a performance hit, whether or not you actually even use them! The .htaccess file is loaded every time a document is requested.

Redirect https traffic to http

By redirecting everything that comes in on port 443:

RewriteEngine On
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{HTTP_HOST} ^(www.)mydomain\.com$ [NC,OR]
RewriteRule ^/(.*)http://www\.mydomain\.com/$1 [R,L]

or by checking the x-forwarded-proto header:

RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://www.domain.com$1 [R=301,L]

Redirect http traffic to https

RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Redirect non-www to www:
(If you see an Internal Server error, check the logs for APC errors)

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]

or

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

Redirect www to non-www:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.yourdomain.com [NC]
RewriteRule ^(.*)$ http://yourdomain.com/$1 [L,R=301]

Redirect to maintenance page that displays image .jpg

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !/maintenance.html$
RewriteCond %{REQUEST_URI} !/image.jpg$
RewriteRule $ /maintenance.html [R=302,L]

 

Redirect for purpose of changing displayed URL
RewriteCond %{SERVER_NAME}  ^fubar.com$
RewriteRule ^/$ http://fubar.net [L]

#To make all letters in the url lowercase
RewriteEngine on
RewriteBase /
RewriteMap insensitive tolower:
RewriteRule ^[\/]*(.*)$ /${insensitive:$1} [R,L]

 

#For phpMyAdmin
RewriteCond %{HTTPS} off$
RewriteRule ^/phpmyadmin https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]$

RedirectMatch 301 ^(/phpmyadmin[^/]*/.*)$ https://hostname$1

Posted in Linux | Leave a comment

Number of processors/number of cores

cat /proc/cpuinfo | grep processor | wc -l

Counts the number of processor lines

Posted in Linux | Leave a comment

compression on your site

Ensure that the browser sends the Accept-encoding: gzip, deflate header

Add the following to your .htaccess file:

# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/js
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

# Or, compress certain file types by extension:


SetOutputFilter DEFLATE

Test it with this:

curl -s -I -H “Accept-Encoding: gzip” http://www.vickistan.com

[root@web01 wherever.com]# curl -s -I -H “Accept-Encoding: gzip” http://www.vickistan.com
HTTP/1.1 200 OK
Server:
X-Powered-By: PHP
X-Pingback: http://vickistan.com/xmlrpc.php
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 20
Content-Type: text/html; charset=UTF-8
Accept-Ranges: bytes
Date: Mon, 30 Jul 2012 14:55:44 GMT
X-Varnish: 1170541803
Age: 0
Via: 1.1 varnish
Connection: keep-alive

or use this site:

http://www.gidnetwork.com/tools/gzip-test.php

Posted in Linux | Leave a comment

PHP email script to test email

Sometimes you gotta test outgoing email. If you have php installed, it is as easy as adding the following into a file called something like emailtest.php and executing with php emailtest.php. Check the email logs to ensure it went out.

< ?php
$to = "someone@somewhere.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@somewhere-else.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
Posted in Linux | Leave a comment

Cool MySQL command list

# to see the full CREATE TABLE statement and show table engine
show create table table_name\G

#To see full CREATE TABLE statement on all tables in a database
export database=”dbname”;for table in `mysql -s –column-name=false -e “SHOW TABLES” $database`;do mysql -e “SHOW CREATE TABLE $table” $database;done

#convert a table from MyISAM to InnoDB
ALTER TABLE table_name ENGINE=InnoDB;

#watch the processlist fly by (from the command line/not a MySQL command)
watch “mysql -e ‘show processlist;'”

#List mysql users from the command line.
mysql -u root -B -N -p -e “SELECT user, host FROM user” mysql

#Show grants for particular myaql user instead of the one you are logged in as
SHOW GRANTS [FOR user]

#Add a new user with only SELECT and UPDATE on a specific database
grant SELECT,UPDATE on database.* to ‘user’@’%’ IDENTIFIED BY ‘PASSWORD’;

#Add a new user with all privileges on a specific database
grant all on database.* to user@’IP_ADDRESS’ IDENTIFIED BY ‘PASSWORD’;

#List all tables in all databases
USE information_schema;
SELECT TABLE_SCHEMA, TABLE_NAME FROM TABLES WHERE TABLE_SCHEMA NOT IN (‘mysql’, ‘information_schema’, ‘performance_schema’) ORDER BY TABLE_SCHEMA, TABLE_NAME;

#Dump all databases to a file
mysqldump –all-databases > /tmp/all.sql

#To import a database
mysql -u username -p -h localhost DATA-BASE-NAME < data.sql

#To turn on slow query logging from the mysql prompt

#Set the long query time to whatever is appropriate, the default is 10 seconds
mysql> SET GLOBAL long_query_time=1;
#Set the location that the slow query log should go to, make sure the folder path exists and that the mysql user has write permissions to it
mysql> SET GLOBAL slow_query_log_file=’/var/lib/mysqllogs/slow-log’;
#And finally set a variables to enable logging
mysql> SET GLOBAL slow_query_log=1;

#To Repair and Optimize all MySql tables:
mysqlcheck –u root –p –auto-repair –check –optimize –all-databases

#To get the sizes of your databases
SELECT table_schema “Data Base Name”, sum( data_length + index_length ) / 1024 / 1024 “Data Base Size in MB” FROM information_schema.TABLES GROUP BY table_schema;
#For extra points, tune your Innodb Buffer Pool accordingly.

#To dump tables t1, t2, t3, t7 from the database test:
mysqldump test t1 t3 t7 > tabledump.sql

#Determine whether a table is indexed:
show index from [table name]

Posted in Linux | Leave a comment

Copying Files in Linux bash shell

So you want to copy a file in Linux? Easy enough.

cp filename newfilename

But sometimes it isn’t so easy… Say the file you want to copy begins with a .

You can’t see these files unless you add -a to your ls command

ls -la
.bashrc
.bash_profile

Once you can see the file, you can copy it as follows:
cp .bashrc .bashrc2

Not so bad, but if it starts with a hyphen it requires special handling to prevent your shell from thinking you are passing a parameter to the cp command. You’ll need to precede the filename with a ./ as follows:

cp ./–filename newfilename

Another difficulty with copying files is when someone has either intentionally or unintentionally created a file with a non-viewable ASCII character in the name. Say, for instance, someone has created a file with a name preceded by an ASCII space or the name is only an ASCII space. How do you delete that file? The same way as we copied a file starting with a hythen above.

rm ./ filename

you can also use rm -i to force you to verify the deletion for extra protection.

Posted in Linux | Leave a comment

vi stuff

” at top of paragraph, format this paragraph
!} fmt -c

” for the whole file, format all paragraphs
!G fmt -c

“from here to the end of the file, format all paragraphs
!$ fmt -c

” from anwhere in the paragraph, format this paragraph
{!}fmt -c

Here’s how I map them in my .exrc file:
map @f !} fmt -c^M
map @F !G fmt -c^M
map ^Xf !$ fmt -c^M
map ^XF {!}fmt -c^M}^M

#To delete all lines which contain the string tornado watch:
:g/tornado watch/d

#To comment out all lines between line 6 and 22
:6,22 s/^/#/

#To run a python script inside vi
:!python script.py

Posted in Linux | Leave a comment