Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

WordPress Local Dev on Linux: Step-by-Step Setup

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Setting up WordPress locally on Linux lets you build and test sites without paying for hosting or waiting for uploads. You get a full WordPress install running on your own machine. The fastest way is using Docker with the official wordpress and mysql images, but we'll also cover a manual LAMP stack method. Both work; Docker is cleaner and easier to reset.

What You'll Need

  • A Linux machine (Ubuntu, Debian, Fedora, etc.) with sudo access
  • Terminal access
  • For Docker method: Docker and Docker Compose installed
  • For manual method: Apache, MySQL/MariaDB, PHP installed
  • Internet connection to download WordPress and dependencies

Step-by-Step

Method 1: Docker (Recommended)

  1. Install Docker and Docker Compose if not already present. On Ubuntu, run sudo apt update && sudo apt install docker.io docker-compose. On Fedora, use sudo dnf install docker docker-compose. Then start Docker with sudo systemctl start docker and enable it to start on boot: sudo systemctl enable docker.
  2. Create a project directory for your WordPress site. For example: mkdir ~/wordpress-local && cd ~/wordpress-local.
  3. Create a docker-compose.yml file in that directory with the following content. This defines a WordPress service and a MySQL database service.
    version: '3.1'
    
    services:
      wordpress:
        image: wordpress:latest
        ports:
          - "8080:80"
        environment:
          WORDPRESS_DB_HOST: db
          WORDPRESS_DB_USER: exampleuser
          WORDPRESS_DB_PASSWORD: examplepass
          WORDPRESS_DB_NAME: exampledb
        volumes:
          - ./wp-content:/var/www/html/wp-content
      db:
        image: mysql:5.7
        environment:
          MYSQL_DATABASE: exampledb
          MYSQL_USER: exampleuser
          MYSQL_PASSWORD: examplepass
          MYSQL_ROOT_PASSWORD: rootpass
        volumes:
          - db_data:/var/lib/mysql
    volumes:
      db_data:

    Note: The ./wp-content volume lets you edit themes and plugins from your host machine. The port 8080 is arbitrary; you can change it to any free port.

  4. Start the containers with sudo docker-compose up -d. The first run will pull images, which may take a few minutes.
  5. Wait for the database to initialize. Give it about 30 seconds after the containers start.
  6. Open your browser and go to http://localhost:8080. You should see the WordPress installation wizard.
  7. Complete the WordPress installation: choose your language, enter a site title, admin username, password, and email. Click “Install WordPress”.
  8. Log in to your new admin dashboard at http://localhost:8080/wp-admin.

Method 2: Manual LAMP Stack

  1. Install Apache, MySQL, and PHP. On Ubuntu: sudo apt install apache2 mysql-server php php-mysql libapache2-mod-php php-xml php-mbstring php-curl php-zip. On Fedora: sudo dnf install httpd mariadb-server php php-mysqlnd php-xml php-mbstring php-curl php-zip.
  2. Start the services: sudo systemctl start apache2 mysql (or httpd and mariadb on Fedora). Enable them to start on boot: sudo systemctl enable apache2 mysql.
  3. Secure MySQL (optional but recommended): run sudo mysql_secure_installation and set a root password.
  4. Create a database and user for WordPress. Log into MySQL: sudo mysql -u root -p, then run:
    CREATE DATABASE wordpress;
    CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'yourpassword';
    GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
    FLUSH PRIVILEGES;
    EXIT;
  5. Download WordPress to your web root. On Ubuntu, the default is /var/www/html. Use: cd /var/www/html && sudo wget https://wordpress.org/latest.tar.gz && sudo tar -xzf latest.tar.gz && sudo mv wordpress/* . && sudo rm -rf wordpress latest.tar.gz.
  6. Set proper permissions so Apache can write to the uploads directory: sudo chown -R www-data:www-data /var/www/html (on Fedora, use apache:apache).
  7. Create the wp-config.php file: copy the sample: sudo cp wp-config-sample.php wp-config.php, then edit it with sudo nano wp-config.php and fill in your database name, username, and password. Save and exit.
  8. Open your browser and go to http://localhost. The WordPress installer will appear. Complete the installation as in the Docker method.

Common Mistakes

  • Forgetting to start Docker or MySQL before trying to access the site. Always check service status.
  • Using the wrong port – if you already have something on port 8080, change it in the docker-compose file.
  • Not waiting for the database to initialize – the WordPress container may show a connection error if you try too early.
  • Editing files inside the Docker container directly – changes are lost when the container is recreated. Use the mounted volume instead.
  • Incorrect file permissions in the manual method – WordPress needs write access to the uploads folder.

Tips

  • Use a unique database name and user for each local site to avoid conflicts.
  • Keep your local WordPress updated by pulling new images or running sudo apt update for PHP/MySQL.
  • Back up your wp-content folder – that’s where your themes, plugins, and uploads live.
  • Use a local domain like mysite.local by editing /etc/hosts and Apache virtual hosts, but this is optional.
  • For testing different PHP versions, use Docker with specific tags like wordpress:php7.4 or wordpress:php8.2.

Troubleshooting

If the site doesn’t load or shows errors, try these in order:

  1. Check that services are running: sudo systemctl status docker or sudo systemctl status apache2 mysql. Restart them if needed.
  2. Check the Docker logs: sudo docker-compose logs – look for database connection errors.
  3. Verify the database is ready: In Docker, run sudo docker-compose exec db mysql -u root -p and try selecting the database. If it fails, wait longer and restart the WordPress container.
  4. Check Apache error logs in manual method: sudo tail -f /var/log/apache2/error.log (or /var/log/httpd/error_log on Fedora).
  5. If you see “Error establishing a database connection”, double-check the credentials in wp-config.php or the environment variables in docker-compose.
  6. If the page shows a 403 Forbidden, check file permissions and that Apache has read access to the web root.
  7. If nothing works, delete the containers/volumes and start fresh: sudo docker-compose down -v (this removes the database – you’ll lose any local data).

Frequently Asked Questions

Can I use this for a production site?

No. This is for local development only. Production requires proper security, caching, and backup configurations.

How do I access my local site from another device?

By default, it’s only available on your machine. To access from another device on your network, use your computer’s IP address instead of localhost, and ensure your firewall allows the port.

How do I reset my WordPress admin password?

You can use the “Lost your password?” link on the login page, or run a WP-CLI command if you have it installed.

Can I have multiple local WordPress sites?

Yes. For Docker, create a new directory with a different docker-compose.yml and change the port (e.g., 8081). For manual, create a new database and a new folder in /var/www/html.

How do I update WordPress locally?

In Docker, pull the latest image and recreate containers: sudo docker-compose up -d --force-recreate. In manual, download the latest WordPress and replace the files, keeping your wp-content folder.

Why is my local site slow?

Local sites are usually fast. If it’s slow, check that MySQL is running on the same machine, and consider increasing PHP memory limits in php.ini.