Link to home
Start Free TrialLog in
Avatar of RobLegge
RobLegge

asked on

Running Wordpress in a Laravel instance

I'm working with a small company that runs a website with an e-commerce system running in the Laravel framework with the rest of the site running in WordPress. Now I want to take a copy of all of this so that I can work on stuff without affecting the production site. Naturally there is no existing dev area. This was all set up for them by a 3rd party who have effectively run away and refuse to answer any calls or emails. I've created a VM running Ubuntu 18.04, Laravel (5.7 I think) MariaDB Apache2 and PHP7.2. I can (and have) taken a backup copy of the WordPress items that I can install onto the VM using the Duplicator Pro plugin. I've tested this on the VM and know that I can expand everything there and having done so I can at least rung the CMS side of WP although seeing the actual web pages is difficult.

I need to get this running partly because I may need to move from the existing hosting arrangement so want to use this as a sort of trial run in addition to creating a dev setup. My question is what do I need to do to get this working? Do I need to make changes in the Laravel set up? It's still got the "your-project" folder where I've put things like phpminiadmin.php (like phpMyAdmin but just one page) so I know that all the bits are running. Can I get away with just duplicating the file and folder structure of the production site and then run the Duplicator Pro installer script to set up the site? Am I being too naïve here? :-)
Avatar of David Favor
David Favor
Flag of United States of America image

1) If you attempt to commingled Laravel + WordPress, you'll likely end up expending a massive amount of extra time trying to debug problems + may or may not ever reach any resolution/fix.

So only commingle Laravel + WordPress if you have unlimited time + budget.

2) Better to completely split Laravel + WordPress across 2x different hosts with 2x separate DocumentRoot directories for each host.

3) To setup a separate dev site for each...

a) First setup your Apache configs with separate DocumentRoot. If your main site is foo.com then setup lavdev.foo.com + wpdev.foo.com or something similar.

b) At this point you'll have both dev sites serving bare directories (no files).

c) Then generate your TLS (SSL) certs for both sites using https://LetsEncrypt.org to get HTTPS + HTTP2 running correctly for both sites.

d) Then run a duplicator backup restore in your wpdev.foo.com site.

c) Do whatever process is required for your lavdev.foo.com site, which might involve restoring databases.

Warning: Be sure to rename your databases, so they're completely different names than they were originally. If you end up clobbering databases either now or in the future, because of name collision, this can be impossible to fix.
ASKER CERTIFIED SOLUTION
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RobLegge
RobLegge

ASKER

Unfortunately the e-commerce site is somewhat entwined with the main site. It takes it's styling from that and contains details of a several thousand music manuscripts that are displayed on the main site. This isn't the way I would have done it either but I'm stuck with what we have for the foreseeable future. The WP set up within Laravel seems to be split, one folder labelled Themes (with a folder under that with the company name) that contains php files for the header and footer, as well as scss and css files with a few other included files, and one named /latest that contains what appears to be the main WP installed files, so WP is already in a sub-directory.

The client has had this system running for about a year in this fashion and aren't ready to spend yet again, having had to invest also in new tills (they have 3 retails outlets as well) to link into this system.
With this layout, you'll pull copies of the WordPress database (and any other database, if there is any) somewhere in the file hierarchy, then rsync the entire hierarchy to another machine or zip the files + move the zip file.

Once you have your dev site clone of files, you'll have to figure out how to muck around with Laravel to change the site name.

With WordPress this is easy. With Laravel, having no standard mechanism for site naming, you may have a long road to figure out how to do this.
Ok, this sounds like it is already set up like I suggested to start with.  

The hardest part is WP but it sounds like you have that licked. Once in a while when moving/copying a site, I am still left with background images pointing to the original site. I am using the Better Search and Replace plug in to fix that.

For Laravel, you can copy and paste the entire site.  Just be sure to update folder permissions
https://laravel.com/docs/6.x#directory-configuration
After installing Laravel, you may need to configure some permissions. Directories within the storage and the bootstrap/cache directories should be writable by your web server or Laravel will not run.

Then just update your database config files https://laravel.com/docs/6.x/database#configuration after you have restored a copy of the live database to the dev site.

This should be pretty straight forward to duplicate. Probably a few hours of frustration the first try and a lot less after that.

The client has had this system running for about a year in this fashion and aren't ready to spend yet again
Yes, I get this too. And it is not always easy to explain in the long run it is easier to just start over to do it the right way.  All they see is what they can physically see and it appears to work. If it is a large, long term project, it may be easier to just do what needs to be done on the inside and they may not realize it except for perhaps a different cms.
I've made a lot of cosmetic changes to the site in the last few months, with some fairly obvious results (like between 50 and 100% increase in sales, month on month) I hope soon, therefore, to be able to suggest a complete rewrite as The Best Way forward. Trust, which had been well and truly shafted, is starting to return. For the most part it's cosmetic changes that need to be made as on the whole the functionality is OK. There's some roughness still there that I'm trying to smooth out, bring it a bit more up to date with what the customer sees.

Occasionally though I'd like to roast the original developers over a very low heat. On a spit.
Still having some trouble with this set up. So I've reverted to the first base installation - that is with MariaDB, Apache2, PHP and Laravel installed and running. Then I downloaded the WP TAR file and expanded it, renaming the WordPress folder to match the production set up, The data base had already been created so I edited the wp-config.php files with that info but all I get when trying to run any php script in the /latest/ folder returns a message that the file cannot be found. In fact no file in any subfolder below /your-project/ will actually run, so I guess there's a configuration needed in Laravel to run stuff, but I've no idea what. Can anyone help with that?

R
Got  a little more movement here, creating a Laravel config file in the config folder which at least now displays the contents of the config file with a message saying "class App can't be found". Will continue trying things.
I completely replaced the original file structure at the base to find that trying to enter the IP address in to the browser results in in being redirected to IPAddress/public/index.php which of course no longer exists. So how do I get Laravel to look elsewhere?
I would do this in steps.

1) Get Laravel app to work as expected.

2) Go through the process of installing a new wordpress site in a subdirectory.
https://medium.com/@Madgeek_in/how-to-install-a-wordpress-blog-to-your-laravel-web-application-24e79036ce77
https://www.elegantthemes.com/blog/tips-tricks/how-to-install-wordpress-within-a-subdirectory
Don't worry about the current site for now, just get this to work with the default site/theme

Once you have that working, then you can use a plug in to copy the files and data over from the original wp site. https://wordpress.org/plugins/duplicator/  I have plesk on my server and it has these functions built in and works nicely.

The data base had already been created so I edited the wp-config.php files with that info but all I get when trying to run any php script in the /latest/ folder returns a message that the file cannot be found.
 
I have a feeling this is because of copying the database.  Also makes sure your htaccess file is correct in the wordpress folder.
I managed to get a clean installation of WP running, went through the install script and so on. I took a snap shot at that point (one of the best things about VMs since I don't have to redo all that work :-) ). Now I'm trying to install the original site from the backup and for the first time it's throwing up errors - not able to create folders in folders where it's already created other folders and files!  Since I've got the file structure elsewhere I've copied the problem areas from another source and redoing the restore function. Nut it does seem to be throwing up errors in the database restore, claiming the file structure (that it's just created) is wrong. Well I can take just a database backup so might try that tomorrow if the current restore fails.
However, I still want to be able to change some of the names in Laravel, for example the /public/ folder needs to renamed as /latest/ but if I do that everything else fails to run.
Right, still got this problem open. To date I now have two instances of Linux running, one as LAMP set up, the other LAMP with Laravel. I've put WordPress on both and uploaded all the back-up stuff and installed it on each machine. In both cases I can run WP-Admin and edit pages and do other stuff inside the CMS. From this I'm making the assumption that WP is installed correctly. However, that's where it ends since in trying to view any actual web pages returns error messages. In the Laravel instance I get "the site is experiencing technical difficulties"., or a 404 error. changing the name of the folder "public" in the Laravel created "your-project" to "latest" (matching the structure in the original) then the error message changes to "page not working " and "too many redirects" while it tries to redirect to the url "/public". From this I would suspect that a config file needs to be changed somewhere. I've copied the ones that existed in the original but that doesn't do the job, so would like some help with that please.