How to Change WordPress Default Upload Folder and URL DOMAIN

This behavior has been removed from WordPress, so if you need to change the default folder location for uploaded files or images, we need to change wp-config.php or set using wp-cli. The default folder is wp-content/uploads, let say we want to change that to /var/www/ on the same server and set the URL for files

Install Dependency

We’ll need curl to download the wp-cli file

sudo apt install curl -y

Download WordPress CLI

Download the latest WordPress CLI from the Github


move these file to /usr/local/bin

sudo mv wp-cli.phar /usr/local/bin/wp

set the file permission to executable, so we don’t need to run wp-cli using php /usr/local/bin/wp

sudo chmod +x /usr/local/bin/wp

Change WordPress Setting

My current WordPress located at /var/www/ Debian use www-data as default user for nginx or apache, replace with your webserver user.

# move to WordPress folder
cd /var/www/
sudo -u www-data wp option set upload_path /var/www/
sudo -u www-data wp option set upload_url_path

Create the folder for upload

mkdir /var/www/

copy data from old location to new location

cp -r /var/www/* /var/www/

Setting Web Server

The last part of this setup is to add vhost (server block) for domain
Set A record for DNS to Server IP. I use nginx, here’s my config

server {
    listen 80;
    return 301$request_uri;
server {
    listen 443 http2 ssl;
    ssl_certificate /etc/nginx/DOMAIN/fullchain.cer;
    ssl_certificate_key /etc/nginx/DOMAIN/;
    error_log /var/log/nginx/;
    root /var/www/;
    index index.htm index.html;

reload the Nginx then check your WordPress, the images should be served using domain.

Verify by checking
wordpress uploading files location

Leave a Comment