{"id":252,"date":"2025-11-22T10:38:12","date_gmt":"2025-11-22T10:38:12","guid":{"rendered":"https:\/\/haco.club\/?p=252"},"modified":"2025-11-22T10:38:12","modified_gmt":"2025-11-22T10:38:12","slug":"wordpress-site-migration-from-centos7-to-ubuntu24","status":"publish","type":"post","link":"https:\/\/haco.club\/?p=252","title":{"rendered":"WordPress site Migration from CentOS7 to Ubuntu24"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\"><strong>Phase 1: Preparation on CentOS 7 (Source Server)<\/strong><\/h3>\n\n\n\n<p>First, you need to back up your data. Log in to your CentOS server via SSH.<\/p>\n\n\n\n<p>1\u3001<strong>Backup the Database<\/strong><br>Run this command to export your database to a SQL file.<br><em>(Replace\u00a0db_name,\u00a0db_user\u00a0with your actual database details)<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysqldump -u db_user -p db_name > wordpress_backup.sql<\/code><\/pre>\n\n\n\n<p>2\u3001<strong>Backup WordPress Files<\/strong><br>Compress your website files into a single archive to make the transfer easier.<br><em>(Assuming your site is at\u00a0\/var\/www\/html\u00a0or\u00a0\/usr\/share\/nginx\/html)<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tar -czf wordpress_files.tar.gz <em>\/var\/www\/html<\/em><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Phase 2: Setup Ubuntu 24.04 (Destination Server)<\/strong><\/h3>\n\n\n\n<p>Log in to your new Ubuntu 24.04 server. You need to install the\u00a0<strong>LEMP<\/strong>\u00a0stack (Linux, Nginx, MySQL, PHP).<\/p>\n\n\n\n<p>1\u3001<strong>Update and Install Nginx &amp; MySQL<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update &amp;&amp; sudo apt upgrade -y\nsudo apt install nginx mysql-server ghostscript -y<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\"><\/ol>\n\n\n\n<p>2\u3001<strong>Install PHP and Extensions<\/strong><br>Ubuntu 24.04 defaults to PHP 8.3. Install PHP-FPM and the required WordPress extensions:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install php-fpm php-mysql php-curl php-gd php-mbstring php-xml php-xmlrpc php-zip php-intl php-bcmath php-soap -y<\/code><\/pre>\n\n\n\n<p>3\u3001<strong>Configure MySQL<\/strong><br>Create a new database and user for your migrated site.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mysql<\/code><\/pre>\n\n\n\n<p>Inside the MySQL shell:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE DATABASE wordpress_db;\nCREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'strong_password';\nGRANT ALL PRIVILEGES ON wordpress_db.* TO 'wp_user'@'localhost';\nFLUSH PRIVILEGES;\nEXIT;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Phase 3: Transfer Data<\/strong><\/h3>\n\n\n\n<p>You can pull the files from your old CentOS server directly to your new Ubuntu server using&nbsp;rsync. Run these commands&nbsp;<strong>on the Ubuntu server<\/strong>:<\/p>\n\n\n\n<p><em>(Replace&nbsp;root@centos_ip&nbsp;with your CentOS server&#8217;s user and IP)<\/em><\/p>\n\n\n\n<p>1\u3001<strong>Transfer the Files<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rsync -avz root@centos_ip:\/home\/root\/wordpress_files.tar.gz \/tmp\/\nrsync -avz root@centos_ip:\/home\/root\/wordpress_backup.sql \/tmp\/<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Phase 4: Restore on Ubuntu 24.04<\/strong><\/h3>\n\n\n\n<p>1\u3001<strong>Restore Files<\/strong><br>Create the web root directory and extract your files.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mkdir -p \/var\/www\/yourdomain.com\nsudo tar -xzf \/tmp\/wordpress_files.tar.gz -C \/var\/www\/yourdomain.com<\/code><\/pre>\n\n\n\n<p>2\u3001<strong>Fix Permissions<\/strong><br>CentOS often uses\u00a0nginx\u00a0or\u00a0apache\u00a0as the user, but Ubuntu uses\u00a0www-data. You\u00a0<strong>must<\/strong>\u00a0update ownership:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo chown -R www-data:www-data \/var\/www\/yourdomain.com\nsudo find \/var\/www\/yourdomain.com -type d -exec chmod 755 {} \\;\nsudo find \/var\/www\/yourdomain.com -type f -exec chmod 644 {} \\;<\/code><\/pre>\n\n\n\n<p>3\u3001<strong>Restore Database<\/strong><br>Import the SQL dump into the new database you created in Phase 2.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mysql wordpress_db &lt; \/tmp\/wordpress_backup.sql<\/code><\/pre>\n\n\n\n<p>4\u3001<strong>Update wp-config.php<\/strong><br>Edit your configuration file to match the new database credentials.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano \/var\/www\/yourdomain.com\/wp-config.php<\/code><\/pre>\n\n\n\n<p>Update these lines:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>define( 'DB_NAME', 'wordpress_db' );\ndefine( 'DB_USER', 'wp_user' );\ndefine( 'DB_PASSWORD', 'strong_password' );\ndefine( 'DB_HOST', 'localhost' );<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Phase 5: Nginx Configuration<\/strong><\/h3>\n\n\n\n<p>Ubuntu stores Nginx configs in\u00a0\/etc\/nginx\/sites-available\/. Create a new config file:<\/p>\n\n\n\n<p>1\u3001<strong>Create Config File<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo vim \/etc\/nginx\/sites-available\/yourdomain.com<\/code><\/pre>\n\n\n\n<p>2\u3001<strong>Paste the Configuration<\/strong><br><em>Note: Ubuntu 24.04 uses\u00a0php8.3-fpm.sock\u00a0by default. Ensure the\u00a0fastcgi_pass\u00a0line matches this.<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>server {\n    listen 80;\n    server_name yourdomain.com www.yourdomain.com;\n    root \/var\/www\/yourdomain.com;\n    index index.php index.html index.htm;\n\n    location \/ {\n        try_files $uri $uri\/ \/index.php?$args;\n    }\n\n    location ~ \\.php$ {\n        include snippets\/fastcgi-php.conf;\n        fastcgi_pass unix:\/run\/php\/php8.3-fpm.sock;\n        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\n        include fastcgi_params;\n    }\n\n    location ~ \/\\.ht {\n        deny all;\n    }\n}<\/code><\/pre>\n\n\n\n<p>3\u3001<strong>Enable the Site<\/strong><br>Link the file to\u00a0sites-enabled\u00a0and test the config.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ln -s \/etc\/nginx\/sites-available\/yourdomain.com \/etc\/nginx\/sites-enabled\/\nsudo nginx -t<\/code><\/pre>\n\n\n\n<p><em>(If you see &#8220;syntax is ok&#8221;, proceed. If not, fix the errors shown).<\/em><\/p>\n\n\n\n<p>4\u3001<strong>Restart Nginx<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl restart nginx<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Phase 6: Final Steps<\/strong><\/h3>\n\n\n\n<p>1\u3001<strong>Update DNS:<\/strong>\u00a0Point your domain&#8217;s A record to the new Ubuntu server&#8217;s IP address.<\/p>\n\n\n\n<p>2\u3001<strong>Install SSL (HTTPS):<\/strong>\u00a0Once DNS propagates, secure your site with Let&#8217;s Encrypt.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install certbot python3-certbot-nginx\nsudo certbot --nginx -d yourdomain.com -d www.yourdomain.com<\/code><\/pre>\n\n\n\n<p>Your site should now be live on Ubuntu 24.04!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Phase 1: Preparation on CentOS 7 (Source Server) First, you [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[40,38,39,37],"class_list":["post-252","post","type-post","status-publish","format-standard","hentry","category-tutotial","tag-centos7","tag-site-migration","tag-ubuntu24","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/haco.club\/index.php?rest_route=\/wp\/v2\/posts\/252","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/haco.club\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/haco.club\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/haco.club\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/haco.club\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=252"}],"version-history":[{"count":1,"href":"https:\/\/haco.club\/index.php?rest_route=\/wp\/v2\/posts\/252\/revisions"}],"predecessor-version":[{"id":253,"href":"https:\/\/haco.club\/index.php?rest_route=\/wp\/v2\/posts\/252\/revisions\/253"}],"wp:attachment":[{"href":"https:\/\/haco.club\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=252"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/haco.club\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=252"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/haco.club\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=252"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}