Archive for Linux
All the content on my site was gone. When I went to investigate, I found my error log was filled with the following error:
WordPress database error Table ‘./database_name/prefix_posts’ is marked as crashed and should be repaired for query SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM prefix_posts WHERE post_type = ‘post’ AND post_status = ‘publish’ GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC made by require, require_once, include, do_action, call_user_func_array, flexx_after_content, get_sidebar, locate_template, load_template, require_once, dynamic_sidebar, call_user_func_array, WP_Widget->display_callback, WP_Widget_Archives->widget, wp_get_archives
A very scary looking error, but it was easy to fix.
My Preferred Repair Method
[user@server ~/public_html]$ mysql -u user -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1120449 Server version: 5.1.48 MySQL Community Server (GPL) Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. This software comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to modify and redistribute it under the GPL v2 license Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> connect database Connection id: 1120477 Current database: database mysql> select * from prefix_posts limit 1; ERROR 2006 (HY000): MySQL server has gone away No connection. Trying to reconnect... Connection id: 1120568 Current database: database ERROR 145 (HY000): Table './database/prefix_posts' is marked as crashed and should be repaired mysql> repair table prefix_posts; +-----------------------+--------+----------+----------+ | Table | Op | Msg_type | Msg_text | +-----------------------+--------+----------+----------+ | database.prefix_posts | repair | status | OK | +-----------------------+--------+----------+----------+ 1 row in set (3.56 sec) mysql> select * from prefix_posts limit 1; +----+-------------+---------------------+---------------------+--------------+------------+---------------+--------------+-------------+----------------+-------------+---------------+-----------+---------+--------+---------------------+---------------------+-----------------------+-------------+------------------------------------------------------------+------------+------------+----------------+---------------+ | ID | post_author | post_date | post_date_gmt | post_content | post_title | post_category | post_excerpt | post_status | comment_status | ping_status | post_password | post_name | to_ping | pinged | post_modified | post_modified_gmt | post_content_filtered | post_parent | guid | menu_order | post_type | post_mime_type | comment_count | +----+-------------+---------------------+---------------------+--------------+------------+---------------+--------------+-------------+----------------+-------------+---------------+-----------+---------+--------+---------------------+---------------------+-----------------------+-------------+------------------------------------------------------------+------------+------------+----------------+---------------+ | 12 | 8 | 2008-05-20 10:09:49 | 2008-05-20 15:09:49 | | 308image1 | 0 | | inherit | open | open | | 308image1 | | | 2008-05-20 10:09:49 | 2008-05-20 15:09:49 | | 0 | http://gaarai.com/wp-content/uploads/2008/05/308image1.gif | 0 | attachment | image/gif | 0 | +----+-------------+---------------------+---------------------+--------------+------------+---------------+--------------+-------------+----------------+-------------+---------------+-----------+---------+--------+---------------------+---------------------+-----------------------+-------------+------------------------------------------------------------+------------+------------+----------------+---------------+ 1 row in set (0.00 sec) mysql> exit Bye [user@server ~/public_html]$
For me, this was the easiest and quickest way to repair the table.
Repairing Tables with phpMyAdmin
For you, you might prefer to use phpMyAdmin. Fortunately, repairing a table with phpMyAdmin is easy.
- Log in to your phpMyAdmin or connect to it via your cPanel back-end.
- Select the database with the crashed table.
- Put a checkmark next to each crashed table.
- Select “Repair table” from the “With selected:” drop down at the bottom of the list.
- Let phpMyAdmin do its thing.
I’m working on building an ideal server setup that allows for both PHP 4 and PHP 5 on Apache with suPHP (I’ll blog about this later). While testing my PHP 4 build, I got the following error:
Warning: mysql_connect() [function.mysql-connect]: Client does not support authentication protocol requested by server; consider upgrading MySQL client in /var/www/test-php.php on line 3
Couldn’t authenticate with MySQL
The code I used to test this is quite simple:
<?php
if ( false === ( $db = mysql_connect( 'localhost', 'username', 'password' ) ) )
die( "Couldn't authenticate with MySQL" );
if ( false === mysql_select_db( 'database' ) )
die( "Couldn't connect to database" );
echo "Yay!";
?>
After digging around for a bit, I found that mixing PHP 4 with a MySQL version greater than or equal to 4.1 causes this problem. MySQL 4.1 introduced a new password caching scheme that PHP 4 can’t work with.
The solution is to update the database user’s password using the OLD_PASSWORD function of MySQL. For example:
[chris@office ~]$ mysql -u root -p mysql Enter password: Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 267 Server version: 5.1.41-3ubuntu12.1 (Ubuntu) Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> update user set Password=OLD_PASSWORD('password') WHERE User='username'; Query OK, 0 rows affected (0.02 sec) Rows matched: 0 Changed: 0 Warnings: 0 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql>
Note the underlined areas. That is where you’ll want to provide your own username and password.
Once you’ve followed these steps, both PHP 4 and PHP 5 will be able to communite with the database.
Thanks to digitalpeer for providing the answer to my issue.
I recently had a issue getting MySQL to read a specific database. Each time I tried to manually query a table in the database, I received the following error message:
ERROR 1018 (HY000): Can't read dir of './default/' (errno: 13)
I’ve seen this message before as it means that there is a permissions issue. I checked the ownerships and permissions, and everything seemed to be in order.
The only thing special about this database is that I have it symlinked to another partition. This has always worked in the past, so I was stumped.
The problem turned out to be that Ubuntu has AppArmor. This software sets up rules that prevent software from gaining access to different areas of the file system. In my case, AppArmor was preventing read and write access to the actual location of my database files.
The solution was quite easy: First, I added the path that I wanted MySQL to have access to in the AppArmor configuration file for MySQL. Second, I restarted the apparmor service. Here’s the technical details:
- On my system, the configuration file that controls MySQL permissions through AppArmor are located at /etc/apparmor.d/usr.sbin.mysqld. The following shows the contents of the file as it now exists:
# vim:syntax=apparmor # Last Modified: Tue Jun 19 17:37:30 2007 #include /usr/sbin/mysqld { #include #include #include #include #include capability dac_override, capability sys_resource, capability setgid, capability setuid, network tcp, /etc/hosts.allow r, /etc/hosts.deny r, /etc/mysql/*.pem r, /etc/mysql/conf.d/ r, /etc/mysql/conf.d/* r, /etc/mysql/my.cnf r, /usr/sbin/mysqld mr, /usr/share/mysql/** r, /var/log/mysql.log rw, /var/log/mysql.err rw, /var/lib/mysql/ r, /var/lib/mysql/** rwk, /var/log/mysql/ r, /var/log/mysql/* rw, /var/run/mysqld/mysqld.pid w, /var/run/mysqld/mysqld.sock w, /home/sites/default/mysql/ rw, /home/sites/default/mysql/* rw, /sys/devices/system/cpu/ r, }The two lines in bold show what I added to the configuation. The first line gives read and write access to the directory itself while the second gives read and write access to the files contained in the directory.
- After saving the configuration changes, I simply needed to restart the AppArmor daemon. I did this with the following command:
[chris@rommie ~]$ sudo service apparmor restart * Reloading AppArmor profiles Skipping profile in /etc/apparmor.d/disable: usr.bin.firefox
One of my all-time most popular posts was how to upgrade to Firefox 3.5 in Ubuntu 9.04. Now it’s Firefox 3.6′s turn to be installed on my system that is now running Ubuntu 9.10.
The team working on Firefox have put a ton of effort into this release and, in order to make our browsing lives safer and faster, rolled a number of features scheduled for 3.7 into this release. Thanks for all the hard work guys.
Read the 3.6 release announcement for details about what is new with this release.
So now onto the installation. Here are the commands that I ran in terminal to install 3.6.
[chris@rommie ~]$ cd /tmp/ [chris@rommie /tmp]$ wget "http://download.mozilla.org/?product=firefox-3.6&os=linux〈=en-US" --2010-01-21 11:41:08-- http://download.mozilla.org/?product=firefox-3.6&os=linux〈=en-US Resolving download.mozilla.org... 63.245.209.58 Connecting to download.mozilla.org|63.245.209.58|:80... connected. ... 100%[=============================>] 10,161,471 924K/s in 11s 2010-01-21 11:41:20 (899 KB/s) - `firefox-3.6.tar.bz2' saved [10161471/10161471] [chris@rommie /tmp]$ tar xvjf firefox-*.bz2 tar: Record size = 8 blocks firefox/ firefox/update.locale firefox/plugins/ firefox/plugins/libnullplugin.so ... firefox/defaults/autoconfig/platform.js firefox/defaults/autoconfig/prefcalls.js firefox/libmozjs.so [chris@rommie /tmp]$ sudo cp -r firefox /usr/lib/firefox-3.6 [sudo] password for chris: [chris@rommie /tmp]$ sudo mv /usr/bin/firefox /usr/bin/firefox.old [chris@rommie /tmp]$ sudo ln -s /usr/lib/firefox-3.6/firefox /usr/bin/firefox-3.6 [chris@rommie /tmp]$ sudo ln -s /usr/bin/firefox-3.6 /usr/bin/firefox
Simply run each command listed in white in your terminal to upgrade your system with the latest release version of Firefox.
After running these commands, close out Firefox, wait a few seconds to let everything shut down properly, and run Firefox again. If all the steps were executed properly and without error, you should be running 3.6. You can click Help > About Mozilla Firefox to confirm.
Happy browsing.
My dual monitor setup didn’t work properly in Ubuntu 9.04, Jaunty Jackalope. Fortunately, it does work properly in 9.10, Karmic Kaola. However, this newfound dual monitor setup has given me a new problem: how do I move my panels to the secondary monitor?
My office machine is a laptop. When I get in the office, I hook it up to a 24″ LCD. I’d like to use this external monitor as the primary, which means that I definitely want to have my panels display on it. However, as much as I tried to drag the panels around or play around with settings, there just didn’t seem to be a way to get them over there. However, I just figured it out.
By default, panels are set to expand. This means that the panels will span the entire width or height of the section of the window they occupy. If the expand option is disabled, they turn into self-sizing bar that can be dragged to different edges or centered.
Having the expand option disabled also allows you to grab and edge of the panel and drag it to another screen. Once on the screen you want it on, simply re-enable the expand option and you now have the panel on another screen.
Here’s a step-by-step way of moving a panel to another screen:
- Right-click the panel you wish to move and select “Properties”.
- Uncheck the “Expand” option under the “General” tab.
- Grab one of the edges of the panel by clicking on the left or right end (top or bottom end for vertical panels).
- Drag the bar to the desired screen and position.
- Check the “Expand” option in the “Panel Properties” window and click “Close”.
PEAR is PHP’s equivalent of Perl’s CPAN. It offers hundreds of ready-to-use code modules that can make projects go much more quickly than having to hand code everything. However, it never seems like PEAR is easy to get running.
Installing the Needed Software
In Ubuntu, installing the following packages will quickly get you started with PEAR: php5-cli, php5-dev, and php-pear.
Make sure that you read the next section about problems with using PEAR to install PEAR packages if you are running 9.10, Karmic Kaola.
Here’s an example of how to quickly install those packages from the terminal.
[chris@rommie ~]$ sudo apt-get install php5-cli php5-dev php-pear Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: autoconf autoconf2.13 automake automake1.4 autotools-dev libltdl-dev libssl-dev libtool m4 php5-common shtool zlib1g-dev Suggested packages: autobook autoconf-archive gnu-standards autoconf-doc gettext libtool-doc automaken gfortran fortran95-compiler gcj php5-suhosin The following NEW packages will be installed: autoconf autoconf2.13 automake automake1.4 autotools-dev libltdl-dev libssl-dev libtool m4 php-pear php5-cli php5-common php5-dev shtool zlib1g-dev 0 upgraded, 15 newly installed, 0 to remove and 5 not upgraded. Need to get 0B/8,690kB of archives. After this operation, 27.7MB of additional disk space will be used. Do you want to continue [Y/n]? y Selecting previously deselected package m4. (Reading database ... 127272 files and directories currently installed.) Unpacking m4 (from .../archives/m4_1.4.13-2_i386.deb) ... ...
With these packages, you are ready to roll with PHP and PEAR in Ubuntu.
Problem with Ubuntu 9.10 Karmic Kaola
A great thing about PEAR is that you can quickly install packages with a simple command. For example, “sudo pear install PHP_Parser-0.2.1″ will install the PHP_Parser package. However, this doesn’t work properly in Ubuntu 9.10, Karmic Kaola.
Output of the standard PEAR install command can be seen below:
[chris@rommie ~]$ sudo pear install PHP_Parser-0.2.1 downloading PHP_Parser-0.2.1.tgz ... Starting to download PHP_Parser-0.2.1.tgz (70,782 bytes) .................done: 70,782 bytes
While this doesn’t look wrong, it has actually failed. Rather than installing the package, it has simply downloaded the archive, encountered an unchecked error, and crashed. A successful installation has a message saying that the installation is successful.
This problem can be easily fixed by giving the install command the “-Z” option. For example:
[chris@rommie ~]$ sudo pear install -Z PHP_Parser-0.2.1 downloading PHP_Parser-0.2.1.tar ... Starting to download PHP_Parser-0.2.1.tar (Unknown size) .............................................................................done: 533,504 bytes install ok: channel://pear.php.net/PHP_Parser-0.2.1
Notice the “install ok: …” portion of the message. That’s what you should see at the end of a successful installation.
For more details on this bug, please check out Bug #451314 on the Ubuntu bug tracker.
I just encountered an odd issue with Ubuntu 9.10, Karmic Kaola. I had music playing in the background, I adjusted the volume, and I noticed that there wasn’t any change in the volume level. Even maxing out the volume and muting it had no effect.
After wondering if the problem was that I went insane, I looked in Sound Preferences (right-click the volume icon and select Sound Preferences) and found that “RV635 Audio device [Radeon HD 3600 Series] Digital Stereo (HDMI)” was selected under the device output. This means that Ubuntu was trying to send audio over my HDMI connection rather than through my headphone jacks.
This wasn’t a problem last night, so it might be due to the fact that my external monitor at the office runs over the HDMI connection, so it automatically switched to the HDMI audio output. In one way, this is nice, in another way, it will frustrate me to no end if it does this every time I’m at the office. If I’m right that it automatically switched upon detecting an active HDMI connection, then wouldn’t it be better to make it easier to provide a notification on where to switch the audio output rather than just switching it and causing confusion?

Switching the option to “Internal Audio Analog Stereo” instantly fixed the problem.
Oddly enough, when I manually selected the HDMI output again, it muted the analog output. So, it seems that it may not be a complete switchover or possibly just a bug. I’ll continue to see how the situation plays out and make a Ubuntu bug report if necessary.
Ubuntu 9.10, Karmic Kaola, launched earlier this week. One of the key new features in this release is Ubuntu One. Unfortunately, from what I’ve seen, this new feature/product launch has been anything but smooth.
Ubuntu One is one of the new ways that Canonical, the creators of Ubuntu, is trying to generate some revenue based on their distro. Ubuntu One is a hosted file storage solution that allows users to keep a folder and all of its content synced between multiple computers. All users get 2GB of storage for free with the option of increasing the store to 50GB for $10/month.
Since this new offering has many Ubuntu users very excited, I thought I’d give it a try as soon as I installed the new release. However, I was instantly met with a very big message telling me that something was wrong.
Continue reading “A Rough Launch for Ubuntu One on Ubuntu 9.10 – Karmic Kaola”
I recently tutored a friend in C coding. Since I hadn’t worked with C in at least 8 years, I really needed to have some references to rely on for syntax and other specifics. Fortunately, there are some easy man pages that can be installed in Ubuntu that offer helpful information that I was able to use to help refresh my memory.
These man pages are easily installed by installing the manpages-dev package. You can install this package via Synaptic or directly on the command line. I like the command line method personally, so I ran sudo apt-get install manpages-dev from the command line to quickly install the package.
After installing the package, I’m able to access man pages for functions such as printf, opendir, and putc. For each function, it shows the valid syntax as well as what library is required to make use of the function.
The information isn’t limited to functions as you can also access information on the libraries, such as stdio or string.
To access any of this information, simply run man [function or library name] such as man stdio.
This package isn’t limited to C functions/libraries. It is a general use Linux development suite of man pages. For a full list of what is installed, check out the file list.
I had fun writing about how I work with Git yesterday. I thought I’d continue on that thread.
I have a solid set of code libraries that I’ve written that latch into the WordPress themes we produce at iThemes. Each time code is duplicated across different repositories, I break that code out and make it into a separate repository. I then link it back into the project as a submodule. This makes it extremely-easy to keep duplicated code across numerous repositories updated with little or no fuss.
After cloning a repository, simply run git submodule init followed by git submodule update in order to initialize all the submodules and update their container folder with the content of the submodule’s repository. For a long time, this is exactly what I did when I would clone a theme repository to start working on it. However, this quickly wasn’t enough.
The problem happened as soon as I added a submodule to a repository that was also a submodule of other repositories. Doing the submodule init and update process wouldn’t do everything I needed in this case as there would be submodules in some subfolder that haven’t been set up.
I didn’t want to get into a habit of always switching to other directories and doing the submodule processes there as well since I 1) knew that I would forget all-too-often, thus wasting my time, and 2) knew that this would not be the last time that a submodule had submodules. Heck, there is even the possibility that I’ll have a submodule that has a submodule that has a submodule. It was immediately clear that I needed a script to do all this dirty work for me. The rest of this post will be about the script I created.






