Jump to content

Best way to get sites online?


dan222
 Share

Recommended Posts

Hey, huge thanks to Ryan and everyone who is involved in creating and developing processwire. I've just built my first site, which is just a simple blog site, but I can see that processwire is a great tool to have available, even if I don't yet have enough knowledge to use it to its full  potential. 

I have a question about getting the site online - I managed to do it by starting again with a blank template in the hosting provider, creating all the fields, templates and pages again, then copy and pasting all my files over. Though this worked, it was a bit long-winded and I'm sure there must be better ways!

I did search the forum and tried following the steps in the below thread, but Export Site Profile kept giving me errors, and replacing the site folder of a new install with my already-made site folder made the server stop working (even after I updated the login details in config) and I couldn't work out what the problem was.

I'm just wondering what the generally accepted way of getting things online is? I use Windows and Laragon - Laragon is really great for local development (as in it's just easy and I've never had any issues) but would I be better off using something else that helps me get the files online more easily?

 

 

Link to comment
Share on other sites

Hello @dan222 and welcome to this forum!

To push a site online :

  •  go to your db manager on laragon and export your db as a sql file
  • then, from your hosting control panel, create a db (or empty it if it already exists) and import your local db
  • with FTP, copy your local files in your hosting folder for your site (don’t forget to change the database config in /site/config.php file)

And that’s all. ?

Now, you can be a bit more efficient by

  • using an "if" statement for your database config, so that you don’t have to worry about changing them when you push your site online (see below)
  • using ssh/rsync to synchronize your local and distant files
  • I’m sure you can optimize database export/import too, I didn’t dig in yet...
// db config online / on localhost
if ( $_SERVER["HTTP_HOST"] === "my-online-url.com") {
	$config->dbHost = '...';
	$config->dbName = '...';
	$config->dbUser = '...';
	$config->dbPass = '...';
} else {
	$config->dbHost = 'localhost';
	$config->dbName = 'my-local-dbname';
	$config->dbUser = 'root';
	$config->dbPass = '';
}
$config->dbPort = '3306';

I generally need 4 minutes to pull or push a website after or before working on it, if it involves db update.
If it’s only changes in files, it’s done in 10-15 seconds.

  • Like 3
Link to comment
Share on other sites

I do it essentially the same as what @TomPich said, but on the first move from local to remote I find it's a lot faster and more reliable to compress all the website files to a ZIP archive, upload that to the remote server, then extract it on the server. If you're using cPanel then the included File Manager is a convenient way to upload and extract.

And when using a host that doesn't include a file manager I like to use TinyFileManager, although you need to take due care with security - as extra protection I rename the containing folder to include a dot prefix to prevent access when I'm not actively using it.

  • Like 7
  • Thanks 1
Link to comment
Share on other sites

Posted (edited)
On 6/2/2024 at 6:32 PM, TomPich said:

Now, you can be a bit more efficient by

  • using an "if" statement for your database config, so that you don’t have to worry about changing them when you push your site online (see below)
  • using ssh/rsync to synchronize your local and distant files
  • I’m sure you can optimize database export/import too, I didn’t dig in yet...

Hi. I am using two site config files. The site/config-dev.php holds the DB settings and debug settings for my local site, the site/config.php holds all the settings for the live site. PW checks for presence of a config-dev.php and uses this file instead of default site/config.php if it exists. On my local dev setup, I do have a config-dev.php file next to my site/config.php file. On the live server I just upload the site/config.php or delete/rename the site/config-dev.php via FTP.

Then I just ZIP my entire local setup once I am finished, upload the ZIP via FTP into the root of my live server together with an PHP unzip file and then visit the URL of the unzip script on my live server in the browser. The unzip scripts extracts all the files, sets right permissions if needed and deletes the ZIP folder and the unzip script itself once done.

The local DB dump is done via DDEV DB export feature and then just loaded to the live server via phpMyAdmin or whatever DB tools the hosting company offers. This is done before I upload the ZIP file to my live server.

For some extra safety, I create a dump of the live DB and rename the live site/ and wire/ folders to site.bak/ and wire.bak/ via Ftp before doing the update. This way I can easily revert back to the last working live state if needed - never needed for my PW sites so far, but happened in the past with some WP sites I tried to update. 

Edited by cwsoft
  • Like 2
Link to comment
Share on other sites

Hi,

just a few words to say don't forget the .htaccess file at the site root that may need to be changed
- to force with or without the www
- probably to force https too
- and, something if nearly always do in the htaccess, to add some headers, pw default ones in the htaccess are

<IfModule mod_headers.c>
  # prevent site from being loaded in an iframe on another site
  # you will need to remove this one if you want to allow external iframes
  Header always append X-Frame-Options SAMEORIGIN

  # To prevent cross site scripting (IE8+ proprietary)
  Header set X-XSS-Protection "1; mode=block"

  # Optionally (O) prevent mime-based attacks via content sniffing (IE+Chrome)
  # Header set X-Content-Type-Options "nosniff"
</IfModule>

and i often end with something like that

<IfModule mod_headers.c>
  # prevent site from being loaded in an iframe on another site
  # you will need to remove this one if you want to allow external iframes
  Header always append X-Frame-Options SAMEORIGIN

  # To prevent cross site scripting (IE8+ proprietary)
  Header set X-XSS-Protection "1; mode=block"

  # Optionally (O) prevent mime-based attacks via content sniffing (IE+Chrome)
  Header set X-Content-Type-Options "nosniff"
  Header set Content-Security-Policy "frame-ancestors 'self' https://www.helloasso.com"
  Header set Access-Control-Allow-Origin "*"
  Header set Referrer-Policy "no-referrer"
  Header set Permissions-Policy "geolocation=(), camera=(), microphone=()"
  Header always set Strict-Transport-Security "max-age=31536000; includeSubdomains"
</IfModule>

of course, just an exemple as helloasso is just here to say i allow iframes from this url (a french asso donation website) but you may need extra iframes,  some of those can be more complex depending on your website needs
more infos on those curious things here
https://securityheaders.com/
?

 

have a nice day

  • Like 3
Link to comment
Share on other sites

sorry, hi again ?

just to say, in your config file, don't forget this line

$config->httpHosts = array('www.yourdomain.com');

as it's important for a lot of things, beginning with preview pages clicking on wiew buttons in the admin

have a nice day

  • Like 1
Link to comment
Share on other sites

Thanks for all the tips, it looks like it should be pretty straightforward to get sites online and this thread will be very helpful to read when I'm trying to put up my next site.

@TomPich - thanks for that, I assume FTP is something I'll find on cpanel? Or otherwise I can use TinyFileManager that @Robin S mentions. I'm sure it will help that I've now got a live site hosted which I can copy the config and htaccess files from if necessary, I imagine the line @virtualgadjo has mentioned is probably one of the things that went wrong last time.

Thanks again!

Link to comment
Share on other sites

@dan222 coming to the htaccess file you just have to use pw one and uncommenting the lines you need about those www (section 13 of the file) an https (section 9) things, evyting thing is very well commented in the file it self

have a nice day

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...