Magento 2 – Local Installation Not Generating Files in pub/static Folder

.htaccesslocalhostmagento-communitymagento2mamp

I've just installed Magento 2 Community Edition with sample data (downloaded from their website and not installed with composer) locally via MAMP. The installation process was succesful, but all files in the pub/static folder are missing except .htaccess. That means all css, js etc. return 404 for both frontend and backend.

I've spent several hours trying to fix this without luck. This is what I've done so far:

  • Changed Options Indexes FollowSymLinks AllowOverride from 'None' to 'All' in the /MAMP/conf/apache/httpd.conf and restarted MAMP
  • Made sure LoadModule rewrite_module modules/mod_rewrite.so is uncommented in httpd.conf
  • Set up a development domain (magento.dev) in MAMP
  • Tried running php bin/magento setup:static-content:deploy in the magento.dev root using Terminal. This however returns:

Fatal error: Class 'Locale' not found in
/Applications/MAMP/htdocs/magento.dev/vendor/magento/framework/Locale/Bundle/DataBundle.php
on line 64

  • Uncommented and changed RewriteBase to RewriteBase / in the .htaccess-file in the magento.dev root directory.
  • Set Magento in development mode
  • Clearing the cache manually and running php bin/magento setup:static-content:deploy again

Most guides and forum posts tell me to run: php bin/magento setup:static-content:deploy but I'm not sure, if I'm doing it correctly.

OS: OSX 10.11.2

MAMP version: 3.5

PHP version: 7.0

Apache version: 2.4.16

MySQL version: 5.6.25

Any help would be appreciated.

Best Answer

SOLUTION # 1 (IF YOU WANT TO EDIT XML FILE)

I would like you to download Magento 2 zip from magentocommerce.com/download, create new db in phpmyadmin, extract zip in htdocs folder. Install Magento 2 but do not use localhost use 127.0.0.1 in store URL and admin URL. After successful installation DO NOT run magento.

Now we are going to clear / delete caches and sessions of Magento 2. Go to following paths and delete everything:

ROOT > var > cache > *DELETE ALL*
ROOT > var > page_cache > *DELETE ALL*
ROOT > var > session > *DELETE ALL*

When Magento 2 is not in production mode, it will try to create symlinks for some static resources on local server. We have to change that behavior of Magento 2 by going to edit ROOT > app > etc > di.xml file. Open up di.xml in your favorite code editor, find the virtualType name="developerMaterialization" section. In that section below, you will find an item <item name="view_preprocessed" xsi:type="object"> which needs to be modified. You can modify it by changing the following content:

Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink

To:

Magento\Framework\App\View\Asset\MaterializationStrategy\Copy

Now last step, also delete old files generated in ROOT > pub > static > DELETE ALL EXCEPT .HTACCESS

I personally tried it on my localhost using MAMP, EasyPHP DevServer, Xampp and Wampp and successfully installed and using Magento 2. For further you can check out this link: Magento 2 CSS and JavaScript not loading from correct folder

SOLUTION # 2

Install Composer. Now I would like you to download Magento 2 zip from magentocommerce.com/download, create new db in phpmyadmin, extract zip in htdocs folder. Install Magento 2 but do not use localhost use 127.0.0.1 in store URL and admin URL. After successful installation DO NOT run magento.

Now we are going to verify Composer installation, Deploy static content, clear / flush Magento cache and reindex the Magento 2 blocks. To perform all above actions, press WINDOWS KEY + R to open RUN dialog and type “cmd” to open Command Prompt.

Type “cd PATH_TO_YOUR_MAGENTO2_FILES” to enter in Magento 2 ROOT directory.

Now to verify Composer installation in above directory, type “composer install”.

If you get any error in this step, please check your Composer installation

In this step, we are setting up static content to deploy on our Magento store. To perform this, type “php bin/magento setup:static-content:deploy”.

If you get any error, check your PHP.EXE and PHP.INI Environment Variable

Clear / Flush Magento cache by typing “php bin/magento cache:flush” in CMD.

And finally, to Reindex Magento Static Blocks type “php bin/magento indexer:reindex”.

You are done with successful installation of Magento 2.