background image

Content tagged with: linux

Eric's picture

This morning, I encountered a PHP fatal error on my development environment. Upon further inspection, one of my third party modules (XML Sitemap) required a later version of PHP. A fresh installation of Centos 5.3 comes with version 5.1.6 of PHP. Here is an easy way to upgrade PHP to a later version by using the Utter Ramblings Yum repository.

I created a new yum repo file:

$ sudo emacs /etc/yum.repos.d/utterramblings.repo

# FILE CONTENTS - START
[utterramblings]
name=Jason's Utter Ramblings Repo
baseurl=http://www.jasonlitka.com/media/EL$releasever/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka
# FILE CONTENTS - END

Ran a yum update:

$ sudo yum update
# ...snip...
Updated: apr.i386 0:1.2.12-2.jason.1 apr-util.i386 0:1.2.12-5.jason.1 curl.i386 0:7.15.5-2.1.el5_3.5 httpd.i386 0:2.2.8-jason.3 ksh.i386 0:20080202-2.el5_3.1 mod_ssl.i386 1:2.2.8-jason.3 mysql.i386 0:5.0.58-jason.2 mysql-server.i386 0:5.0.58-jason.2 pcre.i386 0:7.6-jason.1 php.i386 0:5.2.6-jason.1 php-cli.i386 0:5.2.6-jason.1 php-common.i386 0:5.2.6-jason.1 php-gd.i386 0:5.2.6-jason.1 php-mbstring.i386 0:5.2.6-jason.1 php-mssql.i386 0:5.2.6-jason.1 php-mysql.i386 0:5.2.6-jason.1 php-odbc.i386 0:5.2.6-jason.1 php-pdo.i386 0:5.2.6-jason.1 php-pear.noarch 1:1.6.2-1.jason.1 php-xml.i386 0:5.2.6-jason.1 php-xmlrpc.i386 0:5.2.6-jason.1 subversion.i386 0:1.4.4-jason.1 tzdata.noarch 0:2009k-1.el5
Complete!

After updating all these packages, I checked out my new PHP version:

$ php -v | head -1
PHP 5.2.6 (cli) (built: May  5 2008 10:32:59)

Now, my PHP fatal error has been resolved.

NOTE: This blog entry is a re-post of a previous article.

Eric's picture

Back in September 2008, I wrote an article on how to configure your virtual machine to deliver email locally (using postfix, cyrus, imap, and sasl). I've had to revisit this article recently to test some bulk emailing functionality. I wanted to change my email server configuration to deliver all email locally to ensure clients and coworkers do not receive test emails. After reading a bunch of web articles, I decided to use Postfix's transport functionality (located /etc/postfix/transport). This configuration file allows you to map email addresses and hostnames to message delivery transports.

I edited this file (/etc/postfix/transport) and added the following to the end of the file:

* discard:

I then edited my postfix configuration file (/etc/postfix/main.cf) and added the following:

transport_maps = hash:/etc/postfix/transport
always_bcc = eric

Reload the transport and restart postfix using the following commands:

postmap /etc/postfix/transport
/etc/init.d/postfix restart

The first configuration change discards all outgoing email, and the second automatically BCC's my user. Although this is a drastic configuration change, it does exactly what I want: it ensures that email will never be delivered to real world addresses, and any email sent from my development server will end up in my local inbox.

You may have to tweak these settings to find a configuration that works with your development situation. For instance, if you wanted to continue delivery to a certain domain, you could add the following transport:

your.domain :

Eric's picture

I just encountered a PHP fatal error when running my cron.php:

Fatal error: Call to undefined function timezone_open() in /MYSERVERPATH/httpdocs/sites/all/modules/date/date_api.module on line 607

A quick Google search, and I found the issue is documented here. The solution is to enable the Date PHP4 module. But, this issue does not happen in our production environment, so I decided to compare PHP versions:

# on the production server:
$ php -v | head -1
PHP 5.2.8 (cli) (built: Dec  9 2008 14:03:11)

It turns out, a fully updated installation of Centos 5.2 only supplies PHP 5.1.x. So, I decided to upgrade PHP in my development environment according to this documentation.

I created a new yum repo file:

$ sudo emacs /etc/yum.repos.d/utterramblings.repo

# FILE CONTENTS - START
[utterramblings]
name=Jason's Utter Ramblings Repo
baseurl=http://www.jasonlitka.com/media/EL$releasever/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka
# FILE CONTENTS - END

And, ran another yum update:

$ sudo yum update
# ...snip...
Resolving Dependencies
# ...snip...
Dependencies Resolved

=============================================================================
Package                 Arch       Version          Repository        Size
=============================================================================
Updating:
apr                     i386       1.2.12-2.jason.1  utterramblings    257 k
apr-util                i386       1.2.12-5.jason.1  utterramblings    159 k
httpd                   i386       2.2.8-jason.3    utterramblings    2.5 M
mod_ssl                 i386       1:2.2.8-jason.3  utterramblings    314 k
mysql                   i386       5.0.58-jason.2   utterramblings    6.4 M
mysql-server            i386       5.0.58-jason.2   utterramblings     10 M
pcre                    i386       7.6-jason.1      utterramblings    562 k
php                     i386       5.2.6-jason.1    utterramblings    3.7 M
php-cli                 i386       5.2.6-jason.1    utterramblings    2.6 M
php-common              i386       5.2.6-jason.1    utterramblings    481 k
php-devel               i386       5.2.6-jason.1    utterramblings    568 k
php-gd                  i386       5.2.6-jason.1    utterramblings    320 k
php-ldap                i386       5.2.6-jason.1    utterramblings     56 k
php-mbstring            i386       5.2.6-jason.1    utterramblings    1.3 M
php-mssql               i386       5.2.6-jason.1    utterramblings     61 k
php-mysql               i386       5.2.6-jason.1    utterramblings    258 k
php-odbc                i386       5.2.6-jason.1    utterramblings    112 k
php-pdo                 i386       5.2.6-jason.1    utterramblings    159 k
php-pear                noarch     1:1.6.2-1.jason.1  utterramblings    418 k
php-soap                i386       5.2.6-jason.1    utterramblings    342 k
php-xml                 i386       5.2.6-jason.1    utterramblings    316 k
php-xmlrpc              i386       5.2.6-jason.1    utterramblings    130 k
subversion              i386       1.4.4-jason.1    utterramblings    4.3 M

Transaction Summary
=============================================================================
Install      0 Package(s)        
Update      23 Package(s)        
Remove       0 Package(s)        

Total download size: 35 M
Is this ok [y/N]:

After updating all these packages, I checked out my new PHP version:

$ php -v | head -1
PHP 5.2.6 (cli) (built: May  5 2008 10:32:59)

Now, my PHP fatal error has been resolved :)

Eric's picture

Here's a quick script to reset ownership on a directory and then commit all changes (deletions, additions, and modifications) to subversion...

#!/bin/sh

_DIR="/path/to/my/svn/directory"
_DATE=`date +%Y\-%m\-%d\ %H\:%I\:%S`

_USER="Eric"
_GROUP="Eric"

# reset file ownership
find ${_DIR} -exec chown ${_USER}.${_GROUP} {} \;

# add new files
svn stat ${_DIR} | grep ^? | sed 's/^?      /svn add "/' | sed 's/$/"/' | sh

# remove deleted files
svn stat ${_DIR} | grep ^! | sed 's/^!      /svn del "/' | sed 's/$/"/' | sh

# commit modifications
svn commit ${_DIR} -m "Automated Commit: ${_DATE}"

Eric's picture

After losing my development virtual machine yesterday, I thought I'd document my process for creating a new one. The first thing to do is download your favorite Linux distribution. I prefer Centos (RHEL without the support contract) but what's most important is creating one that's as close to your production environment as possible (to avoid package version differences, differences in documentation, and deployment issues). The second step is creating a new virtual machine and defining it's properties. For a basic development system, I give it 512MB of RAM and a large enough hard drive for your projects. After defining it's properties, point the CDrom drive at your downloaded Linux distribution ISO and install the operating system. Here's the fun part, getting everything to work...

Update your packages

$ yum update

Install your favorite text editor

$ yum install emacs

Configure sudo so you don't have to use root (in: /etc/sudoers)

%wheel ALL=(ALL) NOPASSWD: ALL

Create a new user for yourself, and set your new password

$ adduser Eric
$ passwd Eric
# NOTE: add your user to the wheel group in /etc/group so you can setup sudo
# NOTE: add your user to the apache group and vice versa
# NOTE: from now on, log in as your user and use sudo to execute commands that require root privileges

Install subversion

$ sudo yum install subversion

Install mysql

$ sudo yum install mysql-server

Install PHP

$ sudo yum install php php-cli php-common php-devel php-gd php-ldap php-mbstring php-mssql php-mysql php-odbc php-pear php-soap php-xml php-xmlrpc
# NOTE: The previous command will automatically install Apache (httpd) as a dependency

(OPTIONAL) upgrade PEAR packages

$ sudo pear upgrade-all

(OPTIONAL) install additional PEAR packages

$ sudo pear install DB HTML_QuickForm Mail Mail_Mime

(OPTIONAL) install openssl for HTTPS traffic

$ sudo yum install mod_ssl openssl

Set run levels for mysql and apache to ensure the services start automatically

$ sudo /sbin/chkconfig --level 2345 httpd on
$ sudo /sbin/chkconfig --level 2345 mysqld on

Set MySQL passwords

# root password:
$ /usr/bin/mysqladmin -u root password 'YOUR-NEW-PASSWORD'

# your user:
$ mysql -u root -p
mysql> grant all privileges on *.* to 'Eric'@'localhost' identified by 'YOUR-NEW-PASSWORD' with grant option;

# (OPTIONAL) you can add privileges for your user to connect from other computers:
mysql> grant all privileges on *.* to 'Eric'@'%' identified by 'YOUR-NEW-PASSWORD' with grant option;

Configure PHP (edit /etc/php.ini)

$ sudo emacs /etc/php.ini
display_errors = [Off per prod | On per dev/test]
error_reporting = E_ALL & ~E_NOTICE
memory_limit = 100M
upload_max_filesize = 100M
post_max_size = 100M

Configure Apache

# create a directory for all your vhosts, and set permissions
sudo mkdir /var/www/vhosts
sudo chown -R Eric.Eric /var/www/vhosts
sudo chmod -R 2770 /var/www/vhosts

# create a new configuration file to keep your changes separate from httpd.conf
$ sudo emacs /etc/httpd/conf.d/Eric.conf

# FILE CONTENTS - START

# set directory indexes to ensure php files are not read as text
DirectoryIndex index.php index.html index.html.var index.htm

# set a default character set
AddDefaultCharset ISO-8859-1

# enable name based virtual hosts, so you can host multiple hostnames on one server
NameVirtualHost *:80

# I create a separate directory for all my virtual hosts. This allows .htaccess files to work properly
<Directory /var/www/vhosts>
AllowOverride All
</Directory>

# add your first virtual host entry
<VirtualHost *:80>
ServerName SITEHOSTNAME
DocumentRoot /var/www/vhosts/SITEHOSTNAME/httpdocs
ErrorLog logs/SITEHOSTNAME-error_log
CustomLog logs/SITEHOSTNAME-access_log common
</VirtualHost>

# FILE CONTENTS - END

Configure MySQL (edit /etc/my.cnf)

[mysqld]
set-variable = max_allowed_packet=32M

Start Apache & MySQL

$ /etc/init.d/mysqld start
$ /etc/init.d/httpd start

(OPTIONAL) Configure Samba so you can edit your virtual machine filesystem from your host operating system
[documentation here]

Now, from your host operating system, edit your /etc/hosts file and point your development hostname to the new IP address of your virtual machine. If you go to that web address you should be able to reach your Apache virtual host on your new virtual machine!