- Step by Step Instructions
- Put wordpress files at a proper web folder
- Configure Apache2
- Setup a wordpress database in MySQL
- Create and change wordpress config file so it can connect to its database in MySQL
- Change files’ owner and permissions so we can change wordpress from its online admin panel
- Install WordPress
Step by Step Instructions
sudo mkdir /var/www/wordpress
- Move zip file into
sudo cp 000-default.conf wordpress.conf
wordpress.confso apache2 knows to forward any request or your domain to the wordpress app folder.
sudo a2ensite wordpress.conf
sudo service apache2 restart
- Go to PhpMyAdmin via your browser by
- Create a new user “wordpress” and check to create the corresponding database.
sudo cp wp-config-example.php wp-config.php
- Modify config file to add your MySQL wordpress database information.
sudo chown -R www-data:www-data /var/www/wordpress
sudo chmod -R 755 /var/www/wordpress/
- Open browser and type in your domain. You should see wordpress installation page. Follow the instruction and you are done!
In last tutorial we learned how to setup the LAMP (Linux, Apache2, MySQL, and PHP) stack. Now it’s time to configure them specifically for wordpress and bring it live. The main aspects of configuration are:
- Put wordpress files in a proper web folder.
- Edit and enable Apache2 config file to associate your domain to the wordpress files folder.
- Setup a wordpress database in MySQL.
- Create and change wordpress config file so it can connect to its database in MySQL.
- Change files’ owner and permissions so we can change wordpress from its online admin panel.
- Install wordpress via browser.
Before we proceed and discuss the details, I want to point out that some of the steps above apply to ANY web application setup:
- Steps #1,2,5 are generic for any web applications and for other web server besides Apache2.
- Steps #3 and #4 are generic for many web applications that use a database, even if it is not using MySQL.
Thus, learning and understanding these steps gives you benefits beyond working with wordpress.
Put wordpress files at a proper web folder
The first step of creating a web application is to put the necessary files in a specific folder, so the web server can find it.
You can get wordpress from its official website:
WordPress download page as of 2016/09/05.
After downloading wordpress you can transfer the zip file from local machine to your server via
scp (secured copy):
#> scp latest.zip your_user_name@your_domain_or_ip:
This will copy the wordpress file
latest.zip to your server’s user home directory.
If you login to the server via command line you can get wordpress directly by:
#> wget https://wordpress.org/latest.zip
Create a web app folder:
Next, create a folder to store wordpress’ extracted files. The conventional place on Linux is
/var/www . Do:
#> sudo mkdir /var/www/wordpress
Then extract wordpress files in that folder. Of course you can use other name for your folder. In linux the command to extract a zip file is
sudo unzip latest.zip
- If linux complained that
unzipcannot be found, install it by
sudo apt-get install unzip
- The files might be contained in a
wordpressfolder (/var/www/wordpress/wordpress). In this case just move the entire files from it into
/var/www/wordpressand remove the folder
In linux many software is configured by editing a configuration file. For Apache2 it is no exception.
Apache2’s config file folder
The default apache2 config file folder is
/etc/apache2 . In general the folder
/etc is where linux stores software’s configuration files.
sites-enabled are of interest for adding new web applications. The process is:
- Add a new site config file in
sites-available. Assume it is called
- Do the command to enable the new site:
sudo a2ensite newsite.conf.You should see now
newsite.confalso appears in the folder
- Do the command to restart apache2 and apply the changes:
sudo service apache2 restart
Add a new site config file in
In the folder
sites-available there is a default config file
000-default.conf. We can generate our wordpress config file by simply copy it:
sudo cp 000-default.conf wordpress.conf
We now have to edit
wordpress.conf so apache2 knows to forward requests to the right web app folder location. Open
wordpress.conf and you should see this:
At the place
ServerAdmin we are going to edit it and change to:
Here are the explanation:
ServerNametells apache2 to forward any HTTP requests that begin with
your-domain.comto the web application.
ServerAdminjust represents you the admin by your email.
DocumentRoottells apache2 where your web app folder is.
Enable new config file
Once the new file is created and edited, the next step is to enable it so the new changes apply to apache2. Simply do this:
#> sudo a2ensite wordpress.conf
#> sudo service apache2 restart
The first one “publishes” the config file so apache2 will take it. The second one is to restart apache2 to make sure it takes into the new config file.
Ensure apache2 can change wordpress (later)
Since wordpress has an admin panel that enables wordpress admins (you) to change wordpress, we must give the wordpress file folder proper ownership and permission to do so.
As we still need to create a wordpress config file for the database, we delay this step later.
Setup a wordpress database in MySQL
Now we configure MySQL so wordpress can (1) have a database to store/retrieve data (2) can access the database. Thanks to MyPhpAdmin it’s very easy to do so for wordpress. The process is:
- Login to MyPhpAdmin.
- Create a new user
wordpresswith associated database
- Write down the created user password.
First log in from the url
your-domain.com/phpmyadmin . You should see the top headers as follows:
Click on the “Users” tab. Then click on “Add User” tab below. The Add User page looks like this:
Input username (eg: wordpress), host as “localhost”, and find a good password (eg: from Norton password generator). Then in below check “Create database with same name and grant all privileges”. All these will:
- Create a database called “wordpress”.
- Create a user called “wordpress”.
- The user can read/write/create tables in the “wordpress” database but not others.
Create and change wordpress config file so it can connect to its database in MySQL
Now we go to our web app folder
/var/www/wordpress. You should see a file called
wp-config-sample.php . This is the template file for your wordpress config file
wp-config.php . Copy this file and rename it to
sudo cp wp-config-sample.php wp-config.php
Open the config file. Find these lines and enter the corresponding values from your MySQL settings:
Now the wordpress is ready to connect to your MySQL database!
Change files’ owner and permissions so we can change wordpress from its online admin panel
As mentioned before, wordpress’ files must have proper ownership and permission settings so we can configure wordpress from the web admin panel. To do so, simply execute the two command:
#>sudo chown -R www-data:www-data /var/www/wordpress/*
#>sudo chmod -R 755 /var/www/wordpress/*
The first command changes the owner to
www-data and group to
www-data is the user/group of web server apache2.
The second command is harder to understand. See chmod online page for more information.
Now everything is ready except to install wordpress from the browser. Open the browser and type your domain, and you should see the wordpress installation page.
Simply follow the instructions and press “install”. If you did all the previous steps correctly you should have wordpress installed within seconds!