1

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?

2
  • i'm unclear on what you want to keep: do you basically want to make an image of the partition that ubuntu's installed on, and move it to a new computer? or do you want just configurations and dbs?
    – strugee
    May 1, 2013 at 16:53
  • @strugee: I just want the web sites, including all configurations and databases. I do not want to mirror the whole partition. Part of the reason I am moving to a new computer is to start fresh with most settings. I just want to keep the web sites.
    – Questioner
    May 1, 2013 at 16:59

2 Answers 2

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.

0

This is a pretty simple task for which you need 4 things:

  1. Dump of all MySQL databases (use mysqldump for this) and
  2. List of installed packages for apache2 and the modules that you use (dpkg -l and grep are your friends) and
  3. Files in /etc/apache2/sites-available (since that's where the actual virtualhost configuration files should be - those in sites-enabled should only be symlinks usually created with a2ensite
  4. Other files under /etc/apache2 that you've made modifications to.

If you do this by hand each time you want to move them then yes, it is tedious, which is one of the reasons you should aim to automate it by writing a simple shell script that takes care of all this for you.

5
  • Thank you for answering, however, it's not that I don't understand that I need those things or that a script would be good, what I'm asking is exactly how. Saying "dpkg -l and grep are your friends" is cute, but it doesn't describe any process. Also, if I dump all MySQL databases, that doesn't include all MySQL user account and privilege information. Sorry, but this doesn't really answer the question, as it lacks any details about how to carry out your recommendations.
    – Questioner
    May 2, 2013 at 3:20
  • Well, I did assume your familiarity with basic management of the OS you're using. Also, your question doesn't show any prior research. You can indeed use mysqldump to create a dump of all your databases that would allow you restore it fully, including the privilege and account information, so what you're stating is incorrect. The process is actually described, the implementation of it isn't. It looks like you consider somebody writing the script for you (since you're after the "exactly how" instructions") as the answer which is cute but I think I'll have to pass on your offer. Good luck. May 2, 2013 at 16:40
  • Just to prove the point about the lack of research: stackoverflow.com/questions/3982299/… May 2, 2013 at 16:42
  • Nowhere is there a request for anyone to write a script for me, but isn't Stack Exchange a place to get specific information? Now that I know that the mysql database is where user priveleges are stored, that's information I can use. But saying "Other files under /etc/apache2` is as generic as saying "Just copy over the files you need". Also, your "lack of research" accusation is just lashing out. Of course the information is out there, but that I didn't find it isn't evidence that I didn't look. If everyone always could find everything they needed to know, SE wouldn't need to exist.
    – Questioner
    May 3, 2013 at 7:09
  • If you read my answer again, you'll find that I wrote "Other files under /etc/apache2 that you've made modifications to", which is quite different from just "other files under [...]". I have no way of knowing which files you've made modifications to so it's reasonable to expect you know which ones you need to copy over. And I'd replace "lashing out" with stating the fact - I've found that link with the first query I used. I would have been more understanding if it wasn't for your sarcastic 'cute'. Over and out. May 3, 2013 at 13:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .