Yii Framework Forum: amintado/yii2-module-wordpress - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

amintado/yii2-module-wordpress Rate Topic: -----

#1 User is offline   SteveM 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 80
  • Joined: 26-October 15
  • Location:Navan, Ireland

Posted 09 February 2018 - 06:17 AM

I'm trying to understand how this module works in order to get it to work. If I had a better understanding of auto-loading and the inner workings of Yii, I could solve this myself.

I have it configured according to the instructions:

'modules' => [
        'cms'=>[
                    'class'=> amintado\wordpress\Module::className(),
                ]
]


Then I'm instructed to open this link in order to install Wordpress: http://yourhost.com/.../index.php/cms.

Since I've removed index.php, I'm accessing it with this link: http://yourhost.com/cms/
Note that the trailing slash is needed (is this correct?). Then it runs the default controller of the module, which creates /cms in the root directory (i.e. outside of the web folder) and copies Wordpress to it. Then it runs wp-load.php with this line:

include (__DIR__.'/../../../../cms/wp-load.php');

This is the wp-load file in cms, not in the vendor directory. So far so good, until it comes to line 202 of wp-load, which attempts to redirect to /cms/wp-admin/setup-config.

    if ( false === strpos( $_SERVER['REQUEST_URI'], 'setup-config' ) ) {
        header( 'Location: ' . $path ); // $path = 'https://myhost/cms/wp-admin/setup-config.php
	exit;
    }


But this just returns a 404 not found error. And in fact anything I try to access in /cms/ returns the same error.

My question right now is, how is the module attempting to redirect to a script outside the web folder and why isn't it working?

httpdocs
|----backend

|----cms

|----wp-load.php

|----wp-admin

|----setup-config.php

|----wp-content

|----wp-includes

|----yii-config

|----common

|----frontend

1

#2 User is offline   SteveM 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 80
  • Joined: 26-October 15
  • Location:Navan, Ireland

Posted 12 February 2018 - 03:45 PM

I've managed to complete the WP setup by adding the db schema to my Yii db and configuring wp-config manually. Now the default controller shows the setup is complete:

// Module DefaultController.php
public function actionIndex()
    {
        echo 'ok;Finished';


    }


That's great! Now how do I access Wordpress? If I try https://myhost.com/cms, it just tries to direct me to site/cms. I'm still not clear on how this is supposed to run outside of the web directory.
0

#3 User is offline   atty 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 21-February 18

Posted 21 February 2018 - 07:34 AM

Dia dhuit :-)

View PostSteveM, on 09 February 2018 - 06:17 AM, said:

I'm trying to understand how this module works in order to get it to work. If I had a better understanding of auto-loading and the inner workings of Yii, I could solve this myself.

With folder structure:
Vendor -> amintado -> yii2-module-wordpress
Composer will give you the following autoload entries:

autoload_psr4.php (in vendor / composer folder)
 'amintado\\wordpress\\' => array($vendorDir . '/amintado/yii2-module-wordpress'),


