How Can We Help?
Move Existing WordPress Site to Existing Apache2 Server (Ubuntu 20.04.4)
Create a MySQL database for WordPress via Command Line
- Connect to the MySQL engine using the command (sudo) mysql –u root –p. Once you specify the password you will be connected to the MySQL database and prompted with mysql> prompt.
- To create a database use the CREATE DATABASE command. E.g. if you would like to create the database T3stdb123 enter the following:
CREATE DATABASE T3stdb123; |
- Once the database is created, use the command GRANT ALL PRIVILEGES to create a new user with ALL privileges. If the database name is t3stdb123, the new user is newdbuser and the user’s passwords is !Pi4aX_7z? then the command should be;
GRANT ALL PRIVILEGES ON t3stdb123.* TO 'newdbuser'@'localhost' IDENTIFIED BY '!Pi4aX_7z?'; |
NOTE: Depending on the MySQL version the command above will fail. If that occurs, first create the user and then add it to the database as follows:
CREATE USER 'newdbuser'@'localhost' IDENTIFIED BY '!Pi4aX_7z?'; |
GRANT ALL PRIVILEGES ON t3stdb123.* TO 'newdbuser'@'localhost'; |
- Once the new user has been created and privileges have been assigned to it, run the command FLUSH PRIVILEGES; to flush the old privileges and start using the new assigned ones.
Recommended WordPress Database Permissions
For typical WordPress operation, the MySQL database user only needs SELECT, INSERT and UPDATE data privileges. It is recommended to use the minimum possible privileges when running WordPress. Any other privileges, such as ALTER, CREATE and DROP are sometimes needed during an upgrade or when installing some plugins which need access to change the database structure. In such case you will be advised to do such changes by the plugin developer. Whenever you assign structure related privileges do it ONLY for a temporary period. You can read more about WordPress database privileges from this article: Why minimum MySQL user WordPress database privileges help.
Create a Directory Structure for the WordPress Site
Create a document root directory:
mkdir /var/www/html/site.example.com
Change the ownership of the directory to www-data:
chown -R www-data:www-data /var/www/html/site.example.com
Create a Virtual Host Configuration File:
nano /etc/apache2/sites-available/site.example.com.conf
Add the following lines:
<VirtualHost *:80> ServerAdmin admin@site.example.com ServerName site.example.com DocumentRoot /var/www/html/site.example.com DirectoryIndex index.html ErrorLog ${APACHE_LOG_DIR}/site.example.com_error.log CustomLog ${APACHE_LOG_DIR}/site.example.com_access.log combined </VirtualHost>
Save and close the file. Then, enable the virtual host configuration file with the following commands:
a2ensite site.example.com
Copy the existing WordPress site to the new directory.
Restart the Apache webserver to apply the configuration changes:
systemctl restart apache2