How to install wordpress in ubuntu

This tutorial shows how to install WordPress in Ubuntu 18.04.
It starts by showing how to install Apache2, PHP , MYSQL.
It shows how to change MYSQL password and download and copy WordPress files in Apache.

 

In addition, it talks about how to change the htaccess file and how to enable rewrite mode in Apache. Let’s start:

First install Apache2, PHP and PHP-MySQL:

 


#install apache2 php mysql
sudo apt-get install apache2 php libapache2-mod-php php-mysql

 

Then in the next step, we install MySQL and run a simple security script that comes pre-installed with MySQL which will make MySQL secure.


#install mysql
sudo apt install mysql-server
#run mysql_secure_installation
mysql_secure_installation

 

Then we enable Apache2 rewrite and default SSL modules and restart Apache after enabling those modules


#enable rewrite
sudo a2enmod rewrite
sudo a2ensite default-ssl
sudo a2enmod ssl
systemctl restart apache2

 

At this stage, we want to configure the MySQL root account to authenticate with a password.
The sample password in the example below is ‘Password’ :


#change mysql root password to 'Password'
sudo mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Password';
#test root password
mysql -u root -pPassword

 

In this step, since WordPress needs a database, in MySQL console, we create a database (fullstacklogsdb) and a user and password (dbuser with a password: dbpassword):


mysql -u root -pPassword
#create wordpress database and new database user
create database fullstacklogsdb;
CREATE USER 'dbuser'@'localhost' IDENTIFIED BY 'dbpassword';
grant all on fullstacklogsdb.* to dbuser@localhost;
FLUSH PRIVILEGES;

 

Now we download the WordPress files and copy the files to apache’s html directory and change the mod and owner of the directory:


#download the code
wget https://wordpress.org/latest.tar.gz
tar -xvf latest.tar.gz
cd wordpress
cp -r * /var/www/html
chmod -R 755 /var/www/html
mkdir /var/www/html/wp-content/uploads
cd /var/www
chown -R  www-data:www-data html

 

Now it is time to type in your browser the http://ip-address/ or http://your-domain-name/ or http://localhost/ (if you test it locally)
and finish the WordPress installation. You need to enter the MySQL database, username and password which you created above.


#browse the website and install wordpress
http://ip-address/
#enter database: fullstacklogsdb and user: dbuser , password: dbpassword

 

You need to apply below changes in htaccess file ( which is a hidden file) to make it work.
As you see the RewriteBase is / which means that you can run it in your browser using the server name only. (like http://localhost)
if you want to run it let’s say under a folder called WordPress the RewriteBase should be /wordpress (like http://localhost/wordpress)


# vim .htaccess in /var/www/html
# BEGIN WordPress
RewriteEngine On
DirectoryIndex index.html index.php
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

For enabling WordPress rewrite we need to change the AllowOverride to All as below.
Please note that if you not using SSL put below in
/etc/apache2/sites-enabled/000-default.conf
otherwise, if you enabled SSL change the /etc/apache2/sites-enabled/default-ssl.conf:

 


#enable rewrite in apache
<Directory /var/www/html>
         Options Indexes FollowSymLinks MultiViews
         # changed from None to All
         AllowOverride All
         Order allow,deny
         allow from all
</Directory>       

 

If you want to change the website URL later, you need to run below update SQL command to change the website address:


mysql -u root -pPassword;
show databases;
use fullstacklogsdb;
SHOW TABLES;
update wp_options set option_value='https://your-website-uel/'  where option_name='home' or option_name='siteurl';

Leave a Reply

Your email address will not be published. Required fields are marked *