# WordPress Installer - Edit

Installs a wordpress development environment for Magina's development's team.

Requirements

  • Git
  • Composer
  • an SSH key configured on your BitBucket Account
  • Create the good docroot : /wp/
  • Use nginx on host config
  • Disable proxy on host config

Installation

  • If you are on our server "Carlos", you can execute the following script to run all at once :
    cd /var/wwww/vhost/my-project.ontest.net/
    ./deploy-magina.sh

You can also do all by ourself, with the following commands :

  • Go on the directory you want to install WordPress
    cd /var/wwww/path-to-project/httpdocs/
  • Clone repository
    git clone git@bitbucket.org:magina_fr/wordpress-installer.git . && rm -rf .git

    ⚠️ make sure your vhost webroot points to the wp folder

  • Run Composer to install it and all its dependencies. (The installer will ask you for infos)
composer install && composer install-starter-theme
  • Create a database for your new vhost on your local environment & visit your new website webpage to install WP.

 

⚠️ A note about Webservers

If you run wordpress on a Apache Server, you will need an .htaccess at the root of the wp folder for pretty permalinks to work.
You have two options :
  • A composer command that flushes wordpress rewrites rules (and recreates the .htaccess) is available
    composer flush-rewrite-rules

    You can run this command after your usual deploy process.

  • If you need a more precise control over the content of the .htaccess. You can create the file in the src/public folder.
    ⚠️ Any file created in this folder will be copied into the wp folder at the end of the build process.

Add plugins

With the wordpress installer, you can easily add and manage your plugins

  • cd in the directory you have installed wordpress
    cd /var/wwww/path-to-project/httpdocs/
  • To find the repository for the desired plugin, visit WordPress Packagist
  • open the file "composer.json" (the one in "httpdocs" folder) and add the selected repository under "require". If you want to always have the last version, replace the version with "*"
    "require": { 
    ... 
    "wpackagist-plugin/akismet":"dev-trunk", 
    "wpackagist-plugin/wordpress-seo":"*", 
    },
  • ⚠️ All the plugins are not available in WordPress Packagist, like GravityForm. To install them, you have to download them (most of the time, where they are sold).
    Once you have the file, copy the content in the plugin folder

    cd /var/wwww/path-to-project/httpdocs/src/plugins
  • Run Composer to install the new plugin. It will also update other plugins if necessary
    cd /var/wwww/path-to-project/httpdocs/ 
    MAGINA_ENV=dev composer update

The update will copy all the plugins at the right location, you don't have to copy them under /var/wwww/path-to-project/httpdocs/wp/wp-content/plugins.

Deploy

When you need to deploy your website a few options are available to you.

Build website package (if you only have FTP access)

If you need to build a package to deploy wp on a remote host via FTP.

composer build-delivery-package

This will build a .tar.gz archive that you can upload and unzip on the server directly.

You can create a .env.production file at the root of your project. The variables declared inside it will be used to build the wp-config.php file.

PLESK server

If your production server is a PLESK administrated server (ONYX minimum as we need the Git module)

PLESK Git Configuration

  • Select deploy mode: Automatic deployment
  • Enable additional deploy actions: ✔
  • Actions*:
    /opt/plesk/php/7.1/bin/php /usr/lib/plesk-9.0/composer.phar install --no-dev -a -n

You will need to create a .env file at the root of the project.

If you want your website to redeploy with every push to your branch, you can setup the webhook provided by PLESK into your Bitbucket repo.

Cryptoweb (or any containerized environments)

When you need to deploy your website onto a Cryptoweb container.
Once logged-in the container, you can run the following command to deploy the website :

cd /path/to/your/webroot
git clone git@bitbucket.org:your-repo/url.git && composer install --no-dev -a

If you need to set ownership rights to "www-data" user :

cd /path/to/your/webroot
chown -R www-data:www-data .

When you need to pull new commits from your master branch:

cd /path/to/your/webroot
git fetch --all && git reset --hard origin/master && composer install --no-dev -a