Installing WordPress on Ubuntu LAMP
In this tutorial we are going to install a wordpress website on a LAMP stack. WordPress is the most used CMS worldwide so it’s a great pick for testing our LAMP configuration. If you don’t have a LAMP stack installed you should check this article-Installing LAMP on Ubuntu
Create a database and a username in MySQL
First we need to create a database and a user corresponding to it in MySQL. In order to do that we need to log in to the root administrative account in MySQL. Type the following command:
mysql -u root -p
You’ll be asked for the password for the MySQL root user. Enter it.
Now you have access to MySQL. We are going to make the wordpress database. Use this command
CREATE DATABASE yourdatabasename;
We have to make a MySQL user for the database that we have just created and assign it a password.
CREATE USER [email protected] IDENTIFIED BY 'yourpassword';
Now we have to assign the newly created user to our wordpress database. In order to do that just type:
GRANT ALL PRIVILEGES ON yourdatabasename.* TO [email protected];
We have to flush the privileges in order for MySQl to know that we have made changes
We can exit mysql
In order to download the most recent and stable version of WordPress type the following:
This will download a compressed file containing the wordpress installation files and folders. We have to extract those files into our home directory.
tar xzvf latest.tar.gz
We have to install some additional modules in order to be able to install plugins in WordPress using our SSH login credentials.
sudo apt-get update sudo apt-get install php5-gd libssh2-php
Move WordPress files to Document root
In order for your website to be accessible you have to move your wordpress files to Apaches document root. The location of document root is /var/www/html/
It’s a good idea to create a separate directory for your wordpress installation. This way you can install multiple websites in your document root.
sudo mkdir /var/www/html/wordpress
sudo rsync -avP ~/wordpress/ /var/www/html/wordpress
Now your wordpress files are moved to your document root thus making them accessible for your visitors.
After that remove the wordpress folder and latest.tar.gz in your home directory
rm -rf wordpress
Our next task in to make changes to the wordpress config file
Navigate to /var/www/html/wordpress
We have to copy the wp-config-sample.php to wp-config.php and to remove the wp-config-sample.php
cp wp-config-sample.php wp-config.php rm wp-config-sample.php
Let’s open the wp-config.php and change some fields.
There are some fields which you need to change. We are changing them with the database and user in MySQL that we have made a while back.
define('DB_NAME', 'yourdatabasename'); define('DB_USER', 'yourusername'); define('DB_PASSWORD', 'yourpassword');
Save the file and exit.
Now we have to give our server access rights to our wordpress directory. If we don’t do that we won’t be able to update plugins upload images etc.In order to accomplish that we have to login as root.
Enter your root password
sudo chown -R www-data:www-data /var/www/html/wordpress
Return to your normal user account
su - yourusername
We have to grant read access to our general directory. In order to do that type:
sudo chmod -R 755 /var/www
In order to associate the domain we chose for our website with it’s proper location we have to make some changes
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/wordpress.conf
Now we have to edit wordpress.conf
We need to add the following lines
ServerName yourdomain.com ServerAlias www.yourdomain.com
Also we have to change this to your E-mail in order for you to receive E-mails
ServerAdmin [email protected]
Save and exit
We need to enable our website
sudo a2ensite wordpress.conf
In order for changes to take effect type
sudo service apache2 restart
To access your wordpress installation type the name of your domain in your browser and follow the installation instructions.
If you want to use wordpress pretty permalinks feature you have to make some changes in the host file.
You have to add those lines bellow DocumentRoot /var/www/html/wordpress.
Save and close. Next we need to enable the rewrite module. This enables you to rewrite URL’s
sudo a2enmod rewrite
restart the apache web server
sudo service apache2 restart
We need to create a .htaccess file in order for wordpress to write changes to it.
sudo touch /var/www/html/wordpress/.htaccess
To make the web server the group owner type
sudo chown :www-data /var/www/html/wordpress/.htaccess
Our last step is to give the .htaccess file the right permissions
sudo chmod 664 /var/www/html/wordpress/.htaccess
You can enjoy your newly installed WordPress website. Cheers!