sajad torkamani

Ensure server is properly configured and has required dependencies

Let’s assume you have a standard WordPress project that you want to deploy on an Ubuntu 20.04.3 server. Make sure you’ve configured your server and that it has any required dependencies. A typical set of dependencies might be as follows:

RequirementDescription
php^8.0.3Because WordPress is written in PHP.
php-fpmProvides FastCGI implementation (interface between Nginx and PHP)
PHP extensionscurl, dom, exif, fileinfo, hash, imagick, json, mbstring, mysql, openssl, pdo, pcre, xml, zip
ImageMagickRequired by imagick extension
GhostScriptEnables Imagick/ImageMagick to generate PDF thumbnails for the media library.
Nginx ^1.20To serve static files and process PHP files via php-fpm
MySQL^8.0.28WordPress website will use MySQL as database.
ComposerTo manage PHP dependencies.

Refer to the WordPress hosting handbook for more info on configuring the server environment.

For the purpose of this post, let’s assume you’ll be deploying the website on the domain https://sajadtorkamani.com.

Document system requirements

Add a README.md to your project root and list the dependencies mentioned above. It’s a good idea to specify PHP version and extensions in your composer.json file like so:

  "require": {
    "php": "^8.0.3",
    "ext-curl": "*",
    "ext-dom": "*",
    "ext-exif": "*",
    "ext-fileinfo": "*",
    "ext-hash": "*",
    "ext-imagick": "*",
    "ext-json": "*",
    "ext-mbstring": "*",
    "ext-pdo_mysql": "*",
    "ext-openssl": "*",
    "ext-pcre": "*",
    "ext-xml": "*",
    "ext-zip": "*"
  },

Then, during local setup or on deployment, you can run the following command to ensure these requirements are met:

composer check-platform-reqs

Push latest changes to Git remote

Make sure you push your changes to a remote Git repo.

Clone Git repo on server

Create a directory on the server to contain your Git repo. A good location is /home/<username>/sites/<repo>.

Create Nginx config file

Create file:

touch /etc/nginx/sites-available/sajadtorkamani.com

See this post for what configuration to use.

Create symlink:

ln -s /etc/nginx/sites-available/sajadtorkamani.com  /etc/nginx/sites-enabled/

Test for syntax errors:

sudo nginx -t

Restart or reload Nginx:

sudo systemctl reload nginx

Configure DNS records

Make sure you’ve configured your DNS settings so that the domains sajadtorkamani.com and www.sajadtorkamani are pointing to your Ubuntu server’s IPv4 address. An A and CNAME record like the below should suffice:

TypeHostnameValue
Asajadtorkamani.com<your-server-ip>
CNAMEwww.sajadtorkamani.comsajadtorkamani.com

You can use a service like dnschecker.org to check whether your DNS records have propagated yet.

Clone local database on remote server

See this post.

Transfer media files to remote server

If you need to transfer media files to the remote server, see this post.

Tagged: WordPress