LAMP & Wordpress Installation
Published: 2023-08-16 04:56:28

> **15-08-2023** **" HAPPY INDEPENDENCE DAY "**

Before starting to install WORDPRESS , below LAMP should be in place to bring the WordPress installation successful.

## **LAMP**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/20kquimvyqnhr2mlq5uy.png)

---
## **APACHE2**

- Apache is the web server that processes requests and serves web assets and content via HTTP.
- All the configuration files for Apache are located in **_/etc/httpd/conf_** and **_/etc/httpd/conf.d_** . 
- The data for websites you'll run with Apache is located in **_/var/www_** by default, but you can change that if you want.
- Listen: to bind Apache to specific IP addresses and/or ports. HTTP server, by default, runs on port 80 for production. But, when it has to deal with secure web transactions, it uses the port 443. This secure transaction works using the SSL certificate.

```
sudo apt update -y && apt upgrade -y
sudo apt install apache2 apache2-utils -y
sudo systemctl start apache2
sudo systemctl enable apache2
sudo systemctl status apache2
apache2 -v
sudo chown -R www-data:www-data /var/www/html
```
In the above command , while giving "**_apt upgrade -y_**" it may take more time. So try to do when necessary. If the command is given don't try to stop in-between it may lead to many issues.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/abmvwhsk7yf7tijbwc31.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o8oj3b55yb3zo7ggs70e.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3zuxceij2iq1dhiws6e4.png)
---
## **MariaDB**

- MariaDB is a community-developed, commercially supported fork of the MySQL relational database management system, intended to remain free and open-source software under the GNU General Public License. ( as per WIKI )
- When it comes to performing queries or replication, MariaDB is faster than MySQL.
- MariaDB also easily supports a high concurrent number of connections without much performance degradation.

```
sudo apt install mariadb-server mariadb-client
sudo systemctl start mariadb
sudo systemctl enable mariadb
sudo systemctl status mariadb
```

Root Password,

```
mysql_secure_installation
Enter current password for root (enter for none): enter
Set root password? [Y/n] Y
New password:******
Re-enter new password:******
Remove anonymous users? [Y/n]Y
Disallow root login remotely? [Y/n]Y
Remove test database and access to it? [Y/n]Y
Reload privilege tables now? [Y/n]Y
```

Login to MariaDB,

```
mariadb -u root -p
mariadb --version
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c3h0zksmmdwz0gtnw06m.png)
---
## **PHP**

- The full form of PHP is Hypertext Preprocessor.
- It is a programming language widely used to build web applications or websites. 
- It is the server-side scripting language encoded with HTML to develop Dynamic website, Static website or Web applications.
- PHP is an open-source, server-side programming language that can be used to create websites, applications, customer relationship management systems and more. 
- It is a widely-used general-purpose language that can be embedded into HTML.
```
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php8.2 libapache2-mod-php8.2 php8.2-mysql php-common php8.2-cli php8.2-common php8.2-opcache php8.2-readline php-json
php --version
sudo vim /var/www/html/info.php --> Edit and test
<?php phpinfo(); ?>
http://localhost/info.php --> Try in the browser
curl http://localhost/info.php

```
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jvu60m87t8nr16ac261s.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xbiok428qq2mt0eh82pz.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i9accsg03mmqi5p90olm.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y8n6dl90heli6q7gyvi3.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b6gp97mt4bi1tu0p83xu.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a49293oevgg3uehj4ghq.png)

```
rm /var/www/html/info.php
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b8w3cadk0gnbe8pk8xf9.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k7m59vhzs7gtmyzzjtxx.png)

## **_Above LAMP INSTALLATION COMPLETED SUCCESSFULLY_**
---

## **WordPress Installation**

- WordPress is a content management system (CMS) that allows you to host and build websites.
- WordPress is free, as are many of its add-ons.
- WordPress lives on a web server, and delivers web content to a user's web client (his or her browser). Processes that occur on the server are called “server-side,” as is the server environment itself.

Let's jump into the set-up, login MariaDB and create a DB w.r.t WordPress ,

```
mysql -u root -p
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'kan123';
CREATE DATABASE wpdb;
GRANT ALL PRIVILEGES ON wpdb.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
exit;
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hfa2xc5a8gmg9f51a4o7.png)

Now download WordPress latest version ,

```
wget https://wordpress.org/latest.zip
unzip latest.zip
rm latest.zip
sudo mv wordpress/ /var/www/html/
sudo chown www-data:www-data -R /var/www/html/wordpress/
sudo chmod -R 755 /var/www/html/wordpress/
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7lekx8fmvjl7kqp8gnpd.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hca5krizqrw2pe2o2xck.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tb4vi6t0sdh5i36rkkri.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qukyv38s6e287a85ymue.png)

