9

I am trying to install Wordpress on Lubuntu. I followed the instructions here. Including PHP Apache and MySQL setups. Apache and MySQL appear to be running fine.

However, when I go to http://localhost/blog/, I get the following error:

Neither /etc/wordpress/config-localhost.php nor /etc/wordpress/config-localhost.php could be found. Ensure one of them exists, is readable by the webserver and contains the right password/username.

0

1 Answer 1

12

I have played that guide step by step. And I think in your case something went wrong and the file /etc/wordpress/config-localhost.php is actually missing. But this isn't the worst thing. The manual is missing a step that describes how to create a MySQL database and user for WordPress - the final result. How to do that, under consideration scenario, is described in the article WordPress from the Official Ubuntu Documentation. Another approach is shown under the step 1 below.

However, in my opinion, the approach described in the aforementioned manuals makes the things more complicated than they actually are. Additionally, neither manual provides enough explanations to understand what is happening. Here's a guide for you:

How to install the latest WordPress on Ubuntu with LAMP

I'm updating this short manual time to time, so - the steps listed below are tested within Ubuntu 16.04, 20.04, 22.04 with the native installation of MySQL and/or MariaDB.


Pre-Requirements

The standard Ubuntu LAMP stack, that means we have working Apache2, MySQL, PHP. Refs:

Along with those additional PHP extensions, mod_rewrite for Apache2 must also be enabled:

sudo apt update
sudo apt install libapache2-mod-php
sudo apt install php-curl php-gd php-mbstring php-xml php-xmlrpc #php-mcrypt
sudo a2enmod rewrite php7.x

1. Create MySQL/MariaDB Database

The steps are:

  • Login to the MySQL server from a terminal.
  • Create Database.
  • Create User.
  • Grant all privileges on the Database to the User.
  • Reload the privileges from the grant tables in the mysql database.
  • Exit MySQL.

The commands are:

# for MySQL 5 Ubuntu 16.04
$ mysql -u'root' -p  

mysql> CREATE DATABASE DataBaseName;
mysql> CREATE USER 'DataBaseUser'@'localhost' identified by 'DataBaseUserPassword';
mysql> GRANT ALL PRIVILEGES ON DataBaseName.* TO 'DataBaseUser'@'localhost';
mysql> FLUSH PRIVILEGES;
mysql> exit

# for MySQL 8 Ubuntu 20.04/22.04
$ sudo mysql  

mysql> CREATE DATABASE DataBaseName;
mysql> CREATE USER 'DataBaseUser'@'localhost' IDENTIFIED WITH mysql_native_password BY 'DataBaseUserPassword';
mysql> GRANT ALL PRIVILEGES ON DataBaseName.* TO 'DataBaseUser'@'localhost' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
mysql> exit

# for MariaDB 10 Ubuntu 22.04
$ sudo mysql 

MariaDB> CREATE DATABASE DataBaseName;
MariaDB> CREATE USER 'DataBaseUser'@'localhost' IDENTIFIED BY 'DataBaseUserPassword';
MariaDB> GRANT ALL PRIVILEGES ON DataBaseName.* TO 'DataBaseUser'@'localhost' WITH GRANT OPTION;
MariaDB> FLUSH PRIVILEGES;
MariaDB> exit

  • Where DatabaseName, DatabaseUser and DatabaseUserPassword are subject of your decision.

    According to the example the User will be allowed to access the Database only from the localhost, this is enough (and safe) when Apache and MySQL servers are allocated to the same 'physical' machine.

  • Don't miss the semicolon (;) at the end of each sentence. If you are on Ubuntu 18.04+, where the socket authentication is the default authentication method for MySQL, use sudo mysql to login as root.


2.A. Download the latest WordPress release

The steps are:

  • Go to the directory where WordPress will be stored.

    The directory used here is /var/www - this is the default directory where the web content should be stored in current Ubuntu versions.

  • Download the latest release.

  • 'UnZip' and 'UnTar' the package, then remove it.

  • Rename the folder. This step is not mandatory.

    I usually use the same name for the installation directory, the name of the data base and the name of the virtual host config file. Also these names are based on the Domain Name if there is dedicated one.

  • Create upload directory.

  • Create empty .htaccess file.

    WordPress will write some rewrite rules inside, depending on your preferences. For this purpose, this file must be writable (or owned) by www-data, also mod_rewrite must be enabled and the usage of the .htaccess file must be allowed by the virtual host configuration - the directive AllowOverride All.

  • Change the WordPress directory ownership.

    WordPress has mechanisms for auto update and automatic installation of plugins, and I found that playing with permissions and ownership here is complicated task. In most manuals, the owner of WordPress's content is suggested as www-data.

The commands are:

cd /var/www/

sudo wget https://wordpress.org/latest.tar.gz
sudo tar xvfz latest.tar.gz && sudo rm ./latest.tar.gz*
sudo mv wordpress wordpress-custom-folder
sudo mkdir -p /var/www/wordpress-custom-folder/wp-content/uploads
sudo touch /var/www/wordpress-custom-folder/.htaccess

sudo chown -R www-data:www-data /var/www/wordpress-custom-folder

2.B. Install WordPress from Ubuntu repositories

Another way to install WordPress is through Ubuntu repositories, like it is described here and here. But (in Ubuntu 16.04) the command apt show wordpress shows that the version into the repo is 4.4.2 while the current version is 4.8.1. Because WP has an mechanism for automatic update, it will force you to update this outdated version to the latest one. So you will end up with 4.8, but after few steps of updates where something could go wrong.

The main advantage in this approach is that the installation process of WordPress will include some dependencies, as these, mentioned at the top of this post.


3.A. Setup Apache2: Create Virtual Host, dedicated to the particular WordPress

  • Follow this section if there is dedicated domain or sub-domain name and the WordPress site will be accessible via URL as: http://my-domain.com or http://someprefix.my-domain.com.

  • If you don't intend to run other sites in the near future, just edit 000-default.conf instead of new Virtual Host creation.

  • If you don't have an registered domain name, but you want to access your WP site via domain name instead of IP address (or localhost), you can add the following line somewhere within the /etc/hosts file (more details are provided in this answer):

      127.0.0.1    my-domain.com someprefix.my-domain.com
    

Create and edit a new Virtual Host configuration file:

sudo nano /etc/apache2/sites-available/wordpress.conf
  • The first part of the name of the configuration file - wordpress. - is subject to your decision.

The content of the file should look as this:

<VirtualHost *:80>

    ServerName someprefix.my-domain.com
    ServerAlias my-domain.com 
    
    # If this is the default configuration file we can use: 'ServerName localhost' or also 'ServerAlias localhost'.

    ServerAdmin [email protected]

    ErrorLog ${APACHE_LOG_DIR}/someprefix.my-domain.com.error.log
    CustomLog ${APACHE_LOG_DIR}/someprefix.my-domain.com.access.log combined

    DocumentRoot /var/www/wordpress-custom-folder
    
    <Directory /var/www/wordpress-custom-folder>
        Options None FollowSymLinks
        # Enable .htaccess Overrides:
        AllowOverride All
        DirectoryIndex index.php
        Order allow,deny
        Allow from all
        Require all granted
    </Directory>

    <Directory /var/www/wordpress-custom-folder/wp-content>
        Options FollowSymLinks
        Order allow,deny
        Allow from all
    </Directory>

</VirtualHost>
  • Copy the above content and use in nano: Shift+Insert for paste; Ctrl+O and Enter for save; Ctrl+X for exit.

Enable the configuration and restart Apache2:

sudo a2ensite wordpress.conf
sudo systemctl restart apache2.service

3.B. Setup Apache2: Append WordPress to an existing Virtual Host

  • Follow this section if there is not a dedicated domain or sub-domain name and the WP site will be accessible via URL as: http://my-domain.com/my-blog or http://localhost/my-blog, etc.

  • Within the two mentioned manuals (this and this) WP is appended to all enabled Virtual Hosts.

Edit the existing Virtual Host configuration file in this way:

<VirtualHost ...>
.....

    Alias /my-blog /var/www/wordpress-custom-folder

    <Directory /var/www/wordpress-custom-folder>
        Options None FollowSymLinks
        # Enable .htaccess Overrides:
        AllowOverride All
        DirectoryIndex index.php
        Order allow,deny
        Allow from all
        Require all granted
    </Directory>

    <Directory /var/www/wordpress-custom-folder/wp-content>
        Options FollowSymLinks
        Order allow,deny
        Allow from all
    </Directory>

</VirtualHost>
  • Explanation about the directive Alias. Let's assume that DocumentRoot is /var/www/html. In this case, the directive Alias /my-blog /var/www/wordpress-custom-folder will serve as this symbolic link:

       ln -s /var/www/wordpress-custom-folder /var/www/html/my-blog
    

Enable the configuration (if it is not enabled) and restart Apache2:

sudo a2ensite 000-default.conf         # or type the name of your configuration file
sudo systemctl restart apache2.service

4. Proceed to the web installation of WordPress

Go to the URL http://someprefix.my-domain.com or http://localhost/my-blog/ in your web browser. The WordPress installer will show up. The data about MySQL data base, created in step 1, must be provided there.

That's it.


Setup another instance

To run another instance of WP, just do the steps one more time and use unique data according to the new instance:

  • Create new Database. You can create and new MySQL User.

  • Download WP in new directory within /var/www.

  • Create new Virtual Host if you using approach 3.A, or, if you using 3.B, setup new Alias path and new <Directory> definitions.

  • Proceed to the web installation of the new WP.


References


Further Reading

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .