Install WordPress on Linux (Debian/CentOS)

How to Install WordPress on Linux

1. Ensure You Have a LAMP Stack Configured (Linux, Apache MySQL, PHP)
2. Download & Extract WordPress
3. Create a new database for WordPress
4. Give WordPress Proper Permissions
5. Install WordPress

1. Ensure You Have a LAMP Stack Configured (Linux, Apache, MySQL, PHP)

If you aren’t sure if you have Apache, MySQL, and PHP on your system, verifying this is pretty easy.

Apache

Debian

$ which apache2

CentOS/Fedora/SUSE

$ which httpd

You should get the directory that contains the Apache executable:

$ /usr/sbin/apache2

or

$ /usr/sbin/httpd
If nothing is printed to the terminal, this means that Apache is not installed.

Follow this guide to get a LAMP stack set up on your computer.

2. Download & Extract WordPress

Once you have verified that your LAMP stack is configured and working properly, you can proceed to download WordPress.

$ cd /var/www/html
$ sudo wget https://wordpress.org/latest.tar.gz
$ sudo tar -xf latest.tar.gz

3. Create a New MySQL User & Database for WordPress

Log in to MySQL with the root user, using the password you set in your MySQL install.

(If you have forgotten it, follow this guide.)

$ mysql -u root -p
mysql> CREATE DATABASE newdatabase;
mysql> CREATE USER 'newuser' IDENTIFIED BY 'newpassword';
mysql> GRANT ALL PRIVILEGES ON newdatabase.* to 'newuser';
mysql> FLUSH PRIVILEGES;
mysql> quit

You should create your own user name, and set a secure password, especially if this is not a local install.

4. Give WordPress Proper Permissions

In order for WordPress to run the installation (and to later upload content), you must give Apache write permissions to the directory WordPress is in.

Debian/Ubuntu

$ cd /var/www/html
$ sudo chown -R www-data:www-data wordpress/

CentOS

$ cd /var/www/html
$ sudo chown -R apache:apache wordpress/

If you saved wordpress in a different directory, be sure to use that name instead in the above commands.

5. Install WordPress

Navigate to http://localhost/wordpress.

Enter the Database Name, User, and Password that you configured earlier.

install wordpress linux

If all went well, you will see a page with a button that says “Run the Install”.

install wordpress linux

If you get an error that reads “Cannot Connect to the Database”:
1) You have either entered the wrong information for the database & user, or
2) That user doesn’t have privileges to the database.

In that case, go back to Step 3 and check that you have followed the steps correctly.

If you get a page reading that WordPress is unable to create the wp-config.php file, this means WordPress does not have write permissions to the directory.

Ensure you have completed Step 4 above.

It should be noted that in some VPS setups, the public html folder is not /var/www/html, but /home/[USERNAME]/public_html/.

In this case, the owner and group should be set to the owner of this directory.

Using chmod and chown Commands

If everything was completed successfully, you will see the following page:

install wordpress five minute

You can now set the Site Title, WordPress Username & Password.

You’re done! If all of the steps have been followed, you should now have WordPress configured on your server.

If you do encounter any errors not covered here, as always, Google that shit!

I have been tinkering with Linux and coding for many years. It is extremely rare that I run into a problem I can’t find an answer to.

It can be frustrating at times, but if you dig deep enough, you can always solve the problem.

(And learn something new at the same time! Yay!)

Thanks for reading!

/kimberly

Syntax Highlighting by EnlighterJS

About the Author

Kimberly is a software engineer, and currently works as a Test Engineering Intern for Mozilla.

While she always enjoys learning new technologies, her current focus is python, and when she has free time (she doesn't), Angular & Node.

When not coding, Kimberly spends time with her three young boys in Durango, CO.