<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>WordPress &#8211; Blog of Kliment Andreev &#8211; A place so I won&#039;t forget things</title>
	<atom:link href="https://blog.andreev.it/category/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.andreev.it</link>
	<description></description>
	<lastBuildDate>Sun, 02 May 2021 00:57:02 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>Rocky Linux: Install the pre-release on VMware and WordPress</title>
		<link>https://blog.andreev.it/2021/05/rocky-linux-install-the-pre-release-on-vmware-and-wordpress/</link>
					<comments>https://blog.andreev.it/2021/05/rocky-linux-install-the-pre-release-on-vmware-and-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[Kliment Andreev]]></dc:creator>
		<pubDate>Sat, 01 May 2021 17:05:50 +0000</pubDate>
				<category><![CDATA[ESX/ESXi]]></category>
		<category><![CDATA[Rocky Linux]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[rocky linux]]></category>
		<guid isPermaLink="false">https://blog.andreev.it/?p=8861</guid>

					<description><![CDATA[Rocky Linux was finally release today (5/1/2021) and I&#8217;ve decided to try it in&#8230;]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div><p>Rocky Linux was finally release today (5/1/2021) and I&#8217;ve decided to try it in my lab. I&#8217;ve downloaded the minimal ISO (Rocky-8.3-x86_64-minimal) and installed it under my vCenter version 6.x.<br />
I chose CentOS 8 as a base OS and after I mounted the ISO, I got an error saying <strong>ERROR Verification failed: (0x1A) Security Violation</strong>. If this is the case, shut down the guest, go to <strong>Settings | VM Options</strong> and if you expand <strong>Boot Options</strong>, change the <strong>Firmware</strong> from <strong>EFI </strong>to <strong>BIOS</strong>. This should do the trick.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2021/05/P154-01.png"><img fetchpriority="high" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2021/05/P154-01.png" alt="" width="865" height="472" class="aligncenter size-full wp-image-8864" srcset="https://blog.andreev.it/wp-content/uploads/2021/05/P154-01.png 865w, https://blog.andreev.it/wp-content/uploads/2021/05/P154-01-300x164.png 300w, https://blog.andreev.it/wp-content/uploads/2021/05/P154-01-768x419.png 768w, https://blog.andreev.it/wp-content/uploads/2021/05/P154-01-585x319.png 585w" sizes="(max-width: 865px) 100vw, 865px" /></a><br />
What you&#8217;ll see next is pretty much the same as any other CentOS 7/8 installation.</p>
<p><a href="https://blog.andreev.it/wp-content/uploads/2021/05/P154-02.png"><img decoding="async" src="https://blog.andreev.it/wp-content/uploads/2021/05/P154-02.png" alt="" width="792" height="592" class="aligncenter size-full wp-image-8866" srcset="https://blog.andreev.it/wp-content/uploads/2021/05/P154-02.png 792w, https://blog.andreev.it/wp-content/uploads/2021/05/P154-02-300x224.png 300w, https://blog.andreev.it/wp-content/uploads/2021/05/P154-02-768x574.png 768w, https://blog.andreev.it/wp-content/uploads/2021/05/P154-02-585x437.png 585w" sizes="(max-width: 792px) 100vw, 792px" /></a><br />
<strong>NOTE: The current version is not considered for production.</strong><br />
Do the same as you do with any other CentOS install. Partition the hard drive, change the root password, configure the network and add a user.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2021/05/P154-03.png"><img decoding="async" src="https://blog.andreev.it/wp-content/uploads/2021/05/P154-03.png" alt="" width="786" height="590" class="aligncenter size-full wp-image-8867" srcset="https://blog.andreev.it/wp-content/uploads/2021/05/P154-03.png 786w, https://blog.andreev.it/wp-content/uploads/2021/05/P154-03-300x225.png 300w, https://blog.andreev.it/wp-content/uploads/2021/05/P154-03-768x576.png 768w, https://blog.andreev.it/wp-content/uploads/2021/05/P154-03-585x439.png 585w" sizes="(max-width: 786px) 100vw, 786px" /></a><br />
Once the server is up, you&#8217;ll see the login prompt.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2021/05/P154-04.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2021/05/P154-04.png" alt="" width="673" height="451" class="aligncenter size-full wp-image-8868" srcset="https://blog.andreev.it/wp-content/uploads/2021/05/P154-04.png 673w, https://blog.andreev.it/wp-content/uploads/2021/05/P154-04-300x201.png 300w, https://blog.andreev.it/wp-content/uploads/2021/05/P154-04-585x392.png 585w, https://blog.andreev.it/wp-content/uploads/2021/05/P154-04-263x175.png 263w" sizes="(max-width: 673px) 100vw, 673px" /></a><br />
Check the kernel version and the release.</p>
<pre class="brush: bash; highlight: [1,3]; title: ; notranslate">
uname -a
Linux rocky.andreev.local 4.18.0-240.22.1.el8.x86_64 #1 SMP Mon Apr 12 04:29:16 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
cat /etc/redhat-release
Rocky Linux release 8.3
</pre>
<p>By default, both the firewall and SELinux are enabled. </p>
<pre class="brush: bash; title: ; notranslate">
systemctl status firewalld
sestatus
</pre>
<p>You can use <strong>dnf</strong>, <strong>yum </strong>or <strong>rpm </strong>to manage the packages. If you need to change the network settings, use <strong>nmtui</strong>.<br />
Let&#8217;s install WordPress now. As root or using sudo, install Apache, PHP and MariaDB.</p>
<pre class="brush: bash; title: ; notranslate">
dnf install httpd php php-mysqlnd mariadb-server wget php-json
</pre>
<p>Start the Apache and MariaDB and enable them on both to start on reboot.</p>
<pre class="brush: bash; title: ; notranslate">
systemctl enable httpd --now
systemctl enable mariadb --now
</pre>
<p>Open port 80 on the firewall for the Apache. </p>
<pre class="brush: bash; title: ; notranslate">
firewall-cmd --permanent --zone=public --add-service=http --permanent
firewall-cmd --reload
</pre>
<p>Do the initian MariaDB configuration and specify the new root password for the SQL server.</p>
<pre class="brush: bash; title: ; notranslate">
mysql_secure_installation
</pre>
<p>Log as the SQL root user to MariaDB.</p>
<pre class="brush: bash; title: ; notranslate">
mysql -u root -p
</pre>
<p>Create the database and the WordPress user.</p>
<pre class="brush: sql; title: ; notranslate">
CREATE DATABASE wordpress;
GRANT ALL ON wordpress.* TO 'wpadmin'@'localhost' IDENTIFIED BY 'supersecret';
FLUSH PRIVILEGES;
</pre>
<p>Get the latest WordPress release under /tmp, unzip it and copy it where it belongs (root Apache data directory).</p>
<pre class="brush: bash; title: ; notranslate">
cd /tmp
wget https://www.wordpress.org/latest.zip
unzip latest.zip
mv wordpress/* /var/www/html/
chown -R apache:apache /var/www/html
</pre>
<p>Change the SELinux context for the root Apache data directory. </p>
<pre class="brush: bash; title: ; notranslate">
chcon -t httpd_sys_rw_content_t /var/www/html -R
</pre>
<p>At this point, you can access your WordPress install at http://your_IP_or_hostname.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.andreev.it/2021/05/rocky-linux-install-the-pre-release-on-vmware-and-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>CentOS: Deploy WordPress on CentOS 7 using Chef</title>
		<link>https://blog.andreev.it/2018/04/126-chef-deploy-wordpress-on-centos-7/</link>
					<comments>https://blog.andreev.it/2018/04/126-chef-deploy-wordpress-on-centos-7/#respond</comments>
		
		<dc:creator><![CDATA[Kliment Andreev]]></dc:creator>
		<pubDate>Wed, 04 Apr 2018 14:36:29 +0000</pubDate>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[DevOps]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[Chef]]></category>
		<guid isPermaLink="false">http://blog.iandreev.com/?p=3799</guid>

					<description><![CDATA[In this post, I&#8217;ll describe how to create a Chef cookbook for deploying WordPress.&#8230;]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div><p>In this post, I&#8217;ll describe how to create a Chef cookbook for deploying WordPress. The blog engine will run on CentOS 7 using MariaDB and PHP. The website will be created as a virtual host and you can leave the firewall and SELinux as is. There are probably better WordPress cookbooks at the Chef Supermarket, but I decided to go with my own. Before you go further, make sure that you have a Chef server/workstation environment ready, otherwise you won&#8217;t be able to deploy the code. Check my other <a href="https://blog.andreev.it/?p=3522" rel="noopener noreferrer" target="_blank">post </a>on how to do that. Also, make sure you have a CentOS 7 client powered up and that you are able to log in with some username and that the DNS/hostnames is already in place. In my case, I&#8217;ll have a CentOS 7 server named centostest.andreev.local and a username klimenta that&#8217;s able to login.</p>
<h1>Chef</h1>
<p>OK, so log to your Chef workstation and go to your cookbooks directory. Create the wordpress cookbook.</p>
<pre class="brush: bash; title: ; notranslate">
chef generate cookbook wordpress
</pre>
<p>The directory structure looks like this.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2018/04/P103-01.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2018/04/P103-01.png" alt="" width="301" height="474" class="aligncenter size-full wp-image-8211" /></a><br />
Edit the <strong>metadata.rb</strong> file in the root directory and change it so it suit your needs. This is completely optional. You don&#8217;t have to change anything here. </p>
<pre class="brush: ruby; collapse: true; light: false; title: ; toolbar: true; notranslate">
name 'wordpress'
maintainer 'Kliment Andreev'
maintainer_email 'klimenta@iandreev.com'
license 'Simplified BSD License'
description 'Installs/Configures wordpress'
long_description 'Installs/Configures wordpress'
version '0.1.0'
chef_version '&gt;= 12.1' if respond_to?(:chef_version)

# The `issues_url` points to the location where issues for this cookbook are
# tracked.  A `View Issues` link will be displayed on this cookbook's page when
# uploaded to a Supermarket.
#
# issues_url 'https://github.com/&lt;insert_org_here&gt;/wordpress/issues'

# The `source_url` points to the development repository for this cookbook.  A
# `View Source` link will be displayed on this cookbook's page when uploaded to
# a Supermarket.
#
# source_url 'https://github.com/&lt;insert_org_here&gt;/wordpress'
</pre>
<p>Our next step is to create the default attributes. These are the values that we can change and modify the behavior of the installed packages or change the usernames, passwords, directory locations etc.</p>
<pre class="brush: bash; title: ; notranslate">
cd wordpress
chef generate attribute default
</pre>
<p>The commands above will create a new directory called <strong>attributes </strong>and a file called <strong>default.rb</strong>. Copy and paste the following into that file. As you can see, my blog will be reachable as http://centostest.andreev.local, the WordPress files will be under /var/www/centostest.andreev.local folder, the default httpd file is /etc/httpd/conf/httpd.conf etc&#8230;</p>
<pre class="brush: bash; title: ; notranslate">
# The name of your site
default&#x5B;'wordpress']&#x5B;'server_name'] ='centostest.andreev.local'
# The root directory of your site, it will be /var/www/yoursitename.com
default&#x5B;'wordpress']&#x5B;'document_root'] = &quot;/var/www/#{node&#x5B;'wordpress']&#x5B;'server_name']}&quot;
# The default config file
default&#x5B;'wordpress']&#x5B;'default_conf'] = '/etc/httpd/conf/httpd.conf'
# e-mail for the server admin
default&#x5B;'wordpress']&#x5B;'server_admin'] ='klimenta@iandreev.com'
# log dir for the site
default&#x5B;'wordpress']&#x5B;'log_dir'] = '/var/log/www'
# Error log for the site, it will be /var/log/wwwyoursitename-error.log
default&#x5B;'wordpress']&#x5B;'error_log'] = &quot;#{node&#x5B;'wordpress']&#x5B;'log_dir']}/&quot;&quot;#{node&#x5B;'wordpress']&#x5B;'server_name']}-error.log&quot;
# Access log for the site, it will be /var/log/wwwyoursitename-access.log
default&#x5B;'wordpress']&#x5B;'custom_log'] = &quot;#{node&#x5B;'wordpress']&#x5B;'log_dir']}/&quot;&quot;#{node&#x5B;'wordpress']&#x5B;'server_name']}-access.log&quot;
# The root password for MySQL
default&#x5B;'wordpress']&#x5B;'mysql_password'] = 'MySQLP4ssw0rd$'
# The name of the WordPress database
default&#x5B;'wordpress']&#x5B;'wordpress_database'] = 'wordpress'
# The default username for the WordPress database
default&#x5B;'wordpress']&#x5B;'wordpress_username'] = 'wp_user'
# The default password for the WordPress database
default&#x5B;'wordpress']&#x5B;'wordpress_password'] = 'W0rdPr3$$PWD'
</pre>
<p>Now, let&#8217;s move to the recipes. In order to install WordPress, we&#8217;ll have to install Apache web-server, install PHP and its modules so WordPress as a PHP program can run, then install MySQL database server and finally download WordPress and extract it under the Apache root directory that we specified in the default attributes. We&#8217;ll create a recipe for each of these steps.</p>
<h1>Apache recipe</h1>
<p>Create the recipe first. This will create a file <strong>apache.rb</strong> under the <strong>recipes </strong>directory. </p>
<pre class="brush: bash; title: ; notranslate">
chef generate recipe apache
</pre>
<p>This is how to recipe looks like. You can see from the comments what each block does. It&#8217;s very simple and straightforward. We install the Apache server, create the document root and the logs directory, we&#8217;ll copy the httpd.config file from a template, make sure that Apache starts on boot and we&#8217;ll poke a hole in the firewall so the HTTP port is allowed inbound. </p>
<pre class="brush: ruby; title: ; notranslate">
# Install Apache server
package 'httpd' do
  action :install
end

# Create the root directory and set the permissions and owners
directory node&#x5B;'wordpress']&#x5B;'document_root'] do
  owner 'apache'
  group 'apache'
  mode '0755'
  recursive true
end

# Create the Apache log directory
directory node&#x5B;'wordpress']&#x5B;'log_dir'] do
  recursive true
end

# Create the default httpd.conf file
template node&#x5B;'wordpress']&#x5B;'default_conf'] do
  source &quot;httpd.conf.erb&quot;
end

# Enable start on boot and start Apache
service 'httpd' do
  action &#x5B;:enable, :start]
end

# Allow HTTP to pass on the firewall
execute 'httpd_firewall' do
  command '/usr/bin/firewall-cmd  --permanent --zone public --add-service http'
  ignore_failure true
end

# Reload the firewall rules
execute 'reload_firewall' do
  command '/usr/bin/firewall-cmd --reload'
  ignore_failure true
end
</pre>
<p>One of the steps here says to create the default config file for the Apache web server and that the template for that is a file called <strong>httpd.conf.erb</strong>. So, let&#8217;s create that template. This command will create a directory called <strong>templates </strong>and a file <strong>httpd.conf.erb</strong>.</p>
<pre class="brush: bash; title: ; notranslate">
chef generate template httpd.conf
</pre>
<p>This is how our default config looks like. Copy and paste the following into the <strong>httpd.conf.erb</strong> file.</p>
<pre class="brush: bash; title: ; notranslate">
Listen 80
Include conf.modules.d/*.conf
User apache
Group apache
&lt;IfModule mime_module&gt;
    TypesConfig /etc/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
&lt;/IfModule&gt;

&lt;VirtualHost *:80&gt;
  ServerName &lt;%= node&#x5B;'wordpress']&#x5B;'server_name'] %&gt;
  ServerAdmin &lt;%= node&#x5B;'wordpress']&#x5B;'server_admin'] %&gt;
  DocumentRoot &lt;%= node&#x5B;'wordpress']&#x5B;'document_root'] %&gt;
  &lt;Directory &quot;/&quot;&gt;
          Options FollowSymLinks
          AllowOverride None
  &lt;/Directory&gt;
  &lt;Directory &lt;%= node&#x5B;'wordpress']&#x5B;'document_root'] %&gt; &gt;
          Options Indexes FollowSymLinks MultiViews
          AllowOverride None
          Require all granted
  &lt;/Directory&gt;
  ErrorLog &lt;%= node&#x5B;'wordpress']&#x5B;'error_log'] %&gt;
  CustomLog &lt;%= node&#x5B;'wordpress']&#x5B;'custom_log'] %&gt; combined
  AddType application/x-httpd-php .php
  AddType application/x-httpd-php-source .phps
  DirectoryIndex index.php index.html
&lt;/VirtualHost&gt;
</pre>
<h1>PHP</h1>
<p>Same as with the Apache recipe, we&#8217;ll have to generate a recipe for PHP and it&#8217;s modules.</p>
<pre class="brush: bash; title: ; notranslate">
chef generate recipe php
</pre>
<p>Edit the newly created file <strong>php.rb</strong> and copy and paste the following.</p>
<pre class="brush: ruby; title: ; notranslate">
# Install PHP and its modules
%w{php php-fpm php-mysql php-xmlrpc php-gd php-pear php-pspell}.each do |pkg|
  package pkg do
    action :install
    notifies :reload, 'service&#x5B;httpd]', :immediately
  end
end
</pre>
<h1>MySQL</h1>
<p>Same here, let&#8217;s generate a recipe for the installation of MySQL.</p>
<pre class="brush: bash; title: ; notranslate">
chef generate recipe mysql
</pre>
<p>This is the recipe to install MySQL. </p>
<pre class="brush: ruby; title: ; notranslate">
# Install MySQL client and server&lt;strong&gt;
%w{mariadb mariadb-server}.each do |pkg|
  package pkg do
    action :install
  end
end

# Enable start on boot and start the MySQL server
service 'mariadb' do
  action &#x5B;:enable, :start]
end

# Location of the initial MySQL script
template '/tmp/mysql.sql' do
  source &quot;mysql.conf.erb&quot;
end

# Execute the initial setup of MySQL
execute 'mysql_server' do
  command '/usr/bin/mysql -sfu root &lt; /tmp/mysql.sql &amp;&amp; ls /tmp/mysql.sql'
  ignore_failure true
end
</pre>
<p>As you can see from the recipe, we need a template with some SQL commands to run before we can use MySQL. This is equivalent of running mysql_secure_installation when you first install MySQL. In addition, I&#8217;ll use the SQL script to create the wordpress database as well.</p>
<pre class="brush: bash; title: ; notranslate">
chef generate template mysql.conf
</pre>
<p>This template contains what we need for an initial installation. Any subsequent runs will fail because we changed the MySQL password which is good. That means that we won&#8217;t mess up anything if we run this recipe more than once. So, edit the newly create file under <strong>templates </strong>called <strong>mysql.conf</strong> and copy and paste the following.</p>
<pre class="brush: sql; title: ; notranslate">
UPDATE mysql.user SET Password=PASSWORD('&lt;%= node&#x5B;'wordpress']&#x5B;'mysql_password'] %&gt;') WHERE User='root';
DELETE FROM mysql.user WHERE User='';
DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');
DROP DATABASE IF EXISTS test;
DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%';
FLUSH PRIVILEGES;
CREATE DATABASE &lt;%= node&#x5B;'wordpress']&#x5B;'wordpress_database'] %&gt;;
GRANT ALL PRIVILEGES ON &lt;%= node&#x5B;'wordpress']&#x5B;'wordpress_database'] %&gt;.*
TO &quot;&lt;%= node&#x5B;'wordpress']&#x5B;'wordpress_username'] %&gt;&quot;@&quot;localhost&quot;
IDENTIFIED BY &quot;&lt;%= node&#x5B;'wordpress']&#x5B;'wordpress_password'] %&gt;&quot;;
FLUSH PRIVILEGES;
</pre>
<h1>Download WordPress</h1>
<p>We have to create a recipe to download and extract WordPress.</p>
<pre class="brush: bash; title: ; notranslate">
chef generate recipe download
</pre>
<p>Edit the file and copy and paste the following. Pretty much it executes a bunch of bash commands to download the tarball, unzip it under the root directory and change the ownership. The recipe will stop if wp-settings.php exists, this means that WordPress is already installed. </p>
<pre class="brush: ruby; title: ; notranslate">
ruby_block &quot;download_wordpress&quot; do
  block do
    require 'fileutils'
    FileUtils.cd node&#x5B;'wordpress']&#x5B;'document_root']
    system 'curl -o latest.tar.gz https://wordpress.org/latest.tar.gz'
    system 'tar xzvf latest.tar.gz --strip-components=1 &amp;&amp; rm latest.tar.gz'
    system 'chown -R apache:apache *'
  end
  not_if { ::File.exist?(File.join(node&#x5B;'wordpress']&#x5B;'document_root'], 'wp-settings.php')) }
  action :create
end
</pre>
<h1>Wrap up</h1>
<p>Now that we have all recipes in place, we can tell Chef in what order to execute them. Edit the default recipe (<strong>default.rb</strong> file under <strong>recipes</strong>) and add these lines. </p>
<pre class="brush: ruby; title: ; notranslate">
include_recipe 'wordpress::apache'
include_recipe 'wordpress::php'
include_recipe 'wordpress::mysql'
include_recipe 'wordpress::download'
</pre>
<p>The best practice is to create a role for each cookbook, so let&#8217;s create one. </p>
<pre class="brush: plain; title: ; notranslate">
knife role create wordpress
</pre>
<p>Edit the json file so it looks like this.</p>
<pre class="brush: plain; title: ; notranslate">
{
  &quot;name&quot;: &quot;wordpress&quot;,
  &quot;description&quot;: &quot;Role to install WordPress (apache, php, mysql)&quot;,
  &quot;json_class&quot;: &quot;Chef::Role&quot;,
  &quot;default_attributes&quot;: {

  },
  &quot;override_attributes&quot;: {

  },
  &quot;chef_type&quot;: &quot;role&quot;,
  &quot;run_list&quot;: &#x5B;
    &quot;recipe&#x5B;wordpress::apache]&quot;,
    &quot;recipe&#x5B;wordpress::php]&quot;,
    &quot;recipe&#x5B;wordpress::mysql]&quot;,
    &quot;recipe&#x5B;wordpress::download]&quot;
  ],
  &quot;env_run_lists&quot;: {

  }
}
</pre>
<p>Upload the cookbook to the server and execute it against a node.</p>
<pre class="brush: bash; title: ; notranslate">
knife cookbook upload wordpress
knife bootstrap centostest --ssh-user klimenta --sudo -N centostest.andreev.local -r 'role&#x5B;wordpress]'
</pre>
<p>In my home lab it took about 1m to install everything on a 1 CPU, 1GB RAM virtual CentOS. Once completed go to your website (http://centostest.andreev.local in my case). If you have SELinux, you&#8217;ll have to manually create the config as per WordPress instructions, otherwise &#8211; you are all set.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2018/04/P103-02.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2018/04/P103-02.png" alt="" width="754" height="623" class="aligncenter size-full wp-image-8212" /></a> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.andreev.it/2018/04/126-chef-deploy-wordpress-on-centos-7/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>FreeBSD: Install nginx &#8211; virtual hosts, PHP, MySQL and WordPress</title>
		<link>https://blog.andreev.it/2017/01/107-freebsd-install-nginx-virtual-hosts-php-mysql-wordpress/</link>
					<comments>https://blog.andreev.it/2017/01/107-freebsd-install-nginx-virtual-hosts-php-mysql-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[Kliment Andreev]]></dc:creator>
		<pubDate>Sun, 29 Jan 2017 15:40:02 +0000</pubDate>
				<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[freebsd]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[virtual hosts]]></category>
		<guid isPermaLink="false">http://blog.iandreev.com/?p=3030</guid>

					<description><![CDATA[I&#8217;ve decided to play with nginx to see how different is from Apache. The&#8230;]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div><p>I&#8217;ve decided to play with nginx to see how different is from Apache. The best way to experiment is to have an end goal, e.g. a working WordPress site. I will be using FreeBSD 11.0 and for that  I&#8217;ve created a public server in AWS cloud. The hostname for my server is <strong>test.iandreev.com</strong> and I also have 4 different hostnames that point to the same IP (test1, test2, test3 and test4).<br />
<a href="https://blog.andreev.it/wp-content/uploads/2017/01/P085-01.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2017/01/P085-01.png" alt="" width="1068" height="214" class="aligncenter size-full wp-image-7638" srcset="https://blog.andreev.it/wp-content/uploads/2017/01/P085-01.png 1068w, https://blog.andreev.it/wp-content/uploads/2017/01/P085-01-300x60.png 300w, https://blog.andreev.it/wp-content/uploads/2017/01/P085-01-1024x205.png 1024w, https://blog.andreev.it/wp-content/uploads/2017/01/P085-01-768x154.png 768w, https://blog.andreev.it/wp-content/uploads/2017/01/P085-01-585x117.png 585w" sizes="(max-width: 1068px) 100vw, 1068px" /></a></p>
<h1>Installation</h1>
<p>To install nginx, type:</p>
<pre class="brush: bash; title: ; notranslate">
pkg install nginx
</pre>
<p>Make sure it starts at boot by adding <strong>nginx_enable=&#8221;YES&#8221;</strong> in <strong>/etc/rc.conf</strong>.<br />
To see the version, type:</p>
<pre class="brush: bash; highlight: [1]; title: ; notranslate">
nginx -v
nginx version: nginx/1.10.2
</pre>
<p>To see the modules that were installed with the package, type:</p>
<pre class="brush: bash; title: ; notranslate">
nginx -V
</pre>
<p>You can start and stop the service with the standard <strong>service </strong>command. When making changes in the config file, use reload, e.g. <strong>service nginx reload</strong>.<br />
By default, nginx creates the log files under <strong>/var/log/nginx</strong>. There are two files, <strong>access.log</strong> and <strong>error.log</strong>. The config files are under <strong>/usr/local/etc/nginx</strong>. The main config file is <strong>nginx.conf</strong>.<br />
Let&#8217;s start the nginx.</p>
<pre class="brush: bash; highlight: [1]; title: ; notranslate">
service nginx start
Performing sanity check on nginx configuration:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
Starting nginx.
</pre>
<p>If everything is OK, you can <strong>telnet localhost 80</strong>. Type something and hit ENTER and you&#8217;ll see a response. </p>
<pre class="brush: bash; highlight: [1]; title: ; notranslate">
telnet localhost 80
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
asdf
HTTP/1.1 400 Bad Request
Server: nginx/1.10.2
Date: Sun, 29 Jan 2017 13:56:04 GMT
Content-Type: text/html
Content-Length: 173
Connection: close

&lt;html&gt;
&lt;head&gt;&lt;title&gt;400 Bad Request&lt;/title&gt;&lt;/head&gt;
&lt;body bgcolor=&quot;white&quot;&gt;
&lt;center&gt;&lt;h1&gt;400 Bad Request&lt;/h1&gt;&lt;/center&gt;
&lt;hr&gt;&lt;center&gt;nginx/1.10.2&lt;/center&gt;
&lt;/body&gt;
&lt;/html&gt;
Connection closed by foreign host.
</pre>
<p>Check the nginx process.</p>
<pre class="brush: bash; highlight: [1]; title: ; notranslate">
ps -waux | grep nginx
root     778   0.0  0.7 29640 6984  -  Is   13:55    0:00.00 nginx: master process /usr/local/sbin/nginx
www      779   0.0  0.7 29640 7452  -  I    13:55    0:00.00 nginx: worker process (nginx)
</pre>
<p>As you can see the master process runs as root, but then it forks the connections to the www user.</p>
<h1>Single host</h1>
<p>This is the easiest setup. You don&#8217;t have to do anything except the steps above. nginx works right out of the box with the default configuration. Go to http://server_IP_or_hostname and you&#8217;ll see the welcome page.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2017/01/P085-02.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2017/01/P085-02.png" alt="" width="555" height="227" class="aligncenter size-full wp-image-7639" srcset="https://blog.andreev.it/wp-content/uploads/2017/01/P085-02.png 555w, https://blog.andreev.it/wp-content/uploads/2017/01/P085-02-300x123.png 300w" sizes="(max-width: 555px) 100vw, 555px" /></a><br />
But, this scenario has no real use, so we&#8217;ll create two virtual hosts, test1 and test2.</p>
<h1>Virtual hosts</h1>
<p>First, we&#8217;ll create the two directories for the virtual hosts and put some index files there. I use the same root directory as Apache. Make sure that the locations of the virtual hosts are owned by the user <strong>www </strong>and group <strong>www</strong>.</p>
<pre class="brush: bash; title: ; notranslate">
cd /usr/local/www
mkdir test1.iandreev.com
mkdir test2.iandreev.com
echo &quot;test1&quot; &gt; test1.iandreev.com/index.htm
echo &quot;test2&quot; &gt; test2.iandreev.com/index.htm
chown -R www:www test*
</pre>
<p>Now, we have to edit the main config file and tell nginx where to look for these sites.<br />
Go to <strong>/usr/local/etc/nginx/</strong> and edit <strong>nginx.conf</strong>. Change the values for <strong>worker_processes</strong> from 1 to auto and uncomment <strong>gzip on</strong> directive. See what worker_processes mean <a href="http://nginx.org/en/docs/ngx_core_module.html#worker_processes" target="_blank" rel="noopener noreferrer">here</a>. By uncommenting gzip directive, you are enabling compression on the pages. To test if your web server serves compressed pages, check <a href="http://www.whatsmyip.org/http-compression-test/" target="_blank" rel="noopener noreferrer">this </a>website.<br />
Next, we have to add our two virtual hosts. Scroll all the way down, just before the last accolade &#8220;}&#8221; and add these lines.</p>
<pre class="brush: bash; title: ; notranslate">
    server {
        access_log /var/log/nginx/test1.iandreev.access.log;
        error_log  /var/log/nginx/test1.iandreev.error.log;
        listen 80;
        server_name     test1.iandreev.com;
        location / {
            root /usr/local/www/test1.iandreev.com;
            index index.htm index.html;
        }
    }
    server {
        access_log /var/log/nginx/test2.iandreev.access.log;
        error_log  /var/log/nginx/test2.iandreev.error.log;
        listen 80;
        server_name test2.iandreev.com;
        location / {
            root /usr/local/www/test2.iandreev.com;
            index index.htm index.html;
        }
    }
</pre>
<p>Reload the config with:</p>
<pre class="brush: bash; highlight: [1]; title: ; notranslate">
service nginx reload
Performing sanity check on nginx configuration:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
</pre>
<p>and make sure everything is OK.<br />
If everything is OK, you should be able to browse to your virtual sites.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2017/01/P085-03.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2017/01/P085-03.png" alt="" width="298" height="166" class="aligncenter size-full wp-image-7640" /></a><br />
<a href="https://blog.andreev.it/wp-content/uploads/2017/01/P085-04.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2017/01/P085-04.png" alt="" width="289" height="226" class="aligncenter size-full wp-image-7641" /></a></p>
<p>If you check one of the error logs, you&#8217;ll see an error that favicon.ico is missing for the site. You can ignore this as it&#8217;s not an error, it&#8217;s just a warning that you don&#8217;t have a favicon for your site.</p>
<pre class="brush: bash; highlight: [1]; title: ; notranslate">
tail test2.iandreev.error.log
2017/01/29 14:18:59 &#x5B;error] 838#100084: *4 open() &quot;/usr/local/www/test2.iandreev.com/favicon.ico&quot; failed (2: No such file or directory), client: 240.14.17.24, server: test2.iandreev.com, request: &quot;GET /favicon.ico HTTP/1.1&quot;, host: &quot;test2.iandreev.com&quot;
</pre>
<p>You can get a favicon icon from <a href="http://www.freefavicon.com/freefavicons/objects/" target="_blank" rel="noopener noreferrer">this </a>website or you can generate one from <a href="http://www.favicon-generator.org/" target="_blank" rel="noopener noreferrer">this </a>one.</p>
<h1>nginx and PHP</h1>
<p>Unlike Apache and the php module, nginx is using PHP-FPM as a proxy to requests PHP dynamic code over FCGI protocol. PHP-FPM comes bundled with PHP, so let&#8217;s install php 5.6.</p>
<pre class="brush: bash; title: ; notranslate">
pkg install php56
</pre>
<p>Add this line in <strong>/etc/rc.conf</strong> so PHP-FPM starts on boot.</p>
<pre class="brush: bash; title: ; notranslate">
php_fpm_enable=&quot;YES&quot;
</pre>
<p>Create the <strong>php.ini</strong> file from <strong>php.ini-production</strong>.</p>
<pre class="brush: bash; title: ; notranslate">
cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini
</pre>
<p>Now, edit <strong>/usr/local/etc/php-fpm.conf</strong> and make these changes. Replace <strong>listen = 127.0.0.1:9000</strong> with <strong>listen = /var/run/php-fpm.sock</strong>. In addition, uncomment these three lines.</p>
<pre class="brush: bash; title: ; notranslate">
listen.owner = www
listen.group = www
listen.mode = 0660
</pre>
<p>Finally, start the php-fpm service.</p>
<pre class="brush: bash; highlight: [1]; title: ; notranslate">
service php-fpm start
Performing sanity check on php-fpm configuration:
&#x5B;28-Jan-2017 23:41:31] NOTICE: configuration file /usr/local/etc/php-fpm.conf test is successful
</pre>
<p>Let&#8217;s create a test website that will serve PHP content.</p>
<pre class="brush: bash; title: ; notranslate">
cd /usr/local/www
mkdir test3.iandreev.com
echo &quot;&lt;?php phpinfo(); ?&gt;&quot; &gt; test3.iandreev.com/index.php
chown -R www:www test3.iandreev.com
</pre>
<p>Add a new virtual host in nginx.</p>
<pre class="brush: bash; title: ; notranslate">
server {
        access_log /var/log/nginx/test3.iandreev.access.log;
        error_log  /var/log/nginx/test3.iandreev.error.log;
        listen       80;
        server_name  test3.iandreev.com;
        root /usr/local/www/test3.iandreev.com;
        index index.php index.html index.htm;
        location / {
            try_files $uri $uri/ =404;
        }
        error_page      500 502 503 504  /50x.html;
        location = /50x.html {
            root /usr/local/www/nginx-dist;
        }
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $request_filename;
                include fastcgi_params;
        }
    }
</pre>
<p>and reload the config changes.</p>
<pre class="brush: bash; title: ; notranslate">
service nginx reload
</pre>
<p>Go to your new virtual host, in my case http://test3.iandreev.com and you should see this.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2017/01/P085-05.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2017/01/P085-05.png" alt="" width="1204" height="514" class="aligncenter size-full wp-image-7642" srcset="https://blog.andreev.it/wp-content/uploads/2017/01/P085-05.png 1204w, https://blog.andreev.it/wp-content/uploads/2017/01/P085-05-300x128.png 300w, https://blog.andreev.it/wp-content/uploads/2017/01/P085-05-1024x437.png 1024w, https://blog.andreev.it/wp-content/uploads/2017/01/P085-05-768x328.png 768w, https://blog.andreev.it/wp-content/uploads/2017/01/P085-05-1170x499.png 1170w, https://blog.andreev.it/wp-content/uploads/2017/01/P085-05-585x250.png 585w" sizes="(max-width: 1204px) 100vw, 1204px" /></a></p>
<h1>nginx and WordPress</h1>
<p>Now that we have PHP support we can create a WordPress site. We&#8217;ll use MySQL as a DB backend. Please see my other <a href="https://blog.andreev.it/?p=1309#MySQL" target="_blank" rel="noopener noreferrer">post </a>on how to install MySQL first.<br />
Once you have the MySQL installed, create the database. Replace the values of <strong>wordpress</strong>, <strong>wpuser </strong>and <strong>secret </strong>to suit your needs.</p>
<pre class="brush: sql; title: ; notranslate">
CREATE DATABASE wordpress;
GRANT ALL PRIVILEGES ON wordpress.* TO &quot;wpuser&quot;@&quot;localhost&quot; IDENTIFIED BY &quot;secret&quot;;
FLUSH PRIVILEGES;
QUIT;
</pre>
<p>Install the following php modules, otherwise when you start WordPress you&#8217;ll be presented with a blank page.</p>
<pre class="brush: bash; title: ; notranslate">
pkg install php56-extensions php56-mysql php56-mysqli php56-xml php56-hash php56-gd php56-curl php56-tokenizer php56-zlib php56-zip
</pre>
<p>Download the latest WordPress install. If you don&#8217;t have wget, install it first with <strong>pkg install wget</strong>.</p>
<pre class="brush: bash; title: ; notranslate">
cd /usr/local/www
wget www.wordpress.org/latest.zip --no-check-certificate
unzip latest.zip
mv wordpress test4.iandreev.com
chown -R www:www test4.iandreev.com
rm latest.zip
</pre>
<p>Add the following in nginx.conf to create the virtual host for the WordPress site.</p>
<pre class="brush: bash; title: ; notranslate">
server {
        access_log /var/log/nginx/test4.iandreev.access.log;
        error_log  /var/log/nginx/test4.iandreev.error.log;
        listen       80;
        server_name  test4.iandreev.com;
        root /usr/local/www/test4.iandreev.com;
        index index.php index.html index.htm;
        location / {
            try_files $uri $uri/ =404;
        }
        error_page      500 502 503 504  /50x.html;
        location = /50x.html {
            root /usr/local/www/nginx-dist;
        }
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $request_filename;
                include fastcgi_params;
        }
    }
</pre>
<p>Reload the config and restart php-fpm service.</p>
<pre class="brush: bash; title: ; notranslate">
service nginx reload
service php-fpm restart
</pre>
<p>Go to your website and you&#8217;ll be presented with the WordPress install page.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2017/01/P085-06.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2017/01/P085-06.png" alt="" width="574" height="823" class="aligncenter size-full wp-image-7643" srcset="https://blog.andreev.it/wp-content/uploads/2017/01/P085-06.png 574w, https://blog.andreev.it/wp-content/uploads/2017/01/P085-06-209x300.png 209w" sizes="(max-width: 574px) 100vw, 574px" /></a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.andreev.it/2017/01/107-freebsd-install-nginx-virtual-hosts-php-mysql-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>WordPress: Execute custom code in a post without plugins</title>
		<link>https://blog.andreev.it/2016/09/96-wordpress-execute-custom-code-in-a-post-without-plugins/</link>
					<comments>https://blog.andreev.it/2016/09/96-wordpress-execute-custom-code-in-a-post-without-plugins/#respond</comments>
		
		<dc:creator><![CDATA[Kliment Andreev]]></dc:creator>
		<pubDate>Thu, 15 Sep 2016 19:50:51 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[execute command]]></category>
		<guid isPermaLink="false">http://blog.iandreev.com/?p=2763</guid>

					<description><![CDATA[I wanted to run a custom code from a WordPress post and I was&#8230;]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div><p>I wanted to run a custom code from a WordPress post and I was looking around. I&#8217;ve found a nice plugin but it was running PHP only. It&#8217;s not that I needed more, but I stumbled when I tried to combine HTML elements and the PHP script with this plugin. So, at the end I&#8217;ve found a much more elegant solution, that pretty much runs any code. All I had to do is to embed the HTML page as an object.</p>
<p>So, let&#8217;s say I have a custom code in a PHP page called test.php that&#8217;s in the root of my WordPress installation. All is needed is this code in WordPress (use the Text tab, not Visual).</p>
<pre class="brush: xml; title: ; notranslate">
&lt;object data=&quot;https://blog.andreev.it/test.php&quot; width=&quot;800&quot; height=&quot;600&quot;&gt;&lt;/object&gt;
</pre>
<p><a href="https://blog.andreev.it/wp-content/uploads/2016/09/P075-01.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2016/09/P075-01.jpg" alt="" width="775" height="199" class="aligncenter size-full wp-image-7567" srcset="https://blog.andreev.it/wp-content/uploads/2016/09/P075-01.jpg 775w, https://blog.andreev.it/wp-content/uploads/2016/09/P075-01-300x77.jpg 300w, https://blog.andreev.it/wp-content/uploads/2016/09/P075-01-768x197.jpg 768w, https://blog.andreev.it/wp-content/uploads/2016/09/P075-01-585x150.jpg 585w" sizes="(max-width: 775px) 100vw, 775px" /></a><br />
And this is how my <strong>test.php</strong> page looks like. I won&#8217;t comment the code, but it has an input label and a button. Type a hostname and it will ping it and then render the output as an HTML array. </p>
<div style="border:1px solid red; padding:16px;">
<p style="text-align:center;"><strong><span style="color:#800000;">NOTE</span> </strong></p>
<p style="text-align:center;">If you are executing code that needs root access, this solution won&#8217;t work, because the code runs under the Apache username (which normally is not root).
</p>
</div>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE HTML&gt;
&lt;html&gt;
&lt;head&gt;
&lt;style&gt;
.error {color: #FF0000;}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;?php
// define variables and set to empty values
$hostErr = &quot;&quot;;
$host = &quot;&quot;;

if ($_SERVER&#x5B;&quot;REQUEST_METHOD&quot;] == &quot;POST&quot;) {
  if (empty($_POST&#x5B;&quot;host&quot;])) {
    $host = &quot;Host is required&quot;;
  } else {
    $host = test_input($_POST&#x5B;&quot;host&quot;]);
    // only letters and numbers are allowed
    if (!preg_match(&quot;/^&#x5B;a-zA-Z0-9.]*$/&quot;,$host)) {
      $hostErr = &quot;Only letters and numbers allowed&quot;;
    }
  }
}

function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}
?&gt;

&lt;h2&gt;Online ping (ICMP) probe&lt;/h2&gt;
&lt;p&gt;&lt;span class=&quot;error&quot;&gt;* required field.&lt;/span&gt;&lt;/p&gt;
&lt;form method=&quot;post&quot; action=&quot;&lt;?php echo htmlspecialchars($_SERVER&#x5B;&quot;PHP_SELF&quot;]);?&gt;
&quot;&gt;
  Host: &lt;input type=&quot;text&quot; name=&quot;host&quot; value=&quot;&lt;?php echo $host;?&gt;&quot;&gt;
  &lt;span class=&quot;error&quot;&gt;* &lt;?php echo $hostErr;?&gt;&lt;/span&gt;
  &lt;br&gt;&lt;br&gt;
  &lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Submit&quot;&gt;
&lt;/form&gt;

&lt;?php
        if(isset($_POST&#x5B;'submit']))
        {
                echo &quot;&lt;h2&gt;Output:&lt;/h2&gt;&quot;;
                echo $host;
                echo &quot;&lt;br&gt;&quot;;
                exec(&quot;ping -c 3 $host&quot;, $output, $status);
                echo '&lt;pre&gt;';
                print_r($output);
                echo '&lt;pre&gt;';

        }
?&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>The code in action. Type some host on the internet (e.g www.whatever.com), click the button and see the result. </p>
<p><object data="https://blog.andreev.it/ping.php" width="800" height="600"></object></p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.andreev.it/2016/09/96-wordpress-execute-custom-code-in-a-post-without-plugins/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>WordPress: Migrating WordPress site from one server to another</title>
		<link>https://blog.andreev.it/2014/11/migrating-wordpress-site-from-one-server-to-another/</link>
					<comments>https://blog.andreev.it/2014/11/migrating-wordpress-site-from-one-server-to-another/#respond</comments>
		
		<dc:creator><![CDATA[Kliment Andreev]]></dc:creator>
		<pubDate>Wed, 05 Nov 2014 15:10:29 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<guid isPermaLink="false">http://blog.iandreev.com/?p=1591</guid>

					<description><![CDATA[First, make sure that you have Apache, PHP and MySQL (MariaDB) installed and properly&#8230;]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div><p>First, make sure that you have Apache, PHP and MySQL (MariaDB) installed and properly configured. In order to avoid any problems down the road, make sure that you have the same version of the software. There are some WordPress plugins that allow you to backup/restore the database and the content, but we&#8217;ll do this manually.  </p>
<p>Let&#8217;s say that I want to migrate <strong>www.iandreev.com</strong> from one server to another. First, change the DNS so the hostname points to the new IP. Create a test HTML file and see that you can actually browse to the new web site. Once completed, stop the Apache web server and MySQL database on the old server. Go to the root folder where your WordPress installation is and open the <strong>wp-config.php</strong> file. These are the values that you will need.  </p>
<pre class="brush: sql; title: ; notranslate"> 
/** The name of the database for WordPress */ 
define('DB_NAME', 'wwwiandreevcom'); 
/** MySQL database username */ 
define('DB_USER', 'username); 
/** MySQL database password */ 
define('DB_PASSWORD', 'password'); 
/** MySQL hostname */ 
define('DB_HOST', 'localhost'); 
</pre>
<p>Backup this database with: </p>
<pre class="brush: bash; title: ; notranslate">
mysqldump -u &lt;username&gt;  -p &lt;password&gt; databasename &gt; /somewhere/dbname.sql 
</pre>
<p><em>Note: Don&#8217;t leave a space between &#8220;-p&#8221; and the password. </em></p>
<p>Once you have the database backed up, transfer it to the new server using <strong>scp</strong> or whatever you use to transfer files between servers. In my case I typed this command on the old server. </p>
<pre class="brush: bash; title: ; notranslate">
scp wwwiandreevcom.sql myusername@www.iandreev.com: 
</pre>
<p>Where <strong>wwwiandreevcom.sql</strong> is the backup file, <strong>myusername</strong> is the username that I use on both servers and <strong>www.iandreev.com</strong> is the new server hostname. </p>
<p>Create the database on the new server and grant necessary rights. </p>
<pre class="brush: sql; title: ; notranslate">
create database wwwiandreevcom; 
grant all privileges on wwwiandreevcom.* to &quot;username&quot;@&quot;localhost&quot; identified by &quot;password&quot;; 
flush privileges; 
</pre>
<p>Make sure that the database name, username, password and host are the same as on the old server.<br />
Now, restore the database. </p>
<pre class="brush: sql; title: ; notranslate">
mysql -u username -p wwwiandreevcom &lt; wwwiandreevcom.sql 
</pre>
<p>Where <strong>wwwiandreevcom</strong> is the database being restored and <strong>wwwiandreevcom.sql</strong> is the dump file of the database that we transferred from the old server.  </p>
<p>There is no need to install WordPress from scratch on the new server, so go back to the old server and compress the WordPress installation folder.  </p>
<pre class="brush: bash; title: ; notranslate">
tar czvf zipfile.tgz www.iandreev.com 
</pre>
<p>Where <strong>www.iandreev.com</strong> is my WordPress installation directory. Transfer the tarball to the new server. </p>
<pre class="brush: bash; title: ; notranslate">
scp zipfile.tgz myusername@www.iandreev.com: 
</pre>
<p>Move the file where your new installation will be and unpack it.  </p>
<pre class="brush: bash; title: ; notranslate">
tar xvf zipfile.tgz 
</pre>
<p>Make sure to change the owner to the user that runs Apache if needed. In my case I had to do: </p>
<pre class="brush: bash; title: ; notranslate">
chown -R www:www www.iandreev.com 
</pre>
<p>That&#8217;s it. Go to www.whatever.com and you&#8217;ll see your website/blog back in action.<br />
<strong>Note: If you receive the following error:</strong></p>
<pre class="brush: bash; title: ; notranslate">
Your PHP installation appears to be missing the MySQL extension which is required by WordPress.
</pre>
<p>Then install the following Apache modules and restart Apache.</p>
<pre class="brush: bash; title: ; notranslate">
pkg install php5-pdo_mysql
apachectl graceful
</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.andreev.it/2014/11/migrating-wordpress-site-from-one-server-to-another/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
