Changing wordpress home folder

Could anyone please help me to change the home folder of wordpress from /var/www/html to /home/saurav/wordpress?


Solution 1:

  1. Move everything from /var/www/html to /home/saurav/wordpress:

    sudo mv /var/www/html/* /home/saurav/wordpress/
    
  2. /var/www/html is now empty, remove it:

    sudo rmdir /var/www/html
    
  3. Create a symbolic link from /var/www/html to /home/saurav/wordpress:

    sudo ln -s /home/saurav/wordpress /var/www/html
    

Solution 2:

The best way is create a new virtual host in Apache and then move all file to a new directory . To do it you can follow this guide step by step. Then you will be able to access WordPress with virtual domain from your favorite directory.

  1. Create the /home/user/www/mydomain.local/public_html directory and move your site's files to the new directory:

    mkdir -p /home/user/www/mydomain.local/public_html
    sudo mv /var/www/html/* /home/user/www/mydomain.local/public_html
    

    Note: Replace user with your username or home directory name and mydomain.local with your favorite name of local domain. This use for domain name of your local site public_html directory is optional but recommended, so create it.

  2. Make yourself the owner of the files contained in /var/www/example.com/public_html:

    sudo chown -R $USER:$USER /var/www/example.com/public_html
    

    The $USER variable will take the value of the user you are currently logged in with when you press Enter. By doing this, our regular user now owns the public_html subdirectories where we will be storing our content.

  3. Change the permissions of the files in /home/user/www/ :

    sudo chmod -R 755 /home/user/www/
    

    Your web server should now have the permissions it needs to serve content, and your user should be able to create content within the necessary folders.

  4. Create a virtual host for your site:

    sudo nano /etc/apache2/sites-available/mydomain.local.conf
    

    Add something like this in the file and save it:

    <VirtualHost *:80>
      ServerAdmin [email protected]
      ServerName mydomain.local
      ServerAlias www.mydomain.local
      DocumentRoot /home/user/www/mydomain.local/public_html
      ErrorLog /home/user/www/mydomain.local/error.log
      CustomLog /home/user/www/mydomain.local/access.log combined
    </VirtualHost>
    
  5. Now enable your site:

    sudo a2ensite mydomain.local.conf
    
  6. Open the local host file and add your domain point to localhost IP (127.0.0.1):

    sudo /etc/hosts
    

    Add this at the end of the file:

    127.0.0.1 mydomain.local
    
  7. Finally restart Apache:

    sudo service apache2 restart
    

You should be able to see the result by typing http://mydomain.local in your browser.