Vagrant + Docker + Wordpress - wordpress

I installed vagrant on a Mac and I want to achieve this :
Launch vagrant up and have a vagrant with docker installed and docker compose
Install Wordpress with mysql inside this vagrant machine with docker-compose up
Have the folder (/var/www/html) of the docker container mapped as volume in my vagrant machine at /dockermapinVagrant
Have this /dockermapinVagrant onto my host(OS X) and be able to modify files directly from the host
I achieved that and everything works perfectly.
I can add templates from my OS X host with no problems (dragging the theme in the themes folder on my host OS X), see the changes directly of the Wordpress site using my browser ...
The problem
I noticed is that I can not install any plugins on Wordpress (
dashboard -> updates ) I have a message :
To perform the requested action, WordPress needs to access your web server. Please enter your FTP credentials to proceed. If you do not
remember your credentials, you should contact your web host.
Solution i tried
Change the permission in the docker container wp by setting the user to www-data and chmod to 777 but on some folder as wp-content it doesn’t change to 777. Moreover setting the owner to www-data doesn’t work at all it stay always to 1000:1000 in the container.
Is there a way to update the plugins on wordpress in a docker container without FTP ?
Is there maybe a better way do to that ? Use a data-only container on the vagrant machine with FTP access to the mounted volume ? And map the data container volume on the vagrant machine then to the host to have direct access and see changes directly during the dev process. But I do not want to give FTP access directly on the data-only container (FTP is not secure and I prefer to manage the backup and the data from the vagrant machine directly and delete the mapped volumes in production)

You sure can achieve this, and it's probably just the missing line
define( 'FS_METHOD', 'direct' );
in your wp-config file. You should setup each WordPress outside of the docker environment first IMHO; and then import the database, and WordPress files etc into docker using your Dockerfile(s) as part of staging and deployment, which should be distinct from development (although some of deployment will be shared).
On better ways of managing, I would not put docker inside vagrant if at all possible; it adds unnecessary complexity to that stage of development. I would use vagrant exclusively, focus on getting my provisioning scripts ready (as I use scripts between vagrant and docker), and work via SFTP directly to the vagrant box; committing changes via git. You can then focus your efforts on the necessary code and pull what you need when you need to.
Once it gets to the stage of testing, or staging, I use the provisioner scripts to help me build my docker environment consistently, (probably sharing some of the provisioning code). I Can then pull a specific release from my repo, and build it into my docker image, which I can deploy.
Other alternatives if you really want spin up, delete WordPress, get to grips with the WP-CLI command-line tools, which can install WordPress, plugins, manage updates and install integrity.

Related

Docker Container dynamic hosts file

Hey fellow overflowdians,
I've started to use Docker to facilitate my local development. However I'm facing an issue. I'm a WP Developer and every time I have to set up a new WP project I have to manually add to my Docker compose file the hostname of the machine using the following:
extra_hosts:
projectname.local:IP-of-the-container
Well as you know the IP of the container changes per docker container as so as the ID.
So I'm looking for a way to put this into my Docker compose file where it will automatically add the right container IP to the docker hosts file, so that the PHP Docker container can "talk" using the local domain to the frontend webserver nginx, and vice versa?
Any ideas ??
Thanks!
Andrew

Share my local wordpress site with another developer with git

I want to share my local wordpress site with another developer with git in a way our database will be same when he setups my wordpress site in his local PC.
I am using windows 7 OS
I'm not sure if what you are asking for is possible.
here is my suggestion (the database should be on a real server)
if you use CPanel:
1- In the CPanel create the database and new user and assign the user to the database
2- In the CPanel Go to Remote MySQL, add your IP address and the other developer IP address. (to allow remote access)
3- Export the database from your local PC and import it to the CPanel.
4- Change the wp-config.php configuration.
Note: The urls should be the same on your PC and the developer pc.
for example if your website url on your pc is : http://localhost/mywebsite/
the other developer should make it the same.
I would suggest keeping your database out of git (except perhaps the database definitions).
Instead you can leverage git hooks. Using something like pre-push, run a mysql dump command to get the current state of your db, and copy it to a shared Dropbox/Drive folder with your team mate.
.git/hooks/pre-push
#!/bin/bash
mysqldump -u root -p --all-databases > ~/Dropbox/shared-with-tm/mysql.sql
Completely untested This is a vague answer to answer a vague question - but might give you a starting point.

How to access local WordPress installs from other machines on my network

I have XAMPP running fine on one machine and I have 2 WordPress installs running fine on that machine. I would like to be able to access and work on those WordPress installs on other machines on my network.
Right now, I have it set so that if I try to access those directories from another computer on the network, all I get is either the XAMPP splash screen, or a 404 error if I try to access specific folders.
I've researched this and researched this and I have found numerous posts about how to do this.... but only in bits and pieces.
Does anyone know of a step by step, start to finish, guide of how to do this? In layman's terms?
Remote (from another network) would be great too. But I'll cross that bridge once I figure this out.
Any help would be appreciated.
Thanks!
I would suggest rather than shared folders you use an FTP client / server - I use Filezilla server and client for my local sandbox testing server. This will give you additional info like file and folder groups and permissions.
Got to ask the question what OS? have you opened port 80 on the server machine?
Things like this can also occur on Linux if the folders and files do not have the correct groups for access and or permissions.
chown -R apache:apache /var/www/html
the above if on linux will assign all the folders and files to be accessed by the apache process. not having the correct groups assigned can give you 404 when you know the files are actually there.
also check the file and folder permissions,
different files and directories have permissions that specify who and what can read, write, modify and access them - this wordpress page gives a good overview of permissions
http://codex.wordpress.org/Changing_File_Permissions
edit p.s. to access then from other networks all you will have to do is forward ports from your router to your internal server then your ftp and www services will be accessable from the outside world. I would suggest using a .htpass htaccess password to protect your services at this point.

