Change Max File Upload via php.ini

Backup your php.ini file before you do anything.

Then open the php.ini file so that you can edit it.

Check that file_uploads is set to On (needed to upload files via a PHP script).

Set upload_max_filesize to 64M (or less).

Set post_max_size to 64M (or less).

Set memory_limit, to 64M (or less).

Set max_input_time to 600 or less.

Set max_execution_time to 300 or less.

Save your php.ini file.​

(or minimal modifications):

upload_max_filesize = 500M
post_max_size = 500M
max_execution_time = 500

Update WordPress Site Url and Home values via MySQL

1. First, check the current values:

SELECT * FROM wp_options WHERE option_name = “siteurl”; 

SELECT * FROM wp_options WHERE option_name = “home”;

2. Then modify the values:

UPDATE wp_options SET option_value=”http://[new domain name or ip address, without trailing slash]” WHERE option_name = “siteurl”;

UPDATE wp_options SET option_value=”http://[new domain name or ip address, without trailing slash]” WHERE option_name = “home”;

3. Check the new values:

SELECT * FROM wp_options WHERE option_name = “siteurl”; 

SELECT * FROM wp_options WHERE option_name = “home”;

 

The best way to generate random numbers in JavaScript

var myRand = Math.random(); // Get a random number from 0 to 1
var zeroToSix = myRand * 6; // Get a random number from 0 to 6, not including 6
var zeroToFive = Math.floor(zeroToSix); //Floor it, maiking it 0 to 5
var oneToSix = zeroToFive + 1; // Guarantees that it will be 1 to 6
console.log(oneToSix); //Result

//or, quite simply:

var result = Math.floor(Math.random() * 6) + 1;
console.log(result);

Explanation: Math.random() has a chance to return 0. If we use Math.ceil(0) we may still get 0, which will result in the range of 0 to 6, not 1 to 6, and may mess up our program. So the proper way is Math.floor() + 1 Credit: David McFarland

Set ownership and permissions for WordPress on Amazon EC2

Everything in /var/www owned by root user and www group:

sudo chown -R root:www /var/www

Set /var/www directory permission to owner rwx, group rwx, and everyone else to r-x

sudo chmod 2775 /var/www

Set all current and future directory permissions to owner rwx, group rwx, and everyone else to r-x

find /var/www -type d -exec sudo chmod 2775 {} +

Set all current and future file permissions to owner rw-, group rw-, and everyone else to r–

find /var/www -type f -exec sudo chmod 0664 {} +

Restart Apache

sudo service httpd restart

Useful Commands for Less Reader

PAGE UP or b   Scroll back one page.

PAGE DOWN or Spacebar    Scroll forward one page.

Up Arrow    Scroll up one line.

Down Arrow    Scroll down one line.

G   Move to the end of the text file.

g    Move to the beginning of the text file.

/hello    Search forward to the next occurrence of characters.

n    Search for the next occurrence of the previous search.

h     Display help screen.

q   Quit less.

Fix a Broken / Corrupted Database or Database Tables

First, back up the server (including the database) by creating the image. This way if anything goes wrong, you can always try again.

Then use this fast and easy fix:

mysqlcheck –repair –all-databases

Or, as is the case at Amazon account that I manage:

mysqlcheck -u root -p –repair –all-databases

Password: the root MySQL password. 

If you want to fix certain known tables:

sudo su

cd var/lib/[name of the database]

myisamchk –recover [table name]

In WordPress, you can also go to the wp-config.php:

nano /var/www/html/wp-config.php

and add this line to it:

define(‘WP_ALLOW_REPAIR’, true);

– and then go to wp-admin in the URL and click the repair link that appears there instead of the login

Of course,  you can also repair tables using a graphical user interface, such as phpMyAdmin, if it’s available.

NOTE: This will not work for InnoDB tables, however.

So, how do you repair InnoDB?

One easy way of doing it:

First, check the status of the tables, to see which ones are InnoDB based:

mysqlshow –status -u root -p <database name>

Then login to MySQL and select the database you need to fix.

Then:

create table <new table> like <old table>;

insert <new table> select * from <old table>;

truncate table <old table>;

insert <old table> select * from <new table>;

Basically, creating a new table, dumping data from old table into it. Trunkating the old table (apparently repairs it) – ad then migrating data back into it.

More detailed approach:

http://www.percona.com/blog/2008/07/04/recovering-innodb-table-corruption/