Tuesday, April 23, 2024
 Popular · Latest · Hot · Upcoming
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 4604  / 2 Years ago, mon, september 19, 2022, 4:18:44

I have a whole set of web sites on my Ubuntu computer that I use for testing and development. I don't host them on the internet, I just access them locally for design and debugging.



Each one is built on PHP, each one uses a MySQL database. There are about twelve of them.



I want to transfer them to a new Ubuntu install. I've done this before, and when I have, I created each config file in /etc/apache2/sites-enabled, I load in each MySQL database, I create a user for each database... It's tedious and prone to (my) human error.



I already have all sites and all configurations set up on one computer. Is there not a way I can wholesale pick up all the databases, files, Apache settings, configurations, and everything and move it to the new server all in one go?


More From » apache2

 Answers
3

Thanks to tips both from Askubuntu and from the Linux & Unix SE, I compiled what seems to be the most efficient way of doing what I set out to do. I hope this is helpful to others, and if anyone can see any places where this process can be streamlined and improved, please contribute.



Note before proceeding that I use phpMyAdmin, so that's where I did all my MySQL operations. Also, this is assuming the target computer is a fresh install and that no settings or files on the new computer need saving. These operations will overwrite what's on the target computer. Lastly, this is what I did to transfer my system, so your specific situation will likely differ. This is just offered in hopes of giving people in similar situations a page less blank to start with. I transfered from Ubuntu 13.04 to Linux Mint 14.



On the old computer:



Make a directory where you can store everything you're going to transfer over.



Copy the directory where you keep all your HTML, CSS, and whatever other files that make up your website. I keep mine in directory in my /home folder, and then link to that from /var/www with a symlinked directory called Websites.



Copy all the entire /etc/apache2 directory directory.



Copy the file /etc/hosts.



Using phpMyAdmin, export to an sql file all the databases that you have created and want to move to the new server. In phpMyAdmin, under the export tab in the home area, you need to use the custom option to select which databases to export. Make sure to not copy the databases called mysql, performance_schema, and information_schema. You shouldn't need them, and you can't overwrite them on the new server anyway. So if you include them, it will just cause headaches when installing on the new computer.



Go into the mysql database and copy the table user into an sql file.



On the new computer:



Install phpMyAdmin in Synaptic. This installs all the necessary files for a LAMP server by pulling in all the relevant dependencies. You may need some additional components. In my case, I also needed javascript-common, and xdebug.



From the directory where you have stored all the files from the old computer, as described above, run the following command to move your apache2 directory into your /etc/folder.



sudo cp -R apache2 /etc


Open your old hosts file, and copy the first line only, everything after where it says 127.0.01. Make sure not to copy the line that begins with 127.0.1.1. Open /etc/hosts on the new computer and paste over the first line. Again, be careful to only copy what comes after 127.0.0.1. Leave the rest of the file alone. You will need root privileges to edit and save the /etc/hosts file.



Copy your HTML files and web site data to wherever you usually do. In my case, I keep them in the /home directory. Create a symlink to that directory in /var/www, and if you do, make sure that you have FollowSymLinks set as an option in /etc/apache2/sites-enabled/000-default and /etc/apache2/sites-available/default (usually they are the same file, linked to each other). Also, you need to make sure that the privileges for the folders being symlinked in your /home are accessible to the web server in terms of having the right privileges. That's kind of a big topic, and I've noticed people disagree about what makes sense. There are (at least) two users involved, the user account you log into your system with, and www-data, which administrates web server stuff. You could change which user you access your server with, you could include your login user into the right groups to access the web server... maybe... that part is unclear to me. However, for me, running chmod +x on the directory that contains the folder that contains all the HTML files did the trick. Just to be clear, you have to run that one level up from the folder that contains the HTML files. In my case, my HTML files and directories and sites are all in /home/dave/Dropbox/Websites. So I ran chmod +x /home/dave/Dropbox/, and then chmod +x -R /home/dave/Dropbox/Websites. Like I said, this part is fuzzy to me, as privileges always baffle me, but this is what worked.



In my case, I stored some of my Apache log files in a custom folder, called Apache_Logs in my /home directory. Recreate that file, and if you have any other custom features, you need to do the same.



Restart Apache with this command:



sudo service apache2 restart


Now that Apache is done, onto restoring the databases.



The sql file you created with all your databases in it might be large, many megabytes in size. When uploading an sql file in phpMyAdmin, it defaults to only allowing uploads up to a maximum of 2MB. To change this, open /etc/php5/apache2/php.ini, find where it says upload_max_filesize and change that to be big enough to upload your sql file. This requires root privilege, and change it back after you finish this whole thing, if you think it matters. If you do this, you will have to restart Apache again for the new setting to take effect.



In phpMyAdmin, under the Import tab, import all your databases by uploading your sql file.



Still in phpMyAdmin, go to the mysql database, select the user table, and drop it. Then go to the Import tab, and upload the user table sql file you saved from your old computer. At this point, you'll have all the users you had from the old machine, and all your databases, but the users and databases aren't connected, so this next part still has to be done one by one. :(



In the home area of phpMyAdmin, go into the Privileges tab where you'll find a list of all the users. Go through each of your created users, and with each one, select Edit Privileges, then in the screen that pops up, go to Database-specific privileges, select the correct database, and in the next screen you can select for that user to have the right privileges on the database you want them to control. In my case, each user has complete control over the database they administer, so I used the check-all function and saved.



You need to restart MySQL at this point, so the changes in the user privileges will take hold.



sudo service mysql restart


At this point you should be good to go. Open a browser and go to your web sites like you used to do on your old machine, and away you go!



I hope that is helpful for some others.


[#31455] Monday, September 19, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cisccla

Total Points: 66
Total Questions: 134
Total Answers: 115

Location: Croatia
Member since Fri, Sep 11, 2020
4 Years ago
;