Magento2 – Fix Not Working on Apache2, PHP7, and Ubuntu

Apache2magento-2.0magento2php-7

We are working on a magento 2 project. Since Windows lack cron job, magento 2 refused work full fledged. We decided to install ubuntu.

After striving hard I was able to make PHP7, apach2, mySQL and phpmyadmin work. Now the next hurdle is Magento. It says

The localhost page isn’t working
localhost is currently unable to handle this request.
500

After hours of struggle I still have no idea on how to make it work.

Edit:
I created a folder in var/www/html/Magento2 and copied all magento 2.02 files which has support for PHP7. Then I visit the Magento2 url. Bang I get the above error.

I need to confirm again PHP7 is working fine. Other scripts are working. I can even check for phpinfo. All the modules listed in the comment are installed.

PHP error log

[Sat Mar 12 10:09:29.489176 2016] [:error] [pid 1380] [client 127.0.0.1:44524] PHP Fatal error: Uncaught Magento\Framework\Exception\LocalizedException: Can't create directory /var/www/html/Magento2/var/generation/Magento/Framework/App/ResourceConnection/. in /var/www/html/Magento2/vendor/magento/framework/Code/Generator.php:103\nStack trace:\n#0 /var/www/html/Magento2/vendor/magento/framework/Code/Generator/Autoloader.php(35): Magento\Framework\Code\Generator->generateClass('Magento\\Framewo…')\n#1 [internal function]: Magento\Framework\Code\Generator\Autoloader->load('Magento\\Framewo…')\n#2 [internal function]: spl_autoload_call('Magento\\Framewo…')\n#3 /var/www/html/Magento2/vendor/magento/framework/Code/Reader/ClassReader.php(19): ReflectionClass->__construct('Magento\\Framewo…')\n#4 /var/www/html/Magento2/vendor/magento/framework/ObjectManager/Definition/Runtime.php(44): Magento\Framework\Code\Reader\ClassReader->getConstructor('Magento\\Framewo…')\n#5 /var/www/html/Magento2/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(71): Magento\Framework\ObjectManager\Definition\Runt in /var/www/html/Magento2/vendor/magento/framework/Code/Generator.php on line 103

Best Answer

  1. download magento2 from Magento Commerce website
  2. create a folder magento under /var/www/html 10 extract all the files of magento2 under /var/www/html/magento
  3. Change the file permissions

sudo chmod -R 777 /var/www/html/magento

  1. create a database called magento
  2. Visit website url to install magento2
  3. after completing installation change the directory permission again

sudo chmod -R 777 /var/www/html/magento

  1. set environmental variables in ubuntu

export PATH=$PATH:/var/www/html/magento/bin

  1. Setting up cron

crontab -u -e

example

crontab -u harish -e

select nano editor. add the following lines at the end of the file

*/1 * * * * <path-to-binary> -c <ini-file-path> <your Magento install dir>/bin/magento cron:run > 
*/1 * * * * <path-to-binary> -c <ini-file-path> <your Magento install dir>/update/cron.php >
*/1 * * * * <path-to-binary> -c <ini-file-path> <your Magento install dir>/bin/magento setup:cron:run >

where

is the absolute file system path to your PHP binary is the path to a php.ini file to use for the cron job

Example:

*/1 * * * * /usr/bin/php7.0 -c /etc/php/7.0 /var/www/html/magento/bin/magento cron:run > /var/www/html/magento/var/log/magento.cron.log& */1 * * * * /usr/bin/php7.0 -c /etc/php/7.0 /var/www/html/magento/update/cron.php > /var/www/html/magento/var/log/update.cron.log& */1 * * * * /usr/bin/php7.0 -c /etc/php/7.0 /var/www/html/magento/bin/magento setup:cron:run > /var/www/html/magento/var/log/setup.cron.log&

  1. Run cron from the command

magento cron: run

I have explained the step by step installation of magento2 on ubuntu 14.04 with php7 in this post. It could help someone at least. Installing Magento2 on ubuntu with php7

Related Topic