If you’ve already installed LAMP (Linux, Apache, MySQL, PHP) or LNMP in Ubuntu Server, now it’s time to install wordpress on Ubuntu and get your site running!
WordPress is a popular blogging tool and a content management system (CMS) based on PHP and MySQL. It’s free and open-source. In the steps below the lines that the user needs to enter or customize will be in red in this tutorial!
1. Create MySQL Database and User for WordPress
If you’re using LAMP, install PhpMyAdmin to get a graphical way setting your MySQL Database.
To install PhpMyAdmin, run command below in Ubuntu server:
sudo apt-get install phpmyadmin
Choose apache2 webserver while the installing process and say NO to “Configure database for phpmyadmin with dbconfig-common?”
Once installed, run commands below to get it working:
sudo sh -c 'echo "Include /etc/phpmyadmin/apache.conf" >> /etc/apache2/apache2.conf' && sudo service apache2 restart
Now, go to http://UBUNTUSERVERIP/phpmyadmin/ in your client’s browser and type in root and the password you set when MySQL was installed to login.
Follow the steps below to create Database and user:
Step 1 – Click on Users then click Add User.
Step 2 – Type in your desired User name (wordpress is a good one) and ensure Use text field is selected. Ensure Host is set to Local from the drop down list and the text box will change to localhost and enter a Password and then confirm it in the Re-type box. Ensure the Password Use text field is also selected.
Step 3 – Click on Create database with same name and grant all priviliges.
Step 4 – Click on Go.
If you’re using LNMP (Linux, Nginx, MySQL, PHP), follow the steps below to create user & database (both are wordpress in commands below).
Step 1 – Run command in Ubuntu Server to log into MySQL Shell with MySQL root password:mysql -u root -p
Step 2 – Create database, here I named it wordpress:CREATE DATABASE wordpress;
Step 3 – Create a new user also named wordpress:CREATE USER wordpress@localhost;
Step 4 – Set a password for this user:SET PASSWORD FOR wordpress@localhost= PASSWORD("12345678");
Step 5 – Grant all privileges to the new user:GRANT ALL PRIVILEGES ON wordpress.* TO wordpress@localhost IDENTIFIED BY '12345678';
Step 6 – Refresh MySQL:FLUSH PRIVILEGES;
Exit MySQL shell:exit
2. Download WordPress
On Ubuntu Server, run command below to download the latest wordpress package from its official site:
cd && wget http://wordpress.org/latest.tar.gz
Then uncompress it via command below:
tar -xzvf latest.tar.gz
3. Setup WordPress Configuration
First copy the sample wordpress configuration file into a new config file:
cd && cp wordpress/wp-config-sample.php wordpress/wp-config.php
Then edit the file with command below:
Find the section that contains the field below and substitute in the correct name for your database, username, and password:
// ** MySQL settings – You can get this info from your web host **
Press i to start editing, and Esc to end editing. Finally press Shift+: followed by wq and Enter to save and exit the file.
4 Copy the files
Now move WordPress files to webserver root directory:
For LAMP:cd && sudo rsync -avP wordpress/ /var/www/
For LNMP:cd && sudo rsync -avP wordpress/ /usr/share/nginx/html/
Give ownership of the directory to the apache/nginx user:
cd /var/www/ ###For nginx: cd /usr/share/nginx/html/ sudo chown www-data:www-data * -R sudo usermod -a -G www-data www-data
5. Install WordPress:
Now in your client’s web browser go to http://UBUNTUSERVERIP/wp-admin/install.php and install your wordpress site:
Once done, if you still get “It Works!” Apache page. Run command below to edit dir.conf:
sudo vi /etc/apache2/mods-enabled/dir.conf
You will see a line of index files (index.html, index.php, index.cgi, etc) under the DirectoryIndex setting. Add index.php as the first item in the list.
After that, restart Apache server by:
sudo service apache2 restart
Now you can access your new website: