Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2023-02-23 23:24:57

lindabb
Member
Registered: 2023-02-17
Posts: 111

site URL saved in a table

Hello,

While I’m testing everything , I changed the project folder name, example

http://localhost/textpattern-1/ (located on c:\www\textpattern-1)
to
http://localhost/textpattern-2/ (changed to c:\www\textpattern-2)

Looks the site will show just empty!

after I looked around, I found the path and host name localhost/textpattern-1 saved in a table called txp_prefs
also saved in config.php

With all due respect, I think this is not good idea to save path or anything fixed location in a table.

I understand, textpattern developed long time ago, but maybe time to fix this issue!
really not big deal to change the script before uploading to shared hosting, but extra work, to get the path and then update the file.
That’s just my opinion,

Thank you

Last edited by lindabb (2023-02-23 23:32:12)

Offline

#2 2023-02-24 14:13:43

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,250
Website GitHub

Re: site URL saved in a table

I’m a little confused, sorry.

When you install Textpattern, you have to create config.php which defines:

  • Database credentials (username, password and the database to use).
  • Character set.
  • Path to your installation.
  • Any other optional per-installation settings you might require.

That determines your baseline system, then installation continues. All the information collected at installation time such as paths, site URL, username, theme, etc are used to populate the database for the first time. The paths are written into the txp_prefs table so that the system knows where, for example, your files and temporary files are going to be stored.

After installation has completed, if you use some external system (e.g. a file manipulation program, FTP program, command line, etc) to rename a folder where your installation is kept, how would Textpattern know you’ve changed it? You need to tell it what you’ve done, by doing one or more of the following, depending on what changes you have made:

  1. alter config.php if you’ve changed database credentials or the actual database name/connection method, or if you’ve renamed a folder or moved it.
  2. visit Admin>Preferences and alter the absolute paths to your ‘files’ and ‘temp’ locations [Admin sub-panel] or Site URL [Site sub-panel].
  3. visit any plugin settings that may rely on their own paths (e.g. rss_admin_db_manager needs to know the path where your database backups are stored).

Such data is stored so that Textpattern knows where things are and how to connect to them in the ecosystem. If you picked up a drink off a coffee table and someone else moved it while you were drinking, when you put your cup down where the table used to be, you’d get spillage. Same here. You need to tell Textpattern the new location of the coffee table or it has no idea where to find anything.

I can’t think of any other way round it, but if you know of a way we can give Textpattern access to the database credentials and path to the main site without actually storing them anywhere, please share!


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#3 2023-02-24 15:10:24

lindabb
Member
Registered: 2023-02-17
Posts: 111

Re: site URL saved in a table

Thank you Bloke for your good detailed explanation,
You can produce the issue your side.
here are steps I did:
In my home computer windows 10. I have Apache 2.4 root folder c:\www\
unzipped textpattern into to c:\www\textpattern-1
ran , setup, everything worked as expected.
when I go to http://localhost/textpattern-1 works
closed the browser, and renamed the folder
c:\www\textpattern-1
to
c:\www\textpattern-2

after I opened , the browser and typed http://localhost/textpattern-2 nothing shows just blank page
, and sure I get error if I go to http://localhost/textpattern-1 because no such folder or site.

when I changed config.php to reflect my new path
$txpcfg[‘txpath’] = ‘C:\www\textpattern-2\textpattern’;

same issue, the http://localhost/textpattern-2 didn’t work, just blank page.
logged in to phpadmin, changed
file_base_path, tempdir to reflect new path, and changed
siteurl’, ‘localhost/textpattern-2’ in table txp_prefs

and the new change worked, I was able to see the site http://localhost/textpattern-2

My point is:
file_base_path, tempdir and siteurl
should be stored in config.php not in a db table, possible even siteurl not to be there in first place
can be updated on fly when the browser opens.
yes, we may need file_base_path, tempdir, even that can be site root–relative path
like
.\ so on.
Less or no configuration like plug and play is better, other than db configuration really extra issue :)

Hope I’m clear this time

Thank you

Offline

#4 2023-02-24 18:23:04

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,250
Website GitHub

Re: site URL saved in a table

lindabb wrote #334746:

closed the browser, and renamed the folder c:\www\textpattern-1 to c:\www\textpattern-2 after I opened, the browser and typed http://localhost/textpattern-2 nothing shows just blank page

Yes, as expected.

when I changed config.php to reflect my new path $txpcfg[‘txpath’] = ‘C:\www\textpattern-2\textpattern’; same issue, the http://localhost/textpattern-2 didn’t work, just blank page.

Yes, as expected in the current implementation.

logged in to phpadmin, changed file_base_path, tempdir to reflect new path, and changed siteurl’, ‘localhost/textpattern-2’ in table txp_prefs and the new change worked

As expected.

file_base_path, tempdir and siteurl should be stored in config.php not in a db table

For the first two, maybe. They were probably not put in there to make it seem less burdensome when installing, and also to allow Textpattern admins to change them without requiring file system access.

Since multi-site installations use their own database and config.php, it’s probably okay to store these paths there.

The site URL, I’m not so sure about. Technically, sure, it could go in there. We would need to alter the setup process so it asked for the URL in the 2nd step, rather than the final step. Anything after step 2 can’t be added to config.php without write access to it from the web server user. That’s a level of burden we’ve never been comfortable with pushing onto users. Plus, it’s better if the very heart of the system configuration and security credentials is not writeable by the web server.

The site URL is guessed from the executing script environment, and can be overridden to allow for multi-site setups. It’s conceivable to add it to config.php but it still doesn’t solve your initial request that simply by renaming a folder, everything carries on working. You would still have to alter config.php.

we may need file_base_path, tempdir, even that can be site root–relative path

I’d rather not. The reason these two are absolute paths (where images is root-relative) is because these can be moved outside of docroot for an additional layer of security. Fetching files is handled via an indirection process (example.com/file_download/id) so they do not need to be housed in docroot. They’re only there by default because it’s easier to bundle the installation zip file up that way. Otherwise, people would need to faff with creating the directory by hand during installation, which is a barrier.

The values of these settings are editable from the Admin>Preferences panel to allow site administrators to move the files and temp directories anywhere on the system. A common use case (for me at least) is to set the temp dir to /tmp, or /tmp/site-name on Linux hosts.

By taking the ability to move these folders away from site admins who use Textpattern’s back-end, and only permitting them to be changed by site admins with file system access, we make it slightly more difficult for people to harden their installations. Yes, usually, the site admin is the same person who has file system access, but not always.

As I mentioned earlier, we’re not – and never have been – comfortable with having people open up the permissions on config.php to be writeable by the web server process. If we ever relax that, then sure it’d be possible to divert the settings from the back-end to write to the file rather than the database.

Ultimately it’s a balance. Security vs convenience.

One thing we could do, maybe, is to permit the values of those three settings to be made by you during (or after) setup, manually in config.php. Then, if those settings are defined, lock the settings in the admin panel. That’s a process that works for the new SMTP settings. Try it and see the effect it has on the prefs panel in 4.9.0-dev.

That might be a handy compromise towards allowing database independence for those that really need it. We would have to wire up the internals a little differently so that any access to those three values is obtained from the config file first (if they exist) and then the database second. But I don’t think it’s beyond the realm of possibility.

Be interesting to canvas opinion on this from the other developers. Thoughts?


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#5 2023-02-24 18:59:07

lindabb
Member
Registered: 2023-02-17
Posts: 111

Re: site URL saved in a table

Thank you for detailed explanation, I appreciate it.
also another way to fix this issue is partial fix,
when user browse the site always goes through index.php and then db connection, may be option to let user know something changed like the direct and siteurl doesn’t match what is saved in the configurable db,
offer the user to fix it , just may be. :)

BTW: I’m not complaining or asking anything other than to know how this nice CMS works and possibilities.

Thank you again

Offline

#6 2023-02-24 19:02:32

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,250
Website GitHub

Re: site URL saved in a table

lindabb wrote #334750:

when user browse the site always goes through index.php and then db connection, may be option to let user know something changed like the direct and siteurl doesn’t match what is saved in the configurable db

That could work. It kind of does this already if you mangle the connection details or if config.php is missing. But yeah we could do more, perhaps.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#7 2023-02-28 16:57:47

lindabb
Member
Registered: 2023-02-17
Posts: 111

Re: site URL saved in a table

Hello,
Looks virtual host not working too.

I created a record in host file (c:\Windows\System32\Drivers\etc\hosts) as:
127.0.0.1 sitedev1

then on may Apache24 ..\conf\extra\httpd-vhosts.conf added

<VirtualHost sitedev1:80> DocumentRoot “C:/www/textpattern/” DirectoryIndex index.php ServerName sitedev1
</VirtualHost>

Restarted the computer (I don’t think I needed that) , just restart Apache24 service will work,
However,
when I go to
http://localhost/sitedev1/ shows blank page no error,

any idea ?
again, not an issue, I’m just testing it.

Thank you

Offline

Board footer

Powered by FluxBB