WordPress is a widely-used content management system (CMS) that allows users to create and manage websites efficiently. On Ubuntu, WordPress runs on a web server powered by Apache, a MySQL database, and PHP to process dynamic content. Setting up WordPress involves configuring these components to ensure seamless interaction with the CMS.

For WordPress to function properly, you must install and configure the LAMP stack—Linux, Apache, MySQL, and PHP. Each of these components plays a critical role in serving web content. Apache acts as the web server, MySQL stores site data, and PHP processes and generates dynamic site elements. All configurations must be accurate to ensure a stable and secure setup.

Server security and optimization are key when deploying WordPress. Correct file permissions and database configuration ensure that only authorized users can access the necessary files and data. Configuring Apache settings, such as enabling mod_rewrite, ensures that URLs function correctly within WordPress. Regular updates and maintenance help keep the system secure and running smoothly.

Steps to install and configure WordPress on Ubuntu:

  1. Create a MySQL database for WordPress.
    $ sudo mysql -u root -p
    mysql> CREATE DATABASE wordpress;
    mysql>CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'password';

    Make sure to replace 'password' with a strong, secure password for your WordPress user.

  2. Grant all privileges to the WordPress database user.
    mysql> GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost';
    mysql> FLUSH PRIVILEGES;
    mysql> EXIT;
  3. Download WordPress to the web directory.
    $ cd /var/www/html
    $ sudo wget https://wordpress.org/latest.tar.gz
  4. Extract WordPress files into the Apache web root directory.
    $ sudo tar -xvzf latest.tar.gz
    $ sudo mv wordpress/* /var/www/html/
  5. Set ownership and permissions for the WordPress directory.
    $ sudo chown -R www-data:www-data /var/www/html/
    $ sudo chmod -R 755 /var/www/html/
  6. Rename wp-config-sample.php to wp-config.php.
    $ sudo mv /var/www/html/wp-config-sample.php /var/www/html/wp-config.php
  7. Edit wp-config.php with your database details.
    $ sudo nano /var/www/html/wp-config.php
  8. Update the following lines with your database name, user, and password.
    define('DB_NAME', 'wordpress');
    define('DB_USER', 'wordpressuser');
    define('DB_PASSWORD', 'password');
    define('DB_HOST', 'localhost');

    Ensure that the credentials match the MySQL database you created earlier.

  9. Create a virtual host file for WordPress in Apache.
    $ sudo nano /etc/apache2/sites-available/wordpress.conf
  10. Add the following configuration:
    <VirtualHost *:80>
        ServerAdmin admin@example.com
        DocumentRoot /var/www/html/
        ServerName example.com
        ServerAlias www.example.com
    
        <Directory /var/www/html/>
            AllowOverride All
        </Directory>
    
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>

    Replace example.com with your actual domain name or server IP address.

  11. Enable the Apache rewrite module.
    $ sudo a2enmod rewrite
    $ sudo a2ensite wordpress
  12. Restart Apache to apply changes.
    $ sudo systemctl restart apache2
  13. Complete the WordPress installation in the browser.

    Open your web browser and navigate to http://yourdomain.com// or http://your_server_ip//. You will see the WordPress setup page.

  14. Set up SSL and secure the installation.

    Consider using Let's Encrypt to obtain a free SSL certificate for your domain.

Discuss the article:

Comment anonymously. Login not required.