Posts

Manually trigger a post-receive hook for testing

Using a post-receive hook is a good way to perform a scripted action each time new changes are pushed to a git repo. (If you have not yet set up a basic post-receive hook, consider consulting this article.)

If you’re interested in adding more to your post-receive hook, you might want to have a quick way to test it, without adding & pushing a bunch of test commits. We can trigger it manually with this advice from Kris Jordan.

When you’re working on a post-receive hook, it’s annoying to muck up your project’s commit history and push each time you make a change. Luckily, because it’s just a script, we can fake it from the command-line.

cd ../remote
git log -2 --format=oneline --reverse

First, we need to get the IDs of our most recent 2 commits. The git log command, above, will give us these two IDs in the order you’ll want to replace the $FROM_ID and $TO_ID variables with, respectively.

echo "$FROM_ID $TO_ID refs/heads/master" | ./hooks/post-receive

This method makes setting up your post-receive hooks enjoyable, enabling you to quickly iterate on your script and execute it repeatedly.

Use git with just a shared network drive. No git server required!

Want to use git for a small team of developers, but can’t (or don’t want to) use a git server? No problem! All you need is a shared network drive (like a dev server) that all of your developers can access. You’ll set up a repository for each developer, a central bare repository for them to push files to, and a git hook to auto-deploy files to a folder of your choice. This workflow works great for projects like websites and web applications.

How to install WordPress as fast as possible

This guide intends to walk you through every step of a WordPress install. It was designed with NearlyFreeSpeech.NET hosting in mind, but may be helpful on other hosts as well.

  1. Use PuTTY to SSH into the server where you wish to install WordPress.
  2. Run
    wget https://wordpress.org/latest.tar.gz

    To get the latest install files for WordPress.

  3. Run
    tar -xzvf latest.tar.gz

    To unzip the wordpress folder.

  4. Run
    rm latest.tar.gz

    To delete the zipped folder.

  5. Run
    cp -rp wordpress/* /home/public/

    To copy the contents of the unzipped WordPress directory to the root directory of your server. You might have to use a path different than "/home/public/" depending on your particular server.

  6. Run
    rm -r wordpress

    To delete the unzipped WordPress directory.

  7. Log into  phpMyAdmin (or equivalent UI for your server’s MySQL Database).
  8. Click on “Databases”.
  9. Create a new database by providing a database name like “sitenamewp”, then clicking “Create”. WordPress recommends using “utf8mb4_general_ci” collation when creating a database. Write the database name down–it will be required later.
  10. Return to the main page by clicking phpMyAdmin logo in the top left.
  11. Click “User Accounts”
  12. Click “Add user account”
  13. Give the user a name like “wpuser_sitename” Write the user name down–it will be required later.
  14. Generate a password for the user by clicking the “Generate” button. Write the password down–it will be required later.
  15. Click “Go” to create the user.
  16. Go back to “User accounts”, then click “Edit privileges” for the recently created user.
  17. Click “Database”.
  18. Select the database that you created for this WordPress site, then click “Go”.
  19. Click “Check all”, then click “Go” to give this user all permissions on the selected database.
  20. Look at the top of the page and write down the host name for your MySQl server. It will look something like “hostname.db” and be found after the text “Server:”.
  21. Run
    pico wp-config-sample.php

    to begin editing the WordPress config file. The section of the file that you’ll focus on editing looks like this:

    // ** MySQL settings ** //
    /** The name of the database for WordPress */
    define( 'DB_NAME', 'database_name_here' );
    
    /** MySQL database username */
    define( 'DB_USER', 'username_here' );
    
    /** MySQL database password */
    define( 'DB_PASSWORD', 'password_here' );
    
    /** MySQL hostname */
    define( 'DB_HOST', 'localhost' );
    
  22. Replace the text that says database_name_here with the name of the database you created in step 9.
  23. Replace the text that says username_here with the name of the user you created in step 13.
  24. Replace the text that says password_here with the password you generated in step 14.
  25. Replace the text that says localhost with the host name you made a note of in step 20.
  26. Optionally, add the line, define('FS_METHOD','direct'); to the end of the wp-config-sample.php file. This can make WordPress, Theme and Plugin upgrades easier, but be sure you are aware of the security concerns before doing this.
  27. Press CTRL + X to exit pico.
  28. Press Y to Save modified buffer.
  29. Change the “File Name to write” to wp-config.php, then press enter.
  30. Leave PuTTY open, we’ll come back to it later.
  31. Visit http://example.com/wp-admin/install.php in your browser to run the install script using the config settings you provided.
  32. Follow the on screen instructions to choose a title for your site, and set up the first user.
  33. Click “Install WordPress”.
  34. In PuTTY, run the following commands one after another:
    cd wp-content
    mkdir -p uploads
    chgrp -R web uploads
    chmod -R 775 uploads
    cd ..

    This should ensure that you can upload files to your site (based on recommendation here.)

  35. In PuTTY, run the following command:
    touch .htaccess

    This creates an empty .htaccess file, which can be used for setting up permalinks. (source).

  36. In PuTTY, run the following commands one after another:
    chgrp -R web *
    find . -type d -exec chmod 775 {} \;
    find . -type f -exec chmod 664 {} \;

    This will allow the web server to create a modify files. It also sets proper permissions for directories and files. It’s riskier than using the WordPress CLI from a security standpoint, but more convenient for WordPress users. (source and source).

And that’s it! WordPress should be set up and ready to go!