WordPress Local Dev on Linux: Step-by-Step Setup
In this article
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)
- Install Docker and Docker Compose if not already present. On Ubuntu, run
sudo apt update && sudo apt install docker.io docker-compose. On Fedora, usesudo dnf install docker docker-compose. Then start Docker withsudo systemctl start dockerand enable it to start on boot:sudo systemctl enable docker. - Create a project directory for your WordPress site. For example:
mkdir ~/wordpress-local && cd ~/wordpress-local. - Create a
docker-compose.ymlfile 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-contentvolume lets you edit themes and plugins from your host machine. The port8080is arbitrary; you can change it to any free port. - Start the containers with
sudo docker-compose up -d. The first run will pull images, which may take a few minutes. - Wait for the database to initialize. Give it about 30 seconds after the containers start.
- Open your browser and go to
http://localhost:8080. You should see the WordPress installation wizard. - Complete the WordPress installation: choose your language, enter a site title, admin username, password, and email. Click “Install WordPress”.
- Log in to your new admin dashboard at
http://localhost:8080/wp-admin.
Method 2: Manual LAMP Stack
- 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. - Start the services:
sudo systemctl start apache2 mysql(orhttpdandmariadbon Fedora). Enable them to start on boot:sudo systemctl enable apache2 mysql. - Secure MySQL (optional but recommended): run
sudo mysql_secure_installationand set a root password. - 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; - 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. - Set proper permissions so Apache can write to the uploads directory:
sudo chown -R www-data:www-data /var/www/html(on Fedora, useapache:apache). - Create the wp-config.php file: copy the sample:
sudo cp wp-config-sample.php wp-config.php, then edit it withsudo nano wp-config.phpand fill in your database name, username, and password. Save and exit. - 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 updatefor PHP/MySQL. - Back up your
wp-contentfolder – that’s where your themes, plugins, and uploads live. - Use a local domain like
mysite.localby editing/etc/hostsand Apache virtual hosts, but this is optional. - For testing different PHP versions, use Docker with specific tags like
wordpress:php7.4orwordpress:php8.2.
Troubleshooting
If the site doesn’t load or shows errors, try these in order:
- Check that services are running:
sudo systemctl status dockerorsudo systemctl status apache2 mysql. Restart them if needed. - Check the Docker logs:
sudo docker-compose logs– look for database connection errors. - Verify the database is ready: In Docker, run
sudo docker-compose exec db mysql -u root -pand try selecting the database. If it fails, wait longer and restart the WordPress container. - Check Apache error logs in manual method:
sudo tail -f /var/log/apache2/error.log(or/var/log/httpd/error_logon Fedora). - If you see “Error establishing a database connection”, double-check the credentials in
wp-config.phpor the environment variables in docker-compose. - If the page shows a 403 Forbidden, check file permissions and that Apache has read access to the web root.
- 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.