Installing and using plugins like ACF Pro, WMPL etc. correctly

composer

#1

Hello!

So far I’m loving the new theme development experience using Yarn, Blade + composer etc. !

What I’m not sure about is this: should I strive to install plugins as a composer dependency ?

At the moment I have ACF Pro + WPML installed (basic via WP upload) and it seems to be working, although for example, ACF validation in backend is not Ajax based but its post-ed on a separate page, which is a bit unusual.
Is that a problem with Sage or perhaps it comes out of not using Composer to install a plugin? If I do install it via plugin, which thread/docs should I follow to make it as it’s meant to be?
There’s this thread for example which is perhaps a bit more specific for Trellis which I don’t use. (I just use Sage + MAMP).

Is it possible the issue comes from me accessing backend via my proxy (http://mypage.dev for example) and style changes via http://localhost:3000. I saw this is how it’s supposed to be in another thread, so I guess that’s fine right?

Any help appreciated!


#2

If you are using Bedrock - and I highly recommend you do! - then you will want to install plugins as a composer dependency. Running composer require wpackagist-plugin/plugin-name in your Bedrock root directory will access the normal WordPress plugin database. If you want to use licenced plugins that are not available from packagist, then I would highly recommend setting up a SatisPress repository.

However, I don’t think how you install plugins should cause the issue you are reporting.

I would always access my admin panel through through http//mysite.test rather than through a proxy. Have you tried it to see if that fixes the problem for you?


#3

Hello @danielroe, thanks for your answer.

Unfortunately I’m not using Bedrock with this project yet; probably it’s not as easy to set up now that I have plenty of code done already?
Without it, I should stick to basic plugin installation without Composer?

Why I haven’t used it from start? It seemed a bit of an overkill for me to start with it, since Sage was already quite a new thing to grasp already…
So it just seemed going for Bedrock + SatisPress and other stuff might be too much for me to handle at the same time in the amount of time I have to finish the project :slight_smile:

Did not find an example though, for setting Bedrock up with an existing Sage WP, any ideas?


#4

To move to Bedrock, this is the procedure I follow. (We often do this when taking on clients with an existing website.)

  • Create a new Bedrock install
    composer create-project roots/bedrock my-bedrock-project
  • Set up your database and configure variables in .env

For these first two steps, I actually just run wp valet new my-bedrock-project - but it requires Valet and the wonderful wp-valet plugin.

  • Copy over your existing theme and uploads
    mv existing_site/wp-content/themes/* my-bedrock-project/web/app/themes/
    mv existing_site/wp-content/uploads/* my-bedrock-project/web/app/uploads/
  • Import your database and replace old wp-content URLs
    wp import db old-site-dump.sql
    wp search-replace 'wp-content' 'app'
  • Require all your existing plugins
    composer require wpackagist-plugin/my-plugin-1 wpackagist-plugin/my-plugin-2
  • Set up your version control system
    git init
    git add . && git commit -am 'Initial commit'

You should now be good to go.


#5

Hey @danielroe, thanks for this, just now trying to establish what you proposed but ran into an issue with wp-valet unfortunately.

Installed Valet successfully, then wp-valet has some issues with me it seems :slight_smile:

wp package install git@github.com:aaemnnosttv/wp-cli-valet-command.git

throws

Loading composer repositories with package information
Updating dependencies
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in phar:///usr/local/bin/wp/vendor/composer/composer/src/Composer/Json/JsonFile.php on line 272

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in phar:///usr/local/bin/wp/vendor/composer/composer/src/Composer/Json/JsonFile.php on line 272
Reverted composer.json.

Any ideas perhaps? I found the same issue discussed here but am not sure what is meant by a solution step 2.:

composer -d="$(wp package path)" update

How exactly should I run this if you know? Because for me it’s throwing errors as well (with package git url path given).

It’s not a big fuss to just skip the valet/wp-valet, but It does seem like a time-saving plugin + some features look like a valuable asset for the future work. Might as well put some more effort into learning it, to save time later on, huh? :slight_smile:


#6

I think it’s easier to increase the memory limit for php.

Try running:
grep memory_limit /usr/local/php5/php.d/*

Once you know which file sets your memory limit, you can edit the file to increase it.


#7

Hey, thanks, but /usr/local/php5 does not exist.

Did you mean another path perhaps?
Also, my PHP is v7:

➜  ~ php -v
PHP 7.1.14 (cli)

checking the current memory now with:

➜  ~ php -i | grep memory_limit
memory_limit => 128M => 128M

➜  ~ php --ini
Configuration File (php.ini) Path: /etc
Loaded Configuration File:         (none)
Scan for additional .ini files in: (none)
Additional .ini files parsed:      (none)

Seems like I’d need to then call

grep memory_limit /etc/* but that’s probably not a good idea huh?


#8

Run:
grep memory_limit /usr/local/php*/php.d/*


#9

Also not existing, any “php” folder under /local.

➜  local which php
/usr/bin/php

I followed Laravel’s instructions, installed it via brew and it’s in

➜  php pwd
/usr/local/Cellar/php

But that’s v7.2 whereas php -v says 7.1, so it seems I’m quite lost here :slight_smile:


#10

I’m not really familiar with how your system is set up, but you might try grep memory_limit /etc/* as you suggest. It seems your php.ini is in /etc/ as you note, so that might be /etc/php.ini or /etc/php*/php.ini but you’re better off just having a look to see if you can find it.


#11

Indeed, I changed the /usr/local/etc/php/7.2/php-fpm.d/www.conf to 256MB (was commented out otherwise …).
Still not working though, I believe there’s gotta be an issue with various PHP installations (OS X PHP vs brew PHP or something like that).

This then seems to be an isolated specific issue on my OS, so you can’t do much.
I guess I’ll try next time perhaps, will skip on Valet for now.

Thanks for your time!


#12

Ok, I had some success with my last try.

Updated /usr/local/etc/php/7.2/conf.d/php-memory-limits.ini
from 128MB to 1024MB and only then it worked!

Now another problem occurred, seems like moving from MAMP to other stuff is not as easy as it sounds :slight_smile:

wp valet new my-new-project
Password:
Don't go anywhere, this should only take a second...
Error: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/Applications/MAMP/tmp/mysql/mysql.sock' (2)

Seem like my next task is to find how to change mysql socket used. I thought valet would take care of it by itself?


#13

I would suggest not using MAMP, but rather installing mysql with Homebrew.

But if you want to use MAMP, then consider this article. It sounds like your problem might be fixed by running:

ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock

and then restarting mysql.


#14

Yeah of course not, I have it closed but it seemed it still wanted to reference it.

I installed mariadb via Homebrew, then it worked and command is successfully finished :slight_smile:
Thanks! Moving on to next steps … :slight_smile:

PS: unfortunately it seems my project files are in the same structure as usual wordpress installation. No /web/ folder there to continue …

Hmm, now getting a bit frustrated to be honest :slight_smile:


#15

Run this command instead:
wp valet new my-project --project=bedrock

(See here.)

I didn’t mention it above as I have edited my global wp-cli config so I no longer have to add the --project option.


#16

Indeed that helped, thanks.

Now stuck at the next step as well :persevere:

Can’t import DB it seems, i exported the dump via phpmyadmin, then tried wp export db which couldn’t connect to DB with MAMP running (that’s the used db for old project).

wp import db says:

Error: Parameter errors:
 missing --authors parameter (How the author mapping should be handled. Options are 'create', 'mapping.csv', or 'skip'. The first will create any non-existent users from the WXR file. The second will read author mapping associations from a CSV, or create a CSV for editing if the file path doesn't exist. The CSV requires two columns, and a header row like "old_user_login,new_user_login". The last option will skip any author mapping.)

When --authors=skip or --authors=create is added:

Starting the import process...
Error: This does not appear to be a WXR file, missing/invalid WXR version number

Damn me, now I think I know why I kept using the old MAMP … :slight_smile:


#18

What options did you use when exporting via phpmyadmin? What is the exported filename?


#19

I used default options as usually when exporting, but tried MYSQL40 compatibility as well.

What’s ticked is:

Add CREATE VIEW statement
Add CREATE PROCEDURE / FUNCTION / EVENT statement
Add CREATE TRIGGER statement 

and

Dump binary columns in hexadecimal notation (for example, "abc" becomes 0x616263)
Dump TIMESTAMP columns in UTC (enables TIMESTAMP columns to be dumped and reloaded between servers in different time zones)

Perhaps should change this to something? Database system or older MySQL server to maximize output compatibility with: <select>


#20

First, just to confirm, you did try wp db export and not wp export db before moving to phpmyadmin? I think you can fix the DB connection error by replacing localhost with 127.0.0.1 in your old site’s wp-config.php. (It stops it from trying to connect via socket.)

If you can’t get wp db export working, then does the file you’ve exported from phpmyadmin end in .sql? The error message indicates that WordPress is trying to import it as a WXR/XML file. If it is an XML file, you could try to follow this guide.


#21

Yes, used:

git:(develop) wp db export
mysqldump: Got error: 1045: "Access denied for user 'root'@'localhost' (using password: YES)" when trying to connect
➜  my_folder_name git:(develop)

Changing to 127.0.0.1 still throws the same error unfortunately.

Yes, the phpmyadmin exported file is a .sql file.