How to Install LAMP Stack, WordPress, and Auto SSL Video Tutorial:

In this video, let’s learn Part 2 on How to Get Free Hosting for WordPress On Aws Ec2 Lamp Stack Centos 7 related to Install LAMP Stack, WordPress and SSL, WordPress, and Auto SSL.

I will show you STEP BY STEP how to install the LAMP STACK on CentOS 7 and provide short descriptions for all the commands we will use and why.

After watching this video, you will have enough understanding of how to setup a WordPress website on a lamp stack environment with a CentOS 7 operating system.

You can find the CHEAT SHEET or all the commands for SSH below.

You can learn more about the first part which is related to setting up an AWS Account, Elastic IP & CentOS 7 here.

The remaining parts will be published further, so stay tuned and don’t forget to subscribe to get notified about this FREE COURSE on How to Get Free Hosting For WordPress On AWS with Lamp Stack In CentOS 7 for a lifetime.

You can also check the full series on Youtube.

WE WILL TRY TO ANSWER THESE FAQs:
How to Install WordPress with Apache Web Server on CentOS 7
How to Install LAMP Stack Environment on CentOS 7 for WordPress
How to Install Apache Web Server on CentOS 7 in 2022-2023
How to Install MariaDB/MySQL on CentOS 7 in 2022-2023
How to Install PHP Packages, Modules/Extensions on CentOS 7
How to Fix the Error related to unable to write to wp-config.php
How to Fix WordPress Stuck on Testing 123 Apache Welcome Page
How to Install WordPress In Lamp Stack CentOS 7 in 2022-2023
How to Setup WordPress In Lamp Stack CentOS 7 in 2022-2023
Setup Website Virtual Host Configuration using Lamp Stack on CentOS 7
How to Redirect IP to Domain Name within Lamp Stack on CentOS 7
Install FREE AUTO SSL for by Let’s Encrypt with Lamp Stack on CentOS 7
Install PHPMyAdmin Database Manager with Lamp Stack on CentOS 7

Get access to the commands (Cheat Sheet) below. You can also check the full series on my Youtube Channel.

1. Prepare Server for LAMP Stack Environment

# Login via SSH and run as root:

sudo su -
# OR:
sudo su

# Change root password:

passwd

# Set hostname:

hostnamectl set-hostname --static domain.com

# Install necessary tools, and run commands:

yum -y install wget curl nano vim zip unzip screen

# Update System, run commands:

yum -y update

# Disable SELinux Firewall to avoid conflicts while setting up LAMP:

# Enable SELinux Firewall to Encoforcing Mode:
setenforce 0
# Restart Apache to apply changes
systemctl restart httpd

# OR Disable SELinux Firwall Permanently:
sed 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config -i
# Reboot to apply changes
reboot

Note: If you want to enable back SElinux by the end of your LAMP Stack Environment setup, you can simply enable SELinux by running commands:

# Enable SELinux Firewall to Encoforcing Mode:
getenforce
# Restart Apache to apply changes
systemctl restart httpd

# If it shows "Disabled", Enable through this command:
sed 's/SELINUX=disabled/SELINUX=enforcing/g' /etc/selinux/config -i
# Reboot to apply changes
reboot

2. Install Apache Web Server

# Install Apache Web Server

yum install httpd -y

# Start the Apache daemon and enable it to start automatically during system boot:

systemctl start httpd
systemctl enable httpd

# Check the status of Apache

service httpd status

# Set Apache config to Allow .htaccess to be used

sed -i 's/AllowOverride none/AllowOverride all/g' /etc/httpd/conf/httpd.conf

# Reload Apache

systemctl restart httpd

3. Install MariaDB & Packages

# Create a new repo file for the latest version of MariaDB.

nano /etc/yum.repos.d/MariaDB.repo

# Copy and paste the following contents into the file:

[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.6/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

# Install MariaDB server’s latest version of MariaDB and the most common packages

yum install -y MariaDB-server galera-4 MariaDB-client MariaDB-shared MariaDB-backup MariaDB-common --skip-broken

# Start the Mariadb database daemon and enable it to start automatically during system boot.

systemctl start mariadb
systemctl enable mariadbcode

# Check the status of MariaDB

service mariadb status

# Database Upgrade

mysql_upgrade

# OR (with MySQL password)

mysql_upgrade -u root -p

# Secure MariaDB (preferably SETUP with Password, SEE VIDEO)

mariadb-secure-installation

# Reload MariaDB to apply changes

service mariadb restart

OPTIONAL:

# SET MariaDB New Root Password for MariaDB/MySQL:

mysqladmin -u root password

# Reload MariaDB to apply changes

service mariadb restart

# UPDATE MariaDB Root Password for MariaDB/MySQL:

mysqladmin -u root -p password

# Reload MariaDB to apply changes

service mariadb restart

# OR login to the MySQL console, then type the following at the MySQL/MariaDB command prompt to update:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'YourPassw0rd'; flush privileges; exit;

# Reload MariaDB to apply changes

service mariadb restart

# Login to MySQL (with) password

mysql -u root -p

# Check the MariaDB version

mysql -u root -p -V

OPTIONAL: Login to MySQL (without) password

mysql

# Check the MariaDB version

mysql -V

4. Install PHP & Packages

# Install Linux Packages and tools for switching PHP versions

yum install -y epel-release yum-utils http://rpms.remirepo.net/enterprise/remi-release-7.rpm --skip-broken

# Install PHP & Modules/Extensions (commonly required by Scripts like WordPress):

yum -y install php php-mysqlnd php-pdo php-fpm php-gd php-mbstring php-curl php-mcrypt php-json php-imagick php-zip php-dom php-cli php-fileinfo php-intl --skip-broken

# Enable the latest Remi and select updated PHP

yum-config-manager --enable remi-php74

# Update the System to refresh the repository:

yum update -y

# Reload Apache & Mariadb Database

service httpd restart && service mariadb restart

# Check the Status of Apache & Mariadb Database (just making sure nothing broke)

systemctl status httpd && systemctl status mariadb

# Check the PHP version

php -v

5. Preparing WordPress Database

# Login to MariaDB or Database

mysql -u root -p

OPTIONAL:

mysql

# Create Database for the website. “dba_name” is the database name or whatever:

CREATE DATABASE dba_name;

# Check databases:

SHOW DATABASES;

# Create Database User

CREATE USER 'dba_user'@'localhost' IDENTIFIED BY '[email protected]#';

# Grant database permissions to the user. This will also let you create a database user and password:

GRANT ALL PRIVILEGES ON dba_name.* TO 'dba_user'@'localhost';

# Apply changes

FLUSH PRIVILEGES;

# Exit MariaDB or Database Management interface:

exit

OPTIONAL:

# We can also make the database, user along with granting privileges and EXIT (all at once) thru this line of commands:

CREATE DATABASE dba_name; GRANT ALL PRIVILEGES ON dba_name.* TO 'dba_user'@'localhost' IDENTIFIED BY '[email protected]#'; FLUSH PRIVILEGES; exit;

# To Change USER details

ALTER USER 'dba_user'@'localhost' IDENTIFIED BY 'whateverpassw0rd'; flush privileges;

6. Preparing WordPress / Website Files

# Download the WordPress script

cd
wget https://wordpress.org/latest.tar.gz

# Extract installation files from tar:

tar zxvf latest.tar.gz

# Remove tar file as it is not needed:

rm -rf latest.tar.gz

# Move WordPress files to Website Directory:

mv wordpress/* /var/www/html

# Set permissions for website directory:

chown -R apache:apache /var/www/html
find /var/www/html/ -type d -exec chmod 755 {} \;
find /var/www/html/ -type f -exec chmod 644 {} \;

# Reload Apache

systemctl restart httpd

7. Installing WordPress / Website

OPTION 1:

Disable SELinux temporarily to enable writing wp-config.php (It will be enabled when your server reboots)

setenforce 0

OPTIONAL: Permanently Disable SELinux

sed -i 's/enforcing/disabled/g' /etc/selinux/config

# Reload apache

service httpd restart

Navigate the IP to the Browser and install WordPress.

TROUBLESHOOTING TIPS:

Testing 123… stays on the page:
> Install the required PHP modules/extensions.

Cannot be reached…:

> Change the browser link from https:// to http://

# Check if iptables is enabled:

systemctl status iptables

# If yes, flush the iptables:

iptables -F

# Restart apache to apply changes

systemctl restart httpd

# Add Database details created previously within the Mariadb database console.

Database Name: dba_name
Username: dba_user
Password: [email protected]#

Note: Leave others “as is”

OPTION 2:

Manually add the details in the wp configuration file:

Database Name: dba_name
Database User: dba_user
Database Password: [email protected]#

Browse the file and Add the Database details above:

cd /var/www/html
cp wp-config-sample.php wp-config.php
nano wp-config.php

Navigate the IP to the Browser and install WordPress.

8. Troubleshooting (Site Health)

Log in to WordPress then check Dashboard > tools > site health

1. Check any required PHP modules and install
2. FTP Upload issue (Add in wp-config.php):

define('FS_METHOD','direct');

9. Point the Domain Name To Your Website (and make your website listen to port 80)

This is necessary to enable Let’s Encrypt SSL to generate for your website’s domain.

# Create site config file (or Virtual Host file):

cd /etc/httpd/conf.d
touch 0001-domain.com.conf
nano 0001-domain.com.conf

# Add Virtual Host config file template, and edit with your correct domain name:

# IMPORTANT: CHANGE domain.com to your website domain and "/var/www/html"
# to your related website directory
<VirtualHost *:80>
# Admin email, Server Name (domain name), and any aliases
ServerAdmin [email protected]
ServerName  domain.com
ServerAlias www.domain.com

# Index files and Document Root (where the public files are located)
DirectoryIndex index.html index.php
DocumentRoot /var/www/html

# Allow .htaccess for website
<Directory /var/www/html>
  Options Indexes FollowSymLinks
  AllowOverride All
  Require all granted
</Directory>

# Log file locations
LogLevel warn
ErrorLog  /var/www/html/error.log
CustomLog /var/www/html/access.log combined

# Redirect IP to Domain: If not equal to your domain,
# then redirect to your domain
RewriteEngine On
RewriteCond %{HTTP_HOST} !domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=302]

# Certbot SSL Custom Redirect Rules

</VirtualHost>

# Reload Apache

systemctl restart httpd

TROUBLESHOOTING (if apache doesn’t restart):

# this command will show what directories are necessary to be created:

systemctl status httpd.service -l

# then CREATE them if any:

mkdir -p <directory-path>

10. Install Let’s Encrypt SSL by CertBot with SNAP

# Install important Linux Packages, SSL Module, and Snap:

yum install epel-release mod_ssl snapd -y

# Enable Snap through the system service manager:

systemctl enable --now snapd.socket

# Create a system link to enable support for classic snaps:

sudo su -
ln -s /var/lib/snapd/snap /snap

# Reboot the server to apply changes

reboot

# Update snapd to the latest version

snap install core; snap refresh core

# Installing Certbot. With the EPEL repository added, install Certbot through snap:

snap install --classic certbot

11. Generate Auto SSL by Let’s Encrypt Using CertBort

Get SSL for Multiple domains

If you require SSL for multiple domains, specify them using the following command, ensuring the first domain specified is the base domain.

certbot --apache -d domain.com -d www.domain.com -v

OPTIONAL: Get an SSL Certificate for 1 domain

Certbot automatically takes care of SSL certificate management and installation. Specify a domain and the current web server in use. In this example, the domain domain.com is receiving a certificate.

certbot --apache -d domain.com -v

NOTE: After you run the command specified earlier, you will see step-by-step instructions with choices about the contact email address, forcing HTTPS, and various certificate settings.

12. Change HTTPS in your WordPress / Website URL

This is where you setup your website URL on WordPress or whatever script you use, CHANGE it with HTTPS.

If using WordPress, goto Dashboard > General > CHANGE the URLs from http:// to https://

Final thoughts

Now, you should already have setup a fresh install of WordPress with Lamp Stack on CentOS 7 from AWS EC2. You can learn how to setup WordPress within my WordPress Tutorials on my Youtube Channel.

For your convenience, you can also watch the related video tutorial on How to Install LAMP Stack, WordPress, and Auto SSL: