Installing and Configuring WordPress in Ubuntu

In more detail, I will describe the steps of installing WordPress manually in Ubuntu / Debian.

Install the necessary components:

sudo apt-get update
sudo apt-get install php php-gd php-bcmath php-imagick libssh2-php apache2 unzip mysql-server mysql-client

Next, you need to create a database, the user and give him full rights to this database, here is an example of how to do this using mysql-client.
Connect to mysql:

mysql -u root -p

Create a database:

CREATE DATABASE database_name;

Create user:

CREATE USER username@localhost IDENTIFIED BY 'password';

We will give him full privileges on the created database:

GRANT ALL PRIVILEGES ON database_name.* TO username@localhost;
FLUSH PRIVILEGES;

Let’s exit mysql:

exit

Let’s move to the home directory of the current Ubuntu user:

cd ~

We type wget and a link to the archive with the latest version of WordPress so that it can be downloaded, for example:

wget https://wordpress.org/latest.tar.gz

Unpack the downloaded archive:

tar xzvf latest.tar.gz

Let’s move to the directory where the archive was unpacked:

cd ~/wordpress

Make a copy of the configuration file:

cp wp-config-sample.php wp-config.php

Open the configuration file in any editor, for example nano (in the editor Ctrl+O and Enter to save the changes, Ctrl+X to exit):

nano wp-config.php

In the configuration file, change the parameters for connecting to the database:

define('DB_NAME', 'database_name');
define('DB_USER', 'username');
define('DB_PASSWORD', 'password');
define('DB_HOST', 'localhost');

Move the WordPress files to the directory where the site files will be stored:

sudo mv ~/wordpress/ /var/www/sitename

Let’s go into it:

cd /var/www/sitename/

Create a directory for user uploads if it does not exist:

mkdir wp-content/uploads

We indicate the group and the owner of the files:

sudo chown -R www-data:www-data /var/www/sitename/

Create a site configuration file using the nano editor:

sudo nano /etc/apache2/sites-available/sitename.conf

We indicate the contents:

<VirtualHost *:80>
ServerName sitename.com
ServerAlias www.sitename.com
DocumentRoot /var/www/sitename/
<Directory /var/www/sitename/>
AllowOverride All
Order Deny,Allow
Allow from all
</Directory>
ErrorLog /var/log/apache2/sitename_error.log
LogLevel warn
CustomLog /var/log/apache2/sitename_access.log combined
</VirtualHost>

Activate the site:

sudo a2ensite sitename

For the changes to take effect, restart the apache2 web server:

sudo /etc/init.d/apache2 reload

The final step is to install WordPress through the browser, by opening the link and following the instructions:
http://sitename.com/wp-admin/install.php

See also my article:
Installing WordPress and Nginx

Leave a comment

Leave a Reply