Making local Drupal installation accessible through Virtual Host

I am trying to introduce a staging step in my company's code-production process. We currently have ~10 eng clients who commit code individually, update local codebase - debug/check locally, then we deploy the code to production environment and have other employees QA. Obviously we would like to have a better pre-production test process to help catch bugs before they go live to the public.
My first attempt is to create a staging environment on an extra ubuntu box with the most recent committed code from the eng clients. I then could allow the Product Managers to check this site and find bugs, test features, expose bottlenecks, etc.
What I have: The ubuntu machine (local server) is currently configured as a normal eng client. It has a local drupal installation, complete backup of the db, and all of this is accessible locally. Let's go with mysite.com = official site; and the local staging domain I use on the ubuntu box = ms.com. This local ms.com works just fine, so in essence, I need to just allow other people at the company to navigate to some URL and it acts the exact way ms.com currently behaves. I have DNS servers pointing to the ubuntu box and it is running some side projects out of the /www folder.
In an effort to keep the side projects running, I think my solution is to create a name-based virtual host that points to the directory of the local drupal installation. Is this the right thing to do to achieve my goals? Is there an easier way to open up this local config to the employees.
In trying to set up the virtual host I did the following:
I added the static ip address of the local server to /etc/hosts
I added a virutalHost to /etc/apache2/sites-available with the DocumentRoot dir/DrupalInstallation
I added a2ensite
Then restarted apache.
Halfway success. I can get to the main page, but none of the modules load, I tried loading more hosts/variations, started changing all localhost references to the external, but I don't really know what the underlying issue is and I do not know how to diagnose it. The one interesting bit is that if you click on some of the links, it kicks you back out to the index page of the www folder - I don't think the site alias is 100% sticking for requests.
Let me know if there is any sort of log or report I can share to help diagnose/debug this. Any and all help greatly appreciated - thanks!
It sounds like your specific error accessing pages beyond the homepage is related to not having mod_rewrite enabled/configured.
A different approach:
On a bigger scale, it sounds to me like you might not have what it takes to administer the staging server when something goes wrong. If you're unskilled at linux server admin, save yourself the headache and use a preconfigured virtual appliance (e.g. Quickstart, AegirDev, or Walid) instead of the dedicated box. If your staging box isn't beefy enough to handle hosting virtual machines, then just run the QuickStart install scripts over a base uBuntu build.
Now that you know your staging server is working and runs imported Drupal sites successfully, install git, create a shared repo, and make sure you and your developers are setup to use git as their source control in their IDE.

Wordpress Dev Environment Migration

I've tried looking around for a guide on moving a wordpress site into a dev environment, but all of the guides I've seen have been about CREATING one, as opposed to my situation, where I need to move an existin site to a local VM to create a dev/testing environment.
I'm fairly well-versed on how to create a dev environment from a regular old website, but just about everything wordpress-related gets me confused somehow.
Where I am now:
I've created a CentOS 6.0 VM using VMware on a Windows 7 machine. I've installed PHP, Apache, MySQL, and FTP-Server, along with all of the required updates and such. I have disabled SELinux.
I've moved the contents of the var/www/html/ folder from the live (production) server over to the var/www/html/ folder on my VM (currently exists within /var/www/html/my-website/)
My current issue:
When I attempt to access localhost/my-website/ I'm getting "Error establishing a database connection". An attempt at localhost/my-website/wp-admin/ tells me that either the database server is down (do I have to start this separately?) or that the username and/or password information in wp-config.php is incorrect (this was all simply moved from one place to another).
Any assistance would be greatly appreciated.
Have you updated wp-config.php to include your localhost and database info for your local dev environment?
I bet wp-config.php is still pointing to your remote server DB which the MySQL DB wont allow for external connections
Also, make sure that the dev is using the same domain as the live version. On my windows machine, I do this by changing my hosts file. I'm sure there is something similar on your VM.
If I am unable to do this and I need the dev version to be under a different domain I would do the following.
Create mysqldump of live database
Edit the dump and replace
all occurrences of livedomain.com with devdomain.com (if you dont do
this at least check the wp_options table for the livedomain.com
occurences.
Change wp-config.php database settings.
I always ensure to use the same domain (controlled by local hosts file), and same db config in my dev environment as in my live environment.
If you've not changed the wp_options table for (option_name = siteurl or option_name = home), then chances are if you type in devdomain.com into your browser it will redirect to newdomain.com
Hope this helps
Blake
I know this was been answered but just to be perfectly clear:
on Centos6 you need to run httpd with php, and the mysql server. In the mysql server you have to import the database dump from the live website then you have to edit the config in wordpress to match the username and password on wordpress.
now when moved the db does not keep the username and password so I suggest you do this
commands to be run in shell:
service mysqld start
chkconfig mysqld on
that will take care of the db server running
then edit wp-config with username root and no password (I am pretty sure you have not added a password at mysql-server install)
post in here if you need further help.

Resources