autoload_static.php
 public static $prefixLengthsPsr4 = array (
...
 array (
            'amintado\\wordpress\\' => 19,
        ),


and

public static $prefixDirsPsr4 = array (
...
'amintado\\wordpress\\' => 
        array (
            0 => __DIR__ . '/..' . '/amintado/yii2-module-wordpress',
        ),


you should also have:
install.json in the same folder containing:
{
        "name": "amintado/yii2-module-wordpress",
        "version": "v0.1.x-dev",
        "version_normalized": "0.1.9999999.9999999-dev",
        "source": {
            "type": "git",
            "url": "<removed because this is my first post>.git",
            "reference": "a0320cdf12316e28ee1649e09ffbf9ccd9f41d9c"
        },
        "dist": {
            "type": "zip",
            "url": "",
            "reference": "a0320cdf12316e28ee1649e09ffbf9ccd9f41d9c",
            "shasum": ""
        },
        "require": {
            "php": ">=5.6.0"
        },
        "time": "2017-09-26 09:48:16",
        "type": "yii2-extension",
        "installation-source": "source",
        "autoload": {
            "psr-4": {
                "amintado\\wordpress\\": ""
            }
        },
        "notification-url": "",
        "license": [
            "GPL"
        ],
        "authors": [
            {
                "name": "amintado",
                "email": "amintado@gmail.com"
            }
        ],
        "description": "wordpress CMS for Yii2 Framework ",
        "homepage": "<some url>",
        "keywords": [
            "Yii2 wordpress module",
            "amintado",
            "yii2",
            "yii2-wordpress"
        ]
    }



View PostSteveM, on 09 February 2018 - 06:17 AM, said:

Since I've removed index.php, I'm accessing it with this link: <url>/cms/
Note that the trailing slash is needed (is this correct?). Then it runs the default controller of the module, which creates /cms in the root directory (i.e. outside of the web folder) and copies Wordpress to it. Then it runs wp-load.php with this line:


'removed index.php' - do you mean you have enabled pretty urls?
i do not use a trailing slash, but it gets added anyways when I hit enter


to install I did the following:

composer -vvv require amintado/yii2-module-wordpress "v0.1.x-dev"
composer update amintado/yii2-module-wordpress --lock


Did you add the cms module to the config file in the frontend folder? (Many people add it to either the backend or console and have errors with accessing it)

'cms' => [
            // 'class'=> amintado\wordpress\Module::className(),
            'class'=> 'amintado\wordpress\Module',

        ],


One last thing to check is file permissions at the web root level (where wordpress has been copied)


Dia duit
0

#4 User is offline   SteveM 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 80
  • Joined: 26-October 15
  • Location:Navan, Ireland

Posted 21 February 2018 - 10:58 AM

Dia, thanks for your assistance. I have it successfully installed and configured. And yes, I did add the module to my frontend config. My problem right now is that I can't access the blog.

Quote

'removed index.php' - do you mean you have enabled pretty urls?

I removed index.php in .htaccess.

When I go to <url>/cms, I just get the "ok;Finished" message, showing that it's configured. But how do I access the blog?

The file permissions is 750 for the web project directory and 755 for the cms directory.
0

#5 User is offline   atty 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 21-February 18

Posted 22 February 2018 - 05:38 AM

View PostSteveM, on 21 February 2018 - 10:58 AM, said:


I removed index.php in .htaccess.

When I go to <url>/cms, I just get the "ok;Finished" message, showing that it's configured. But how do I access the blog?


A useful resource for testing .htaccess is: htaccess(dot)madewithlove(dot)be/

CMS has a 'index.php' maybe .htaccess is removing that and then you fall back to the default controller?

Part of my .htaccess:

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    IndexIgnore /
    RewriteEngine On
</IfModule>

<IfModule mod_rewrite.c>
...

#if frontend request
	RewriteCond %{REQUESTURI} ^/frontend/web
	RewriteCond %{REQUESTFILENAME} !-f
	RewriteCond %{REQUEST_FILENAME} !-d
	RewriteRule . /frontend/web/index.php
...
	
</IfModule>



If you change .htaccess you may then have to update your [urlManager]
Here is mine (the third one down is the only one directly relevant to you I do believe):

  'urlManager' => [
            'baseUrl' => $baseUrl,
            'class' => 'yii\web\UrlManager',
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
                'admin/<controller:\w+>/<action:[\w-]+>/<id:\d+>' => 'admin/<controller>/<action>',
                'admin/<module:\w+>/<controller:\w+>/<action:[\w-]+>/<id:\d+>' => 'admin/<module>/<controller>/<action>',
                '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
                '<controller:\w+>/view/<slug:[\w-]+>' => '<controller>/view',
                '<controller:\w+>/view/<cat:[\w-]+>/<slug:[\w-]+>' => '<controller>/view/',
                '<controller:\w+>/cat/<slug:[\w-]+>' => '<controller>/cat',
            ],
        ],


Séamus
0

#6 User is offline   SteveM 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 80
  • Joined: 26-October 15
  • Location:Navan, Ireland

Posted 23 February 2018 - 06:43 AM

I'm using this for .htaccess: https://github.com/i...-basic-htaccess
I do have pretty urls enabled.

These urls return a 404 not found error:
https://myhost.com/f.../index.php/cms/
https://myhost.com/f...d/index.php/cms
https://myhost.com/cms

This url resolves to the default controller and returns "Ok;Finished":
https://myhost.com/cms/

Can you show me where in the code it's trying to redirect to the <project folder>/cms? I know I'm being dense, but I just can't see how this is supposed to work.

By the way, I'm American living in Ireland. Dia dhuit was lost on me. But I googled it and I get it now. My daughter says it all the time. :-)
0

#7 User is offline   atty 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 21-February 18

Posted 23 February 2018 - 09:49 AM

I tried putting in die() in both module.php and defaultcontroller, no effect.

I deleted my amindato vendor folder and still everything worked as usual.

I then removed the cms folder from the root of my web directory and only then was the module run.

If I understand correctly Yii will serve up <yoursite>/cms/index.php if it is found, if not it loads the module that corresponds to cms which runs once to setup the wordpress cms folder and then does not run again until cms folder is absent.

Do you have a cms folder on your root web directory? (not just in your development environment but also on the server)
Does it contain index.php ?(wordpress' one)

Is the path spesified (correctly) in the init function of defaultcontroller.php

I cannot remember if I modified my path, here is what mine looks like:

 if (empty(realpath(__DIR__ . '/../../../../cms'))) {

            mkdir(__DIR__ . '/../../../../cms', 0777, true);
            $this->copy_directory(realpath(__DIR__ . '/../wordpress/') . '/', realpath(__DIR__ . '/../../../../cms/') . '/');
        }


Don't feel like you are dense, it is not very transparent what is happening in this particular module.
0

#8 User is offline   SteveM 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 80
  • Joined: 26-October 15
  • Location:Navan, Ireland

Posted 23 February 2018 - 10:25 AM

I have my folder structure as shown above in the original post. Yes, there is an index file in the cms folder.

Maybe the problem is in the way I have the server setup. I have my production site at myhost.com and the dev server at dev.myhost.com. Right now I'm installing cms on the dev server. In Plesk, I have the the document root set to dev/frontend/web. So, I can't access anything outside the web folder. As far as I know, this is how Yii should be set up. I thought this extension would run WordPress as a module of Yii, and so be accessible somehow through the web folder without needing to access the cms directory directly.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users