We will set up a development environment with Magento. For this, we need to set up a LAMP (Linux, Apache, MySQL, PHP) environment. In that LAMP environment, we will create a Fully Qualified Domain Name (FQDN) and a virtual host.
We have to set up a development server that we will use to run Magento. When we have a Ubuntu desktop environment, we have to install the latest versions of the following software:
Apache2
PHP
MySQL server
Extra PHP libraries
We can install these software by running the following commands on a CLI interface. These commands are based on a Ubuntu-based Linux distribution. To run the commands on a desktop with Ubuntu OS, launch the Terminal program:
To install the web server Apache2, run the following command:
sudo apt-get install apache2
To install PHP, run the following command:
sudo apt-get install php5
To install the MySQl server, run the following command:
sudo apt-get install mysql-server
To install the required PHP extensions that Magento uses, such as the MySQL bridge, run the following command:
sudo apt-get install php5-mysql php5-curl php5-gd php-pear
When everything is installed, we will create a virtual host with an FQDN. We want our development environment to be available at http://magento-dev.local/
. To do this, we have to create a virtual host with this domain name. This domain points to the IP of our previously created web server.
The following steps describe how you can create a virtual host with an FQDN:
Create a
magento-dev.local
file in the/etc/apache2/sites-available/
directory.To create and edit the file, run the following command:
sudo nano /etc/apache2/sites-available/magento-dev.local
Paste the following content in that file:
<VirtualHost *:80> # ServerName (domain) and admin email ServerAdmin [email protected] ServerName magento-dev.local DocumentRoot /var/www/magento-dev.local/public # Folder of the site. We have to create this # Log file locations LogLevel warn ErrorLog /var/log/apache2/magento-dev.error.log CustomLog /var/log/apache2/magento-dev.access.log combined </VirtualHost>
Run the following commands in the terminal to create the
www
root folder:To create the site folder (document root), run the following command:
sudo mkdir /var/www/magento-dev.local/public sudo chown -R www-data:www-data /var/www/magento-dev.local/
To enable the site, run the following command:
sudo a2ensite magento-dev.local
To reload the Apache server, run the following command:
sudo service apache2 reload
To test the site, we have to add the following line in our host's file (
/etc/hosts
):127.0.0.1 magento-dev.local
This will point the domain
magento-dev.local
to the IP address 127.0.0.1. This is the IP address of the local web server (localhost), so a request to this URL doesn't go to the Internet but goes to the local web server.
This recipe describes how to install a web server from a CLI interface. If you already have a web server with a specific domain, you can skip this chapter.
The Magento files will be installed in the public directory. When a request is made to the domain, the www-data
user will execute the request. So, it is best that all files and folders have the www-data
user and group to avoid permission problems.
On a Linux server, every file and folder has three types of permissions. These permissions are read, write, and execute (rwx). You can set these permissions in three scopes: for owners, groups, and others. On every file request, Linux decides, based on the permissions, whether a user can read, write, or execute a certain file.
For an HTTP request, the www-data
user will be used to execute a request. So, it is important to ensure that the www-data
user has enough file permissions to run the application. To change file permissions, you can use the chmod
command. To change the owner and group, you can use the chown
command.
It is also possible to run Magento and the web server on other operating systems. To run a web server, we need Apache, MySQL, and PHP. It is possible to install these software on a Windows or Mac device.
The variant for Windows operating systems is WAMP (Windows, Apache, MySQL, and PHP). You can find more information about this variant on the WAMP website at http://www.wampserver.com.
For Mac OS, the alternative is MAMP. More information on MAMP is available at http://www.mamp.info.
A cross-platform web server is XAMP. You can download the installer for Linux, Windows, or Mac from their website at http://www.apachefriends.org/en/xampp.html.