Wojtek Naruniec

Fix Apache broken after OS X Yosemite update

I could call it OS X tradition, Apple again broke the Apache 2 installation with latest OS X Yosemite upgrade. Let’s see how you can fix that and bring your local Apache2, PHP5 and MySQL development environment back.

I did very naive thing and just started the Apache 2 using sudo apachectl start . It worked, I got “It works!” page but nothing more. Then I reviewed Rob Allen’s article about setting up PHP & MySQL on Yosemite. He described steps on setting that on clean install but I needed to go through different steps as I had everything already installed. However, the article was helpful as it covered a few parts of the process.

If you have Apache 2 already installed, these steps can help you to go through to make it working again:

Update Apache 2 configuration

1. Uncomment Virtual Hosts line in Apache2 config ( /etc/apache2/httpd.conf ) if you use that file to configure all hosts:

2. Change Access Control block in httpd.conf as it has changed in new Apache 2.4:

3. Uncomment following lines to enable mod_rewrite and PHP5:

4. Restart apache:

After doing these steps my local sites started working again along with PHP5. However, Yosemite upgrade also removed custom extensions and at least Xdebug and Mcrypt were missing.

Reinstall Homebrew

I wanted to follow Rob’s guide regarding Mcrypt in which he used a Homebrew. Unfortunately the Homebrew didn’t worked for me as I didn’t upgrade that before upgrading OS X to Yosemite. I reinstalled the Homebrew then:

1. Remove old Homebrew

2. Install latest one

3.Run brew doctor

It came with a few recommendations. I fixed some of them, then I did the last one which was upgrading Xcode to 6.1. Actually Rob mentioned that in the article but I missed that part. It’s the following package:

https://developer.apple.com/downloads/download.action?path=Developer_Tools/xcode_6.1/xcode_6.1.dmg

Remember to run Xcode ater upgrading, it can save a lot of time later. I didn’t run that and I couldn’t get Mcrypt PHP extension installation working. After installing and running Xcode you also need to install Xcode command line tools. Run following in console to do so:

When Brew and Xcode are on their place, proceed to a Mcrypt installation.

Install Mcrypt

That part comes from Rob Allen’s post mentioned earlier.

1. Install Mcrypt using brew:

2. Prepare for PHP extension installation

Run following commands:

I haven’t been able to run successfully some of these commands on my local. I needed to follow recommendations mentioned in commands output eg. to clean some symlinks, install some other packages using brew install, etc.

When  these repositories are added, edit one broken file and apply patch:

3. Install PHP extension:

4. Enable PHP extension:

Then restart apache again and mcrypt should work properly.

I’m really happy I made my development environment working after Yosemite upgrade. I also realized what should be the next step – I should get rid of MacPorts leftovers and make sure everything is installed using one package manager.

I hope these steps and Rob’s article can help you in fixing OS X web development environment.

Bring a lot of customers to Magento store… using n98-magerun

Recently I talked about my favourite n98-magerun commands, this time I’ll continue that topic. Let’s see how to easily add a lot of customers to a Magento store. Of course it’s about adding fake data for testing purposes, unfortunately n98-magerun doesn’t help in bringing real ones :-)

Command customer:create:dummy allows you to create dummy customer accounts for testing purposes. It supports a few different locales and allows to generate any amount of accounts.

It took about 13 minutes to create 1000 customers, so it is able to fill a database with thousands of customers in a few hours. Sample output looks as follows:

Internally it uses https://github.com/fzaninotto/Faker. That library allows it to generate other assets like texts (either lorem ipsum or more real ones), addresses, phone numbers, companies, date and times, internet accounts, payment data and a few others.

I would love to see the ability to generate products using Faker and have a few more dummy methods incorporated into n98-magerun. The ability to generate products, customer addresses, maybe sales data would be great. However, the ability to generate fake customer accounts helps a lot and it’s a great start.

Work from anywhere

I have worked remotely for a few years. Actually I have worked remotely almost since the beginning of my career. There was a time when I was heading to the office almost everyday, but it was just “almost” and I wasn’t able to hang on there for more than 5 or 6 hours.

I love the mobility and ability to change the place I’m working from. Usually I work at my home office or on the terrace. Catching up with other team members is also important so this month I worked for a few days in our Bucharest office, and next month I’m going to start working in a co-working space once or twice a month. Sometimes changing to a completely different environment helps me to maximize productivity and keeps me happy.

This summer I got a chance to stay in a cottage house in Uniszowa for a week and work from there. It’s a place located in the Western Carpathians, so calm that it’s hard to see any house in a neighborhood there. The only thing I needed to figure out was the internet access. Fortunately it was really easy as the cottage was in a 4G LTE network coverage so connection was even better than at home. I was only missing a comfortable chair there but a sunbed did the job for these few days. Photo above shows a lovely sight I had from my work space.

I’m looking forwad to go to Uniszowa again this year. However, I need to wait til next summer to try a few crazy ideas about working from other calm and quiet places – work from forest or meadow :-)

What other places do you recommend for remote work?

Top 10 n98-magerun command calls

n98-magerun is a very useful tool when working on Magento stores. It saves time and makes a lot of Magento development related tasks much easier. Check out a list of my 10 favorite commands.

1. dev:module:rewrite:conflicts

This one is a must have. It’s a good replacement for an Extension Conflict module which I have been using before I found the n98-magerun. It shows rewrite conflicts in a clean ASCII table:

2. mysql-client

Command opens a mysql command line client without need of looking for a host, a port and credentials in local.xml file.

However, it doesn’t work on a server with proc_open() function disabled.

3. cache:flush

It flushes all Magento caches. If a store uses filesystem cache, this command isn’t much more helpful than simple  rm -rf var/cache* var/full_page_cache/* . However, when using the n98-magerun I don’t need to wonder what cache type is used in a store and this command provides an interface working for all cache types.

The only glitch is that in some cases it doesn’t clean cache if file permissions are not correct.

4. sys:cron:list

Prints list of all active CRON jobs configured in a Magento store. It shows output in readable way, showing a job code, minutes, hours, days, month and week days.

Another usable command related to CRON may be sys:cron:history which lists recently finished CRON jobs.

5. sys:setup:run

It’s useful to run database updates from a command line when installing an extension or upgrading Magento.

Recently I used that when working on a Magento upgrade from 1.12 to 1.14. Frontend kept throwing error as PHP code was trying to use things which haven’t existed in the database yet, but sys:setup:run command dealt with that perfectly.

6. dev:theme:duplicates

This could be used when working on templates, to clean them from not needed files. I ran that command in 3 projects I’m working on and it found a few duplicated templates.

7. sys:info

Command allows to quickly show an overall picture on the store. It shows a store edition and version, list of vendors coming from all code pools and a few other information. Additionally it shows basic factors which can determine the store size – amount of attributes, categories and products.

It’s handy when starting to work on an already existing site.

8. sys:check

It checks for missing system paths such as media/, var/ or a local.xml config file and checks if required PHP modules are installed. For example on my local server it keeps complaining about a missing index.php.sample file and about missing bytecode cache extension. I will need to get rid of this to get a nice green output :-)

Additionally it checks if each base URL contains dot, however I don’t get this part.

9. dev:console

This opens an interactive console with Magento initialized. It’s marked as experimental but works pretty well. It allows to run code in interactive way, most useful when I need to check multiple objects one by one eg. go through blog posts. For example to open console run:

And then run code to dump the blog post data:

Or order:

10. sys:modules:list

It lists all modules along with fields like code pool, key, version and status.

Documentation says it’s possible to filter list by a code pool and a status, but I couldn’t get it working. It simply shows nothing when I use any filter. However, even without filtering it’s pretty useful.

I chose these 10 commands as most interesting, but there are many other handy tools: a command for working with database dumps, a command for debugging Magento configs and all toggle commands which allow to enable/disable things like a cache, a demo notice, template hints and many more.

Take a look on http://magerun.net to see all of them or better just play with the tool. Also make sure to subscribe my RSS feed or my twitter as soon I will talk more about cool n98-magerun use cases.

How to handle zero dollar checkout

Zero Dollar Checkout is a core Magento payment method available to handle checkouts with a zero total. Of course it’s not really desired to have too many  zero dollar checkouts in e-commerce, but it can occur in some cases. It could be an order completely paid with reward points, an order with a 100% discount code or an order containing only a free item.

If method is enabled and the order total is zero, it becomes visible and the customer can choose to finish checkout without using other payment methods. However, if other payment methods are still enabled and displayed, it can confuse the customer. I saw use cases in which the customer tried to pay $0 using credit card payment method. It failed as payment gate throws error in such case.

A good way to handle that is setting Minimum Order Total configuration value to $0.01 for all methods other than Zero Dollar Checkout. Then all other methods will be automatically hidden if total is $0.

Unfortunately not all methods implement Minimum Order Total field.

Luckily, it’s very easily to fix that. It’s only about adding a new configuration field for the payment method.

I’ve added a new field for my payment method in system.xml file under XML path “config -> sections -> payment -> groups -> your_payment_method_key -> fields”:

And then added default value in config.xml file under XML path “config -> default -> payment -> your_payment_method_key”:

That’s it, the rest should be automatically done thanks to Magento core Mage_Payment_Block_Form_Container::_canUseMethod() method.

I see that as good practice to implement Minimum Order Total field in each method and use that properly. Don’t try to process $0 with payment gates.

Photo: it’s Common Raven, my favourite bird, which we spotted in way to Detiffoss waterfall in Iceland.

Welcome

A few years ago, in  2006 I started a PHP and Zend Framework blog under naruniec.info domain. The intention was to share my Zend Framework knowledge and experience with Polish developers while the framework grows. I stopped writing in 2009 as it was really hard to find time for blogging . It was even harder to start blogging again because a lot of important things started happening in my life – a serious job, family, children and a lot of hobbies.

Now I’m going to start blogging again. However, my areas of expertise have evolved a bit. Now the main focus is Magento. I’m going to share my Magento knowledge as well as general e-commerce and work experience.

My previous blog was naruniec.INFO and contained mostly information. This one is naruniec.ME and will also include few things about me.