sudo apt update
wget https://wordpress.org/latest.zip
sudo apt install unzip
sudo mkdir -p /var/www/html/
sudo unzip latest.zip -d /var/www/html/
# not mandatory
sudo mv /var/www/html/wordpress /var/www/html/example.com
# to access mariadb shell (or sudo mysql -u root)
sudo mariadb -u root -p
# list all databases
show databases;
# create a database for WordPress
create database wordpress;
# create a database user for WordPress
This command also grants all privileges of WordPress database to the user.
Replace wpuser and your-password with your preferred username and password.
grant all privileges on wordpress.* to wpuser@localhost identified by 'your-password';
# Flush the privileges table for the changes to take effect and then exit out of MariaDB shell
flush privileges;
exit;
# Go to your WordPress directory
cd /var/www/html/example.com/
# Copy the sample configuration file and rename it to wp-config.php
sudo cp wp-config-sample.php wp-config.php
# Now edit the new config file with a command-line text editor like Nano
sudo nano wp-config.php
# Find the following lines and replace the blue texts with the
database name,
username ,
password
you created in the previous step
/** The name of the database for WordPress */
define('DB_NAME', 'database_name_here');
/** MySQL database username */
define('DB_USER', 'username_here');
/** MySQL database password */
define('DB_PASSWORD', 'password_here');
# Save and close the file.
To save the file in Nano text editor, press Ctrl+O, then press Enter to confirm.
Next, press Ctrl+X to exit.
We also need to set the Apache user (www-data) as the
owner of the WordPress site directory using the following command
sudo chown www-data:www-data /var/www/example.com/ -R
# Run the following command to create a virtual host file for your WordPress site in the /etc/apache2/sites-available/ directory.
sudo nano /etc/apache2/sites-available/example.com.conf
# Put the following texts into the file.
Replace the blue texts with your own domain name
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
DocumentRoot /var/www/example.com
#This enables .htaccess file, which is needed for WordPress Permalink to work.
<Directory "/var/www/example.com">
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/example.com.error.log
CustomLog ${APACHE_LOG_DIR}/example.com.access.log combined
</VirtualHost>
# Save and close the file. Then test configurations.
sudo apache2ctl configtest
# If you see “Syntax OK”, then enable this virtual host.
sudo a2ensite example.com.conf
# And reload Apache for the changes to take effect
sudo systemctl reload apache2
# open browser and type : example.com
The following code, inserted in your wp-config.php file, will log all errors, notices, and warnings to a file called debug.log in the wp-content directory. It will also hide the errors so they do not interrupt page generation.
# Edit wp-config file.
sudo nano /var/www/html/wordpress/wp-config.php
// Enable WP_DEBUG mode
define( 'WP_DEBUG', true );
// Enable Debug logging to the /wp-content/debug.log file
define( 'WP_DEBUG_LOG', true );
// Disable display of errors and warnings
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );
// Use dev versions of core JS and CSS files (only needed if you are modifying these core files)
define( 'SCRIPT_DEBUG', true );