NavigationContentFooter
Jump toSuggest an edit

Installing WordPress on a Scaleway Instance with Ubuntu 22.04 LTS (Jammy Jellyfish) and LEMP

Reviewed on 11 September 2024Published on 24 February 2023
  • WordPress
  • cms
  • php
  • LEMP
  • nginx
  • mysql
  • mariadb

WordPress is a popular and freely accessible open-source tool that offers a seamless means to craft and manage content on your website. With its intuitive interface and user-friendly features, WordPress has garnered extensive adoption, making it an ideal solution for swiftly launching a website. The web front-end it provides ensures effortless administration, simplifying the process even for those lacking technical expertise.

If you are seeking to install WordPress on a newly established Ubuntu 22.04 LTS Instance, this tutorial is tailor-made for your needs. We will meticulously walk you through the installation steps, employing the LEMP stack (Linux + Nginx - pronounced “engine x” + MySQL + PHP). For the sake of this tutorial, we are choosing Nginx, a robust HTTP server that is efficient in resource usage, resulting in faster page delivery, especially for static content. By opting for a Cost-Optimized Instance configured with LEMP, you will gain access to a robust web server that elevates website performance, thus ensuring a seamless WordPress installation experience.

Tip

We recommend you follow this tutorial using a Cost-Optimized Instance.

Before you start

To complete the actions presented below, you must have:

  • A Scaleway account logged into the console
  • Owner status or IAM permissions allowing you to perform actions in the intended Organization
  • An SSH key
  • sudo privileges or access to the root user
  • Installed LEMP
  • An FQDN (Fully Qualified Domain Name) pointing to your Instance’s IP address
  • Secured your LEMP stack with TLS/SSL

Installing WordPress

We assume that you have already installed LEMP stack. Let us proceed with the installation of WordPress on your Ubuntu Jammy Instance.

Important

WordPress is equipped to serve dynamic content and manage user authentication and authorization with ease. However, to ensure a secure connection to your site, the implementation of Transport Layer Security/Secure Sockets Layer (TLS/SSL) technology is essential. By encrypting your traffic, TLS/SSL guarantees a secure connection to your site. To configure SSL with Let’s Encrypt and complete the last stage of the tutorial, follow the link: Configuring SSL with Let’s Encrypt.

Configuring Nginx

To prepare for the upcoming WordPress installation, it is essential to configure Nginx to handle traffic. In the LEMP tutorial, we previously set up a server block for example.com, which served as the default Nginx page for our domain. Now, we will create a new server block called wordpress that will serve our WordPress site from the subdomain blog.example.com.

  1. Create a new server block for Nginx:

    nano /etc/nginx/sites-available/wordpress
  2. Paste the following configuration. Make sure to replace the configuration at the server_name line with your domain.

    server {
    listen 80;
    root /var/www/wordpress;
    index index.php index.html index.htm;
    server_name blog.example.com;
    location = /50x.html {
    root /usr/share/nginx/html;
    }
    location / {
    # try_files $uri $uri/ =404;
    try_files $uri $uri/ /index.php?q=$uri&$args;
    }
    location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/run/php/php7.2-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    }
    location = /favicon.ico {
    access_log off;
    log_not_found off;
    expires max;
    }
    location = /robots.txt {
    access_log off;
    log_not_found off;
    }
    # Cache Static Files For As Long As Possible
    location ~*
    \.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$
    {
    access_log off;
    log_not_found off;
    expires max;
    }
    # Security Settings For Better Privacy Deny Hidden Files
    location ~ /\. {
    deny all;
    access_log off;
    log_not_found off;
    }
    # Return 403 Forbidden For readme.(txt|html) or license.(txt|html)
    if ($request_uri ~* "^.+(readme|license)\.(txt|html)$") {
    return 403;
    }
    # Disallow PHP In Upload Folder
    location /wp-content/uploads/ {
    location ~ \.php$ {
    deny all;
    }
    }
    }
  3. Test the configuration to ensure that it will function correctly:

    nginx -t

    An output similar to the following displays.

    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful
  4. Enable the server block by symlinking:

    ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/wordpress
  5. Delete the Nginx default server block:

    rm /etc/nginx/sites-enabled/default
  6. Open the Nginx configuration file:

    nano /etc/nginx/nginx.conf
  7. Edit the following elements:

    • Update the number of worker processes to match the number of cores in your Instance to optimize your Nginx configuration.
    user www-data;
    worker_processes 1;
    pid /run/nginx.pid;
    • Add use epoll; to the events block.
    events {
    worker_connections 4096;
    multi_accept on;
    use epoll;
    }
    • Add the client_max_body_size 100m; and server_tokens off; directives, then set keepalive_timeout to 30 seconds as shown below.
    # Basic Settings
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 30;
    types_hash_max_size 2048;
    server_tokens off;
    client_max_body_size 100m;
    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;
    include /etc/nginx/mime.types;
    default_type application/octet-stream;
    • Make sure that the whole Gzip settings block is similar to the following.
    # Gzip Settings
    gzip on;
    gzip_disable "msie6";
    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 6;
    gzip_buffers 16 8k;
    gzip_http_version 1.1;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
  8. Restart the server:

    service nginx restart

Configuring PHP

To enable the upload of files larger than 2 MB to your WordPress website, you must adjust the PHP upload size variables located in the php.ini file.

  1. Open the php.ini file:
    nano /etc/php/7.4/fpm/php.ini
  2. Press Ctrl+W and search for upload_max_filesize and set it to 100M.
  3. Restart PHP:
    sudo service php7.4-fpm restart

Setting up the MySQL database

In this section, we will create the database user and tables.

  1. Log into the MySQL shell using your MySQL root password:

    mysql -u root -p
  2. Create a WordPress database and name it as desired:

    MariaDB [(none)]> CREATE DATABASE wordpress;

    The following output displays:

    Query OK, 1 row affected (0.00 sec)
  3. Create a new user and name it as desired:

    CREATE USER wordpressuser@localhost;

    The following output displays:

    Query OK, 0 rows affected (0.00 sec)
  4. Set a password for the new user:

    SET PASSWORD FOR wordpressuser@localhost= PASSWORD("password");

    The following output displays:

    Query OK, 0 rows affected (0.00 sec)
  5. Grant all privileges to the new user. Without this command, the WordPress installer will not be able to start up:

    GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost IDENTIFIED BY 'password';

    The following output displays:

    Query OK, 0 rows affected (0.00 sec)
  6. Refresh MySQL:

    FLUSH PRIVILEGES;

    The following output displays:

    Query OK, 0 rows affected (0.00 sec)
  7. Exit the MySQL shell:

    exit

Installing the WordPress Files

  1. Navigate to the site root directory:
    cd /var/www/
  2. Download the latest version of WordPress:
    wget http://wordpress.org/latest.tar.gz
  3. Extract it from the archive:
    tar -xzvf latest.tar.gz
  4. Grant the www-data user permissions to /var/www/wordpress to enable automatic updates of WordPress plugins and file editing with SFTP in the future.
    chown -R www-data:www-data wordpress/
    usermod -a -G www-data www-data

Completing the installation through the web interface

With the server configuration completed, you can now proceed to complete the installation via the web interface.

Open your preferred web browser and enter your Instances’s domain name or public IP address in the address bar:

http://instance_domain_or_IP/wordpress/

  1. Select your language.

    Before entering your database information, you need to return to the terminal to complete the following steps.

  2. Open the WordPress configuration file from your terminal:

    nano /var/www/wordpress/wp-config-sample.php
  3. Edit the information for your database under MySQL settings, to replace the default values with those you configured while setting it up. In our case, it looks like this:

    // ** MySQL settings - You can get this info from your web host ** //
    /** The name of the database for WordPress */
    define( 'DB_NAME', 'wordpress' );
    /** MySQL database username */
    define( 'DB_USER', 'wordpressuser' );
    /** MySQL database password */
    define( 'DB_PASSWORD', 'password' );
    /** MySQL hostname */
    define( 'DB_HOST', 'localhost' );
    /** Database charset to use in creating database tables. */
    define( 'DB_CHARSET', 'utf8' );
    /** The database collate type. Do not change this if in doubt. */
    define( 'DB_COLLATE', '' );
  4. Save and exit the file, then return to your web browser.

  5. Enter the database information for WordPress:

  6. Complete the five-minute WordPress installation process.

  7. Log in. Your dashboard displays.

API DocsScaleway consoleDedibox consoleScaleway LearningScaleway.comPricingBlogCareers
© 2023-2024 – Scaleway