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:
-
Move everything from
/var/www/html
to/home/saurav/wordpress
:sudo mv /var/www/html/* /home/saurav/wordpress/
-
/var/www/html
is now empty, remove it:sudo rmdir /var/www/html
-
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.
-
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 andmydomain.local
with your favorite name of local domain. This use for domain name of your local sitepublic_html
directory is optional but recommended, so create it. -
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 thepublic_html
subdirectories where we will be storing our content. -
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.
-
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>
-
Now enable your site:
sudo a2ensite mydomain.local.conf
-
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
-
Finally restart Apache:
sudo service apache2 restart
You should be able to see the result by typing http://mydomain.local
in your browser.