How to install wordpress with LAMP (Debian, Ubuntu)

Installing Wordpress with LAMP


In this post, I am going to show you how to install WordPress in Linux(Debian, Ubuntu) which is most popular CMS for blogging and small size businesses. Before we install WordPress, we need to install HTTP Server ( Apache2 in this post ), Latest version of PHP and Database ( MariaDB in this post ).


Installing Apache2 HTTP Server



Type the commands below through console.

sudo -s apt-get update

apt-get upgrade

apt-get install apache2

Now we need to open the ports to make sure we can access the content through http, https.

If our hosting service or clouds allow us to setup firewall setting with their system, then we don't need to open the ports through commands.

However if we can't find the way to open it then we can run another two commands:
※ http is 80, https is 443


iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p udp --dport 80 -j ACCEPT


If we are using GCP (Google Cloud Platform), then we can just open the ports through the Networking page.
※ Please read the related document which is provided from your hosting(cloud) service.


Installing PHP


There are many version of PHP and I recommend you to download latest/default version. If we are using latest version of Linux, we would not have any problem because just one line of code will do everything for us.

apt-get install php libapache2-mod-php

When we install wordpres, if WordPress installation page show the message that it requires some PHP libraries/commands, then we should install them as well. Check Debian libapache2-mod-php for more about libapache2-mod-php.

Restart Apache2

service apache2 restart


Installing MariaDB and Preparation


We are going to install the highest stable version of MariaDB. After installation, we are going to create a database and a user, then we grant privileges on the created database to the created user.

MariaDB Repositories

While the installation, we will be asked to type the password for root user. This is quite important so we should make a complex password and write the password on somewhere in our sight. After the installation, type the commands below to login MariaDB.

mysql -u root -p

The password should be what we have typed while installation.
※ The typed characters won't show up in console so it will just display empty space.

Now we can create a database and a user, and grant privilges on the database to the user.



CREATE DATABASE nameOfDataBase;

CREATE USER userName@localhost IDENTIFIED BY 'password';

GRANT ALL PRIVILEGES ON nameOfDataBase.* TO userName@localhost;

FLUSH PRIVILEGES;

exit

※ We can use quit instead of exit.

Finally, we restart MariaDB, just in case.

service mysql restart


Installing WordPress


Type the commands below through console for WordPress installation

sudo -s

cd

cd /var/www/html

rm *

wget http://wordpress.org/latest.tar.gz

tar xzf latest.tar.gz

mv wordpress/* .

rm -rf wordpress latest.tar.gz

chown -R www-data:www-data /var/www/html

chmod -R 755 /var/www/html/

※ If we get a message that we do not have a command in the system then we should install the package for commands/use the command that does same job.

Now if we load the page through server ip address in web browser, we will get to the wordpress installation page. At the beginning it will ask us to choose the language we are going to use, so just select the language that we want to use.

After that, submit the database name, database user name, database user password, database path (localhost or ip address) and you may want to have different database table prefix than default.



※ We must not use root user for our database connection. We just need to put the database name and information of user that we created before.

In next page, it will ask us to submit site title, account name, account password and email. Do not forget to write them on somewhere in your sight.

From now, this is more likely my way of installing wordpress.

rewrite_mode from apache2 might not be enabled, so we have to enable rewrite_mode.

a2enmod rewrite

After this, we need to modify apache2.conf or httpd.conf.
※ You can look up the apache2 server document for more information.

cd

cd /etc/apache2

nano apache2.conf


If we go down of the console page that showing apache2.conf, we will find <Directory /var/www/> .... </Directory>.

<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>

We are going to fix above texts, change 'AllowOverride None' to 'AllowOverride All'.
※ Only <Directory /var/www/> .... </Directory>

<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>


We save the file with 'ctrl + x', 'y' and 'Enter'.

Now we need to modify .htaccess file.

cd

cd /var/www/html

nano .htaccess


Add the texts below to below of # END WordPress or very end of the .htaccess file.

php_value upload_max_filesize 64M
php_value post_max_size 64M
php_value max_execution_time 300
php_value max_input_time 300
 

This will give us control of upload size in wordpress.

Finally, we add texts below to the end of .htaccess file for the simple security.


<Files wp-config.php>
order allow,deny
deny from all
</Files>


<Files license.txt>
order allow,deny
deny from all
</Files>


<Files wp-config-sample.php>
order allow,deny
deny from all
</Files>


<Files readme.html>
order allow,deny
deny from all
</Files>


<Files xmlrpc.php>
order allow,deny
deny from all
</Files>


<Files .htaccess>
order allow,deny
deny from all
</Files>


# disable directory browsing
Options All -Indexes

<Files robots.txt>
Options +Indexes
</Files>

# prevent folder listing
IndexIgnore *


This prevents listing, indexing and browsing for the files that don't have to be shown.

If we have sitemap.xml file, we should add the text below as well but normally we don't have to do that, since most of WordPress plugins don't create sitemap.xml file.

<Files sitemap.xml>
Options +Indexes
</Files>




No comments:

Post a Comment