Creation of configuration file ,

```
sudo vim /etc/apache2/sites-available/wordpress.conf
<VirtualHost *:80>
ServerAdmin admin@example.com
DocumentRoot /var/www/html/wordpress
ServerName <server_ip> --> which you have mapped in /etc/hosts
<Directory /var/www/html/wordpress/>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/osl24yzitcah4kxcjn2z.png)

Enable the virtual host and the rewrite module,

```
sudo a2ensite wordpress.conf
sudo systemctl reload apache2
sudo a2enmod rewrite
sudo systemctl restart apache2
```
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f26cw31hvycngk6g88u4.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2h3ctpf2mq30kvsay4ie.png)

In the browser , try below URL - it will navigate to WordPress home page configuration.
```
http://server_ip
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z0g33bkmo4adcozb1jtq.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ukd7sqsexd8ce0uuk26b.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ymvw94vkh3r7eiipsw7l.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2dy7m7c1byhrkj3lk2gi.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nu2ae6yx1c397gqvz3hr.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mwn4h1pab125eopqw6mr.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vrx12275ilh61uebj6lr.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0hi845xpvmj8acbqordt.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jh4lu1f36ffpcvfxukrd.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vwkzwqzach7687k0qlh1.png)

Schemas created by the WordPress,

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s2iet6774cnk6520thx0.png)
---

## **Error's Faced :**

**ERROR 1**. Inside hosts file, we could see many host-name which is mapped to 127.0.0.1 . Its better to delete and try to make the WordPress up and then add if its required.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ekwz0s63hyxux0544djp.png)

**ERROR 2**. PHP is not loaded properly,

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ehliowltnjf6x54a1rsa.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r4qtiv07thlsxz2tympm.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n4cu1qivpdxf8nz9lgxb.png)

E: Unable to correct problems, you have held broken packages.

The following packages have unmet dependencies:
 curl : Depends: libcurl4 (= 7.81.0-1ubuntu1.10) but 7.81.0-1ubuntu1.13 is to be installed
E: Unable to correct problems, you have held broken packages.

Which leads to unable to start the apache2 ,

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xpuyjggha21352qdq44i.png)

Try the below to which the issue details,

```
cd /etc/apache2
apache2ctl configtest
journalctl | tail
```
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/82bjirjgo4pww0liaik2.png)

Try to purge the apache2 and start the service,

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ue2vzcvbkakqcswwbghz.png)

E: The repository 'https://ppa.launchpadcontent.net/ondrej/php/ubuntu lunar Release' does not have a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f7m2tyyycvipwfcnagd9.png)
```
sudo apt --fix-broken install
sudo apt update
sudo cp /etc/apt/trusted.gpg /etc/apt/trusted.gpg.d
sudo apt update
sudo apt install apache2 apache2-utils -y
```
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5ngapj5g6yta4zu8174u.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8fnb2hkqpj5jirilpjns.png)

**ERROR 3**. Its loading different index page,

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vzevg6qck0xh45rw4pie.png)

```
cd /var/www/html/
sudo rm index.html site1.test.com/ site2.test.com/
```
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ivk3ccxpq2r728q86a2o.png)

**ERROR 4**. Unable to connect DB,

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ikzrx308q4d5ybsheu2k.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/16szzik887srkwpbmj88.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ihwjsvdlxuqmhg7jdcq3.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yga4w6yl0x45bmisn5pi.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ax56tp1896mlg7hmtayr.png)

Solution : Provide the proper "Password".

**ERROR 5**. Could not enable dependency mpm_prefork for php8.2, aborting:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yioqdvj4dplwszky170y.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/199zqzh2awm3pfsc9lpp.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vumj6rnj3c84szh7cj6y.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/stcc9eg50xopx3d7yig3.png)

Still it was failing,

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uerg94xodmlfzwrd98ji.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/94hqfz2a42xv9acjwhov.png)

Solution:

https://stackoverflow.com/questions/47024111/apache-installing-and-running-php-files

```
sudo a2dismod mpm_event
sudo systemctl restart apache2
sudo a2enmod mpm_prefork
sudo systemctl restart apache2
sudo systemctl status apache2
sudo a2enmod php8.2
sudo a2ensite wordpress.conf
sudo systemctl reload apache2
sudo a2enmod rewrite
sudo systemctl restart apache2
```
---
## **Important points:**

1. https://mariadb.org/
2. https://httpd.apache.org/
3. https://www.php.net/
4. Completed installation steps with more details : https://github.com/tkdhanasekar/kaniyam-devops-course-materials/blob/main/Linux/lamp-stack.md
5. https://wordpress.com/
6. shift control + n/p --> Private Window
7. All plugins are available in WordPress , which are free and can be paid.