Site Down!!

The last couple of hours my site was down and the cause was my IP address had changed. The way I figured this out was first trying to access my site locally and that worked. Checked my apache error and access logs (/var/log/apache2) and there were no signs of hackers. Tried to access my site through my IP address and that didn’t work, so I search to see what was my current IP address and it had changed. Then I went to my hosting sites and changed the IP address they were directing to. Now its fixed and running.

/var/log/apache2/error.log also records php errors

Bring it together

The past couple of years I’ve been learning many different technologies starting with after effects, photoshop, web design, programming and circuitry. I do this not on purpose but by accident and wonder whether it’s a lack of focus.

However, I’m doing what I enjoy and all this learned knowledge seems to come in handy on whatever project I’m currently working on.

I ran into a quote by Steve Jobs that identified with this.

Ultimately it comes down to taste. It’s a matter of trying to expose yourself to the best things that humans have done. And then try to bring those things into what you are doing. Picasso had a saying: “Good artists copy. Great artists steal.”

Faster Database

You should use indexes where its required to speed up your queries. Keep them simple and don’t create indexes that are not being used by your queries. Indexes slows down INSERT and UPDATE. Indexies are beneficial on columns that are used for WHERE, ORDER BY or a SQL function.

Example in the MySQL console or terminal

select a database

mysql> USE pua;

run a query

mysql> SELECT count(date) FROM stats;

mark the time it took to process = 0.01 sec
and then make the “date” column an index

run the query again

mysql> SELECT count(date) FROM stats;

mark the time it took to process = 0.00 sec
as you can see the time went down

You can check which indexes are being used by running EXPLAIN

mysql> EXPLAIN stats;

tags:
faster, query

How to install memcached on Lampp for Ubuntu 11.10

Install the server and php extention:

$ apt-get install memcached
$ pecl install Memcache

Edit your php.ini:

$ nano opt/lampp/etc/php.ini

Add the following line to the file and save the changes:

extension=/path/to/extension/memcache.so

If you only provide the name of the extension, PHP will look for it in its default extension directory. If not found it will not work. Path Eg: /usr/lib/php5/200905+lfs/memcache.so

Restart Lampp:

/opt/lampp/lampp restart

To check if memcached is running:

$ ps aux | grep memcached

Sample code:

<?php    
$memcache = new Memcache;
$memcache->connect("localhost",11211); # You might need to set "localhost" to "127.0.0.1"

echo "Server's version: " . $memcache->getVersion() . "
\n"; $tmp_object = new stdClass; $tmp_object->str_attr = "test"; $tmp_object->int_attr = 123; $memcache->set("key",$tmp_object,false,10); echo "Store data in the cache (data will expire in 10 seconds)
\n"; echo "Data from the cache:
\n"; var_dump($memcache->get("key")); ?>

The memcached configuration file can be found here:

/etc/memcached.conf

Access MySQL database Remotely

After a long research and unnecessary changes in order to access mysql database over a PHP script or a command line/terminal.  What is needed is to add privilege to you MySQL database and edit the my.cnf file, eg:

mysql> GRANT ALL PRIVILEGES ON mydb.* TO 'myuser'@'%' WITH GRANT OPTION;
and comment out the line in /etc/mysql/my.cnf

# bind-address = 127.0.0.1

Restart server

I’m using Ubuntu 11.10 and it didn’t need to install telnetd, or mess with the iptables. Again all is needed is to give or change mysql privileges and edit my.cnf.

Now an issue you may come across is having a firewall on your system like shorewall. Either stop shorewall (/etc/init.d/shorewall stop) or give privileges to allow access by editing the /etc/shorewall/rules and type mysql as an additional ACCEPT permission.

Now to access it outside your home network and anywhere in the world you’ll need to access your router port forward. Insert mysql port 3306 like you would do for you http 80 and ssh 22 request.

Login example

$ mysql -h192.168.1.1 -uUSERNAME -pPASSWORD

if you telnet you should see this

user@ubuntu:~ $ telnet youdomain.com 3306
Trying 13.1.24.131...
Connected to yourdomain.com.
Escape character is '^]'.
b
5.5.5-10.0.27-MariaDB-0+deb8u1 "UdxPf2?▒xU}:F2e*=66Lmysql_native_password

tags:
host