Install Magento on Ubuntu and fix PHP Extensions "0" must be loaded error with PHP 5.4

Magento LogoEvent though I follow MVC pattern in many of my web related projects, like every PHP web developer I came to the point when I have to dive into some well established MVC PHP framework. This is something backend developer must do if he wants to stop being a lone wolf and start working inside a team of developers. Web frameworks of my choice are fast Codeigniter and powerful Zend Framework. Getting to know about Codeigniter wasn't hard, but mastering Zend is still work in progress especially since Zend Framework 2 has been recently released. Talking about Zend, recently I got interested in getting to know about open source eCommerce solutions and I choose to get acquainted with Zend based Magento. In this article I'll show you how to install Magento on a Debian based distributions like Ubuntu and provide workaround for the PHP Extensions "0" must be loaded error thrown by Magento installer running on PHP 5.4.

My assumptions for this article are that you have working LAMP installation and that your web document root is located inside /home/$USER/public_html, you can check out one my older articles to find out more about how create such environment. So lets first install some of Magento prerequisites:

sudo apt-get install php5-mcrypt php5-curl php5-gd

Next thing to do is to create database to host our Magento EAV modeled database. I'll use CLI way to create user magento, with the password and magento database that grants all privileges to that user. You can also use phpMyAdmin to do the same. First let's open MySQL Monitor, in my case with MySQL admin user named root privileges:

mysql -u root -p

On the MySQL monitor command line enter these commands to create user, grant usage on localhost, create database and grant all privileges on that database:

1
2
3
4
CREATE USER 'magento'@'localhost' IDENTIFIED BY 'magento';
GRANT USAGE ON * . * TO 'magento'@'localhost' IDENTIFIED BY 'magento' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;
CREATE DATABASE IF NOT EXISTS magento;
GRANT ALL PRIVILEGES ON magento. * TO 'magento'@'localhost';

Now that we have that covered, we will create temporary directory on our desktop like this:

1
2
3
cd /home/$USER/Desktop
mkdir magento_temp
cd magento_temp

Here you will need to download Magento package and sample data from Magento download page (login required). In my case I will download:

  • magento-1.7.0.2.tar.bz2
  • magento-sample-data-1.6.1.0.tar.bz2

Next we extract out tarballs, move data to web document root, import sample data .sql file into our database and adjust file permissions.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Extract Magento tarball
tar -xvjf magento-1.7.0.2.tar.bz2
 
# Move magento to document our root
mv magento /home/$USER/public_html/
 
# Extract Magento sample data tarball
tar -xvjf magento-sample-data-1.6.1.0.tar.bz2
 
# Move Magento sample data catalog files
cp -r magento-sample-data-1.6.1.0/media/* /home/$USER/public_html/magento/media/
 
# Import Magento sample data into our database
mysql -u magento -p -h localhost magento < magento-sample-data-1.6.1.0/magento_sample_data_for_1.6.1.0.sql
 
# Adjust write permisions
cd /home/$USER/public_html/magento/
sudo chmod o+w var var/.htaccess app/etc
sudo chmod -R o+w media

There's only one thing to adjust before starting Magento installer, and that's the PHP Extensions "0" must be loaded error if you're installing Magento 1.7.0.2 on LAMP with PHP 5.4. Here's the screenshot of what I'm talking about:

Magento installer error with PHP 5.4

It appears that one of the configuration XML files, namely /home/$USER/public_html/magento/app/code/core/Mage/Install/etc/config.xml isn't parsed correctly by PHP 5.4 so we must make some changes to work around this issue. We need to open that file and find following (around lines 66 to 75):

1
2
3
4
5
6
7
8
9
10
<databases>
    <mysql4>
        <type>pdo_mysql</type>
        <initStatements>SET NAMES utf8</initStatements>
        <min_version>4.1.20</min_version>
        <extensions>
            <pdo_mysql/>
        </extensions>
    </mysql4>
</databases>

and replace it with the following XML:

1
2
3
4
5
6
7
8
9
10
<databases>
    <mysql4>
        <type>pdo_mysql</type>
        <initStatements>SET NAMES utf8</initStatements>
        <min_version>4.1.20</min_version>
        <extensions>
            <pdo_mysql>1</pdo_mysql>
        </extensions>
    </mysql4>
</databases>

After this little adjustment we can proceed to Magento installer accessible on http://localhost/magento/ address. Since we're talking about graphical installer, I won't spend words describing it but I've attached gallery of screenshots for your to review. Enjoy!

DevGenii

E-commerce is a breeze with Magento Certified Developer Plus & Zend Certified PHP Engineer nearby. Get in touch!

6 thoughts on “Install Magento on Ubuntu and fix PHP Extensions "0" must be loaded error with PHP 5.4

  1. Matthias

    I am sure that I’ve installed Magento 1.7.0.x several times with php 5.4.4 – I receive this error since I’ve changed my development environment to 5.4.25

    Reply
    1. Marko Author

      Hi Matthias,
      I can confirm that. It’s probably SimpleXML PHP extension bug, but since these Magento versions do not officially support PHP 5.4, we must work around it. I haven’t encountered this bug on later Magento versions though.

      Cheers

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *