Archive for PHP
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.
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.
Sorry about the late post everyone. I had a long week and went to bed before making sure a post was queued. Hopefully you’ll forgive me.
I’m working on a project where I needed to generate a MIME type given a file name. Not only did I need to create a solution that worked, I also needed the solution to be compatible with PHP 4/5 and not require any additional software to be installed on the host. I thought this would be a simple matter of finding a PHP function that does this. Unfortunately, things were not as simple as this.
Yesterday, I talked about how to get the most out of running regular expressions in PHP. The reason that I needed to dig in deep on regular expression syntax with PHP is because I needed to write some regular expressions that deal with Unicode characters.
After much reading, I believed that I knew everything that I needed. I started writing some regex strings and testing the code. Unfortunately, every time I ran a test with a string that contained Unicode characters, the match failed. When I removed the Unicode characters from the string and tested again, it would work. I was baffled.
Continue reading “Unicode Support on CentOS 5.2 with PHP and PCRE”
Since beginning work on my DNS Yogi site, I’ve had to do numerous regular expressions to matching all sorts of string bits. I quickly ran into problems when I realized that I need to add support for Unicode characters since certain TLD registrars support registrations with non-Latin characters.
The main issue is that there are multiple regular expression engines. PHP uses a flavor of the PCRE (Perl Compatible Regular Expression) engine. Each engine and varient of an engine has a slightly different way of handling regular expression syntax. I needed to find out exactly how the PHP regular expression engine worked, and finding that information was not easy.
FFmpeg is an amazing collection of open-source tools that can record and stream video and audio. However, it can also transcode video and audio (convert the files to different formats), and that is what has me so excited. There’s also a great PHP package called ffmpeg-php that allows for easy use of FFmpeg from inside PHP scripts. Today, I’m going to see if I can’t help you get both of these set up on your system.
Admittedly, it’s been a while since I’ve tried to install FFmpeg, about two years. I recently thought up some ideas on how I’d like to use FFmpeg, so I thought it was time to give it a try yet again. Today, I’m proud to say that installing FFmpeg is so much easier to install compared to the past, that I dare say it’s simple.
Here is my experience with installing FFmpeg on my server and how to fix the pitfalls that I encountered.
Continue reading “Install FFmpeg and ffmpeg-php on CentOS Easily”
I’m working on a project where I needed to convert an XML doc into an associative array in PHP easily. I hadn’t done any work with XML in PHP yet, so I started digging around the usual places.
Soon, it looked like my best option would be to create a completely-custom XML parsing engine out of PHP’s built-in XML Parser. I started working on a set of code based off of the External Entity Example since that is the only example that actually incorporates the ability to retrieve data and not just attributes. My results were slow and very error prone. Why is this so tough? XML isn’t exactly new, and it is very widespread. Similarly, PHP is an extremely popular language. So, why is it so hard to combine the two and work with them easily? I shouldn’t have to create a custom syntax parser just to be able to read a standard format document into a PHP data structure.
I had to configure Sendmail in order for Ubersmith to be able to receive support requests via email. Basically, you configure an alias (/etc/aliases) like so:
support: "|php -q -f /home/html/cron/gateway.php domain.com 1"This all seemed to be very straightforward. I didn’t even think to test it until hours later. When I finally did test out the support request by email function, I received this very abrupt rebuke from Sendmail in the form of a bounceback:
Continue reading “smrsh: “php” not available for sendmail programs (stat failed)”
Today I’m installing Ubersmith, a billing system solution, on a server to test it out. I have to say that Ubersmith has a more complex installation process than I’m used to these days. I guess that I’ve been spoiled.
Here’s a quick word about what I’m running. My test server is a dedicated system running CentOS 5.2 64-bit. The software setup is nothing special as most of the packages are straight from the repository.
I loaded the release files on the server, untarred them, and proceeded to read the instructions. Everything looked to be straight-forward. I quickly got down to the part about installing Ioncube. That’s when the trouble started.
Continue reading “Trouble with Ubersmith, Ioncube, and mb_internal_encoding”












