Linux on Windows: WSL with Desktop Environment via RDP

Linux on Windows: WSL with Desktop Environment via RDP

WSL (Windows Subsystem for Linux) is very common these days especially with the new that Windows will ship a Linux kernel with WSL 2.0!

Installing a Linux distro as WSL is easy via the Microsoft App Store and there are plenty of tutorials out there for it.

Most of the resources cover the access via Shell, Terminal, Hyperterminal or other console based tools to the WSL.
Running GUI software is possible and there are resources describing how to archieve this via VcXsrv (see chapter in this post of mine).

But what if you:

Want to have/access a Desktop environment on WSL?

You can use any Desktop Environment you want, I will be using Xfce in this example because it is lightweight.

Here is the quick rundown of all commands and steps, explained in the sections below. One is for Kali Linux, the other is for the Debian based distros (Debian, Ubuntu, …).

For Kali:

sudo apt update && sudo apt -y upgrade
sudo apt -y install kali-desktop-xfce
sudo apt-get install xrdp
sudo cp /etc/xrdp/xrdp.ini /etc/xrdp/xrdp.ini.bak
sudo sed -i 's/3389/3390/g' /etc/xrdp/xrdp.ini
sudo sed -i 's/max_bpp=32/#max_bpp=32\nmax_bpp=128/g' /etc/xrdp/xrdp.ini
sudo sed -i 's/xserverbpp=24/#xserverbpp=24\nxserverbpp=128/g' /etc/xrdp/xrdp.ini
sudo /etc/init.d/xrdp start

For other debian based distros:

sudo apt update && sudo apt -y upgrade
sudo apt -y install xfce4
sudo apt-get install xrdp
sudo cp /etc/xrdp/xrdp.ini /etc/xrdp/xrdp.ini.bak
sudo sed -i 's/3389/3390/g' /etc/xrdp/xrdp.ini
sudo sed -i 's/max_bpp=32/#max_bpp=32\nmax_bpp=128/g' /etc/xrdp/xrdp.ini
sudo sed -i 's/xserverbpp=24/#xserverbpp=24\nxserverbpp=128/g' /etc/xrdp/xrdp.ini
sudo /etc/init.d/xrdp start

And then connect via RDP localhost:3390 to your desktop.

Connect to WSL DE via Xrdp

Login to WSL DE

Detailed steps

Updating the system and installing Xfce4

sudo apt update && sudo apt -y upgrade
sudo apt -y install kali-desktop-xfce
sudo apt -y install xfce4

The first command updates the source list and the packages. Always important, I will not explain this.
The sudo apt -y install kali-desktop-xfce installs a Kali Linux specific version of Xfce4 and sudo apt -y install xfce4 will install the Xfce4 package for debian based distros.

Installing Xrdp

sudo apt-get install xrdp

Xrdp is an open source remote desktop solution and also very lightweight and easy to configure. This command will install the package and setup the default configuration with port 3389.

Configuring Xrdp

sudo cp /etc/xrdp/xrdp.ini /etc/xrdp/xrdp.ini.bak
sudo sed -i 's/3389/3390/g' /etc/xrdp/xrdp.ini
sudo sed -i 's/max_bpp=32/#max_bpp=32\nmax_bpp=128/g' /etc/xrdp/xrdp.ini
sudo sed -i 's/xserverbpp=24/#xserverbpp=24\nxserverbpp=128/g' /etc/xrdp/xrdp.ini
sudo /etc/init.d/xrdp start

Copy the config file as backup before the changes, change the port from 3389 to 3390 and for quality reasons increase the bpp from 24 to 128. You can play with those settings but since this is a local connection, the speed should not be worse with those settings.
And finally restarting the xrdp service to apply the changes.

Now you can connect via localhost:3390 and the credentials of your WSL account via RDP! ?

Desktop of WSL via xrdp

Why the port change from 3389 to 3390?

Two reasons: security and sometimes port 3389 is used by a process on wsl and you get the message

Your computer could not connect to another console session on the remote computer because you already have a console session in progress.

Benefits of RDP here

Even though you can run GUI software via XServer in a window, sometimes it is more convenient to have the full desktop environment accessible.
Also you can restore a previously disconnected session easily and do not have to close the console (let processes running for example).

Source : Linux on Windows: WSL with Desktop Environment via RDP – DEV Community ?‍??‍?

How to Restart or Shutdown a Remote Computer

How to Restart or Shutdown a Remote Computer

There will be times as a Windows Administrator that you will need to reboot or shutdown a remote computer or server.

In this tutorial, I’ll show you two easy methods for rebooting and shutting down remote computers.

The first method uses a built in Windows command and the second method uses PowerShell.

Check it out.

Windows Shutdown Command

Windows systems has a built in shutdown command that can be used to restart or shutdown local and remote computers.

The command is shutdown.

To use this command just open the windows command prompt and type shutdown.

To view the full list of command options type shutdown /? in the CMD window.

There are several command line switches, below I list the most useful options.

/s – Shutdown the computer

/r – restart computer

/m \\computer – Specify the remote computer

/l – Log off

/t xxx – Set the time out period before shutdown to xxx seconds

/c “comment” – Message to display on the screen before restart or shutdown

Now lets move onto some examples

Restart or Shutdown Examples with Command Line

In these examples, I’ll be on PC1 and will initiate a remote restart or shutdown on PC2.

I’ll be using the /r switch in these examples, you can change them to /s to shutdown instead of restart.

Example 1: Restart Remote Computer

By default, this will prompt the remote computer and give it about a minute before it restarts.

shutdown /r /m \\pc2

The pop up below is what a Windows 10 system will display.

Example 2: Restart With a Custom Message

You may want to display a custom message to the logged on users, to do that just use the /c command.

shutdown /m \\pc2  /c "The IT department has initiated a remote restart on your computer"

Below is the pop up on the remote computer with the custom message.

Example 3: Immediate Restart no Countdown

If you want to immediately restart with no countdown or message use this command.

shutdown /r /m \\pc2 /t 0

If you want a longer countdown just specify the seconds /t 60

Example 4: Log user off remote computer

If you just want to log a user off the remote computer use this command.

shutdown /l /m\\pc2

Restart or Shutdown with Powershell

Here are a few examples of how you can restart or shutdown computers with PowerShell.

The downside to PowerShell is it doesn’t have as many options as the shutdown command. There is no option to prompt users with a custom message or provide a countdown.

Example 1: Use Powershell to restart a computer

This command will immediately restart a remote computer. The -Force option will force a restart even if a user is logged on.

Restart-Computer -ComputerName REMOTE_COMPUTER_NAME -Force

Example 2: Use PowerShell to shutdown a computer

This command will shutdown a remote computer. Use the -Force to force a shutdown even if a user is logged on.

Stop-Computer -ComputerName REMOTE_COMPUTER_NAME -Force

Example 3: Use PowerShell to restart a list of computers

This is handy if you have several computers to restart. Just list all the computers you want in a text file and add that to the PowerShell command.

restart-computer (get-content c:\work\computers.txt)

Example 4: Use PowerShell to shutdown down two computers

Stop-Computer -ComputerName "Server01", "Server02"

Have fun!

See also:

How to View Open Files On Windows Server
How To Check Windows Server Uptime

Recommended Tool: SolarWinds Server & Application Monitor (SAM)

This utility was designed to Monitor Active Directory and other critical applications. It will quickly spot domain controller issues, prevent replication failures, track failed logon attempts and much more.

What I like best about SAM is it’s easy to use dashboard and alerting features. It also has the ability to monitor virtual machines and storage.

Download Your Free Trial of SolarWinds Server & Application Monitor. 

Source : How to Restart or Shutdown a Remote Computer

How to Exit When Errors Occur in Bash Scripts

How to Exit When Errors Occur in Bash Scripts

It’s a common issue that scripts written and tested on GNU/Linux don’t run correctly on macOS–or vice versa–because of differences between the GNU and BSD versions of the core utils. Error messages can get drowned in the script output, making it far from obvious that something isn’t executing correctly. There are a couple of easy fixes to avoid problems like this, but they rely on some bash features that you may not be familiar with if you don’t do a ton of scripting. I’ll summarize my two approaches here and hopefully they’re of some use to you if you’re looking for a how-to guide for this specific problem.

Exit When Any Command Fails

This can actually be done with a single line using the set builtin command with the -e option.

# exit when any command fails
set -e

Putting this at the top of a bash script will cause the script to exit if any commands return a non-zero exit code. We can get a little fancier if we use DEBUG and EXIT traps to execute custom commands before each line of the script is run and before the script exits, respectively. Adding the following lines will allow us to print out a nice error message including the previously run command and its exit code.

# exit when any command fails
set -e

# keep track of the last executed command
trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG
# echo an error message before exiting
trap 'echo "\"${last_command}\" command filed with exit code $?."' EXIT

For example, if we run ls --fake-option then we’ll see an informative error message as follows.

ls: unrecognized option '--fake-option'
Try 'ls --help' for more information.
"ls --fake-option" command filed with exit code 2.

Exit Only When Specific Commands Fail

The global solution is often fine, but sometimes you only care if certain commands fail. We can handle this situation by defining a function that needs to be explicitly invoked to check the status code and exit if necessary.

exit_on_error() {
    exit_code=$1
    last_command=${@:2}
    if [ $exit_code -ne 0 ]; then
        >&2 echo "\"${last_command}\" command failed with exit code ${exit_code}."
        exit $exit_code
    fi
}

# enable !! command completion
set -o history -o histexpand

That bottom line isn’t strictly necessary, but it allows us to use !! and have it expand to the last command executed. For example, we can check explicitly for an error like this

ls --fake-option
exit_on_error $? !!

will pass the exit code of the previous command as the first argument to exit_on_error() and then !! will expand to ls --fake-option as the second and third arguments. The second and third arguments–plus any further arguments if they were there–are then recombined by slicing ${@:2}.

This approach will print the same error message as the one in the previous section, but will only check the commands that are explicitly followed by exit_on_error calls.

Source : How to Exit When Errors Occur in Bash Scripts

How to Copy a File in Python with shutil | Python Central

So you want to know how to copy a file in Python? Good! It’s very useful to learn and most complex applications that you may design will need at least some form of copying files.

Copying a Single File in Python

Alright, let’s get started. This first section will describe how to copy a single file (not a directory) to another location on the hard disk.

Python has a special module called shutil for simple, high level file operations that is useful when copying single files.

Here’s an example of a function that will copy a single file to a destination file or folder (with error handling/reporting):

And that’s it! We just call that method, and the file is copied. If the source or destination file doesn’t exist, we print an error notifying the user that the operation has failed. If the source and destination files are the same, we don’t copy them and notify the user of the failed operation.

Python shutil’s Different Copy Methods

The module shutil has several methods for copying files other than the simple copy method that we have seen above.

I’ll go over them in some detail here, explaining the differences between them and situations where we might need them.

shutil.copyfileobj(fsrc, fdst[, buffer_length])

This function allows copying of files with the actual file objects themselves. If you’ve already opened a file to read from and a file to write to using the built-in open function, then you would use shutil.copyfileobj. It is also of interest to use this function when it is necessary to specify the buffer length of the copy operation. It may help, when copying large files, to increase the buffer length from its default value of 16 KB in order to speed up the copy operation.

All of the other copy functions mentioned below call this function at some point. It is the « base » copy method.

Let’s look at a benchmark for copying files using a 50 KB, 100 KB, 500 KB, 1 MB, 10 MB, and 100 MB buffer size vs a normal copy operation. We will test an archived file in iso format of 3.2 GB.

We’ll be using this function to specify the buffer size:

And Ubuntu’s built in time bash command to time the operation.

Here are the results:

50 KB: 29.539s
100 KB: 27.423s
500 KB: 25.245s
1 MB: 26.261s
10 MB: 25.521s
100 MB: 24.886s

As you can see, there is quite a big difference between the buffer sizes. Almost a 16% decrease in the amount of time it took using a 50 KB buffer size to using a 100 MB buffer size.

The optimal buffer size ultimately depends on the amount of RAM you have available as well as the file size.

shutil.copyfile(src, dst)

This method copies a file from the source, src, to the destination, dst. This differs from copy in that you must ensure that the destination path exists and also contains the file name. For example, '/home/' would be invalid because it’s the name of a directory. '/home/test.txt' would be valid because it contains a file name.

shutil.copy(src, dst)

The copy that we used above detects if the destination path contains a file name or not. If the path doesn’t contain a file name, copy uses the original file name in the copy operation. It also copies the permission bits to the destination file.

You would use this function if you are uncertain of the destination path format or if you’d like to copy the permission bits of the source file.

shutil.copy2(src, dst)

This is the same as the copy function we used except it copies the file metadata with the file. The metadata includes the permission bits, last access time, last modification time, and flags.

You would use this function over copy if you want an almost exact duplicate of the file.

Comparison of Python File Copying Functions

Below we can see a comparison of shutil‘s file copying functions, and how they differ.

Function Copies Metadata Copies Permissions Can Specify Buffer
shutil.copy No Yes No
shutil.copyfile No No No
shutil.copy2 Yes Yes No
shutil.copyfileobj No No Yes

That’s pretty much the end of copying files. I hope you benefited from this article, and I hope it was worth your time to learn a little bit of file operations in Python.

 

Source : How to Copy a File in Python with shutil | Python Central

How to get file creation & modification date/times in Python?

Getting some sort of modification date in a cross-platform way is easy – just call os.path.getmtime(path) and you’ll get the Unix timestamp of when the file at path was last modified.

Getting file creation dates, on the other hand, is fiddly and platform-dependent, differing even between the three big OSes:

Putting this all together, cross-platform code should look something like this…

import os
import platform

def creation_date(path_to_file):
    """
    Try to get the date that a file was created, falling back to when it was
    last modified if that isn't possible.
    See http://stackoverflow.com/a/39501288/1709587 for explanation.
    """
    if platform.system() == 'Windows':
        return os.path.getctime(path_to_file)
    else:
        stat = os.stat(path_to_file)
        try:
            return stat.st_birthtime
        except AttributeError:
            # We're probably on Linux. No easy way to get creation dates here,
            # so we'll settle for when its content was last modified.
            return stat.st_mtime

Solution 2:

You have a couple of choices. For one, you can use the os.path.getmtime and os.path.getctime functions:

import os.path, time
print("last modified: %s" % time.ctime(os.path.getmtime(file)))
print("created: %s" % time.ctime(os.path.getctime(file)))

Your other option is to use os.stat:

import os, time
(mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat(file)
print("last modified: %s" % time.ctime(mtime))

Note: ctime() does not refer to creation time on *nix systems, but rather the last time the inode data changed.

Solution 3:

The best function to use for this is os.path.getmtime(). Internally, this just uses os.stat(filename).st_mtime.

The datetime module is the best manipulating timestamps, so you can get the modification date as a datetime object like this:

import os
import datetime
def modification_date(filename):
    t = os.path.getmtime(filename)
    return datetime.datetime.fromtimestamp(t)

Usage example:

>>> d = modification_date('/var/log/syslog')
>>> print d
2009-10-06 10:50:01
>>> print repr(d)
datetime.datetime(2009, 10, 6, 10, 50, 1)

 

Source : How to get file creation & modification date/times in Python? – Stack Overflow

Backup with rsync

Everyone needs to make backups. Some people copy their most important files to an external hard disk or DVD, others use automated software to do the job for them. Many Mac OSX users use Time Machine, Apple’s backup application. I think i don’t have enough control when i use it. So i started looking for a program that did what i wanted it to do, make incremental backups from folders that i chose, and have the option to exclude files or folders from the backup.

rsync, a command line (cli) program that’s installed by default on almost all UNIX based operating systems (so also Mac OSX and a whole lot of GNU/Linux distro’s), does the job quite good for me.

Example bash commande bellow:

rsync -avzru /Volumes/LACIE/ /Volumes/LaCie\ 1 --exclude "/Applications/**" --exclude ".*" --exclude ".*/" --exclude ".*/**"

This can be perfectioned by passing it to tar command etc.

Notes:

  • rsync is the program.
  • -avzru means ‘archive’, ‘verbose’ (more output to the command line), ‘compress’ (use compression to decrease traffic if you use rsync over a network), ‘recursive’ (go into all folders), ‘update’ (don’t overwrite newer files)
  • /Volumes/LACIE/ this is the source external hard disk (notice the “/” at the end!)
  • /Volumes/LaCie\ 1 this is the destination external hard disk. It’s called ‘LaCie 1’, and the backslash is there to see the space as part of the path. (notice that there is no “/” at the end)
  • –exclude “/Applications/**” here i exclude the folder ‘Applications’ from the backup
  • –exclude “.*” –exclude “.*/” –exclude “.*/**” also exclude all hidden files and folders

that’s it ?

linux – Loop over file names from `find`?

Loop over file names from `find`? & execute a command

Some examples…

find . -name '*.mp3' -exec cmd {} \;

or

find . -name '*.mp3' -print0 | xargs -0 cmd

While Loop

As others have pointed out, you can frequently use a while read loop to read filenames line by line, it has the drawback of not allowing line-ends in filenames (who uses that?).

xargs vs. -exec cmd {} +

Summarizing the comments saying that -exec+ is better, I prefer xargs because it is more versatile:

  • works with other commands than just find
  • allows ‘batching’ (grouping) in command lines, say xargs -n 10 (ten at a time)
  • allows parallellizing, say xargs -P4 (max 4 concurrent processes running at a time)
  • does privilige separation (such as in the OP’s case, where he uses sudo find: using -exec would run all commands as the root user, whereas with xargs that isn’t necessary:
    sudo find -name '*.mp3' -print0 | sudo xargs -0 require_root.sh
    sudo find -name '*.mp3' -print0 | xargs -0 nonroot.sh
  • in general, pipes are just more versatile (logging, sorting, remoting, caching, checking, parallelizing etc, you can do that)

Source : linux – Loop over file names from `find`? – Stack Overflow

How to Install and Configure WordPress on CentOS 7 | ProfitBricks DevOps Central

Table of Contents

Introduction

WordPress is a free and open source blogging platform or content management system based on PHP and MySQL. Currently WordPress is the most popular CMS all over the world, and has 20000 plus plugins to extend its functionality.You can easily create a simple website, blog or complex portals and enterprise websites using WordPress.

WordPress provides lots of features. Some of them are listed below:

  • WordPress is available in more than 70 languages. So you can build a website in a language as your choice.
  • You can easily manage your content, schedule, look and publication using WordPress, and also secure your posts and content with a password.
  • WordPress comes with thousands of themes for you to create a beautiful website. You can also upload your own theme with the click of a button.
  • With the importers feature you can easily import your blog from another website to WordPress.
  • WordPress provides search engine optimization out of the box, and also provides many SEO plugins.

In this tutorial, we will discuss how to install and configure WordPress on a CentOS 7 server.

Requirements

  • A server running CentOS 7.
  • A non-root user with sudo privilege setup on your server.

Getting Started

Update your system with the latest package versions by running the following command:

sudo yum update -y

Once your system is up-to-date, you can proceed to the next step.

Installing LAMP

Before installing WordPress itself, you will need to install the LAMP stack and other required packages on your server.

You can install all the necessary packages with the following command:

sudo yum install httpd mariadb mariadb-server php php-common php-mysql php-gd php-xml php-mbstring php-mcrypt php-xmlrpc unzip wget -y

Once installation is complete, start the Apache and MariaDB services and enable them to start at boot with the following commands:

sudo systemctl start httpd
sudo systemctl start mariadb
sudo systemctl enable httpd
sudo systemctl enable mariadb

Configuring MariaDB for WordPress

By default MariaDB is not secured, so you will need to secure it first. You can do this by running mysql_secure_installation script:

sudo mysql_secure_installation

Answer all the questions as shown below:

Set root password? [Y/n] n
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

Once you have finished, login to MariaDB console with the following command:

mysql -u root -p

Enter your MariaDB root password and hit Enter. After login, create a database for WordPress:

MariaDB [(none)]>CREATE DATABASE wordpress;
MariaDB [(none)]>GRANT ALL PRIVILEGES on wordpress.* to 'user'@'localhost' identified by 'password';
MariaDB [(none)]>FLUSH PRIVILEGES;
MariaDB [(none)]>exit

Installing and Configuring WordPress

You can download the latest version of the WordPress source from the official website. You can get the latest version of WordPress by running the following command:

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

Once download is finished, extract the downloaded file with the following command:

tar -xzvf latest.tar.gz

Next, move the extracted files to the Apache web root directory:

sudo cp -avr wordpress/* /var/www/html/

Next, create a directory for WordPress to store uploaded files:

sudo mkdir /var/www/html/wp-content/uploads

Next, assign proper ownership and permissions to your WordPress files and folders:

sudo chown -R apache:apache /var/www/html/
sudo chmod -R 755 /var/www/html/

Next, you will need to make some changes in the WordPress main configuration file, so it can be connected with the database and user.

First, rename and edit the WordPress main configuration file:

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

Change the DB_NAME, DB_USER, and DB_PASSWORD variables as shown below:

define('DB_NAME', 'wordpress');
define('DB_USER', 'user');
define('DB_PASSWORD', 'password');

Save and close the file when you are finished.

Accessing WordPress Web Installation Wizard

Before starting, you will need to allow access to the Apache ports using firewalld.

You can do this by running the following command:

sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload

Next, open your web browser and type the URL http://your-server-ip. You should see the following page:

WordPress language selection

Select language as per your need and click on Continue button, you should see the following page:

WordPress site info page

Fill out all the required site information and click on Install WordPress button. You should see the WordPress default dashboard as below:

WordPress dashboard page

Once installation is completed, you can login WordPress by typing the URL http://your-server-ip/wp-login.php? on your web browser. You should see the WordPress login page as below:

WordPress login page

Next, provide username and the password which you have created earlier and click on Log In button, you should see the following page:

WordPress dashboard

Summary

Congratulations! You have successfully installed WordPress on CentOS 7. I hope you have now enough knowledge to host your own WordPress blog easily. Feel free to comment below if you have any questions.

Source : How to Install and Configure WordPress on CentOS 7 | ProfitBricks DevOps Central

How To Install WordPress On CentOS 7 Linux | Unixmen

Today, we will learn how we can install WordPress on our CentOS 7 Linux distribution.

Why CentOS?

CentOS Linux is a community-supported distribution derived from sources freely provided to the public by Red Hat for Red Hat Enterprise Linux (RHEL). As such, CentOS Linux aims to be functionally compatible with RHEL. The CentOS Project mainly changes packages to remove upstream vendor branding and artwork. CentOS Linux is no-cost and free to redistribute. Each CentOS version is maintained for up to 10 years (by means of security updates — the duration of the support interval by Red Hat has varied over time with respect to Sources released). A new CentOS version is released approximately every 2 years and each CentOS version is periodically updated (roughly every 6 months) to support newer hardware. This results in a secure, low-maintenance, reliable, predictable and reproducible Linux environment.

You can download CentOS from here. You can directly download the ISO file format disk image from here.

What is WordPress?

WordPress is an open source website creation tool or content management system (CMS) based on PHP and MySQL. Matt Mullenweg and Mike Little programmed WordPress back on 2003. This is the most easiest static (can be developed for dynamic also) website content management system (or CMS) that exists.

WordPress is a free and license under GPLv2 (or later) from the Free Software Foundation. According to a survey report, WordPress was used by more than 23.3% of the top 10 million websites. WordPress is one of the most popular blogging system used on the Web.

It supports

  • Different free & paid themes for different different UI & UX
  • Plugins for different services & functionalities
  • Mobiles (Responsive views)
  • Multi-user & multi-blogging

To know more about WordPress, visit this link. To download latest WordPress from here.

Prerequisites

To install WordPress, we will need these following thing that needs to be installed or available on our CentOS 7 Linux server.

  • Apache or Nginx as web server
  • PHP version 5.6 or greater
  • MySQL / MariaDB version 5.6 or greater as database

Legacy or older version of PHP & MySQL can drive WordPress but not recommended from their official page.

Also, make sure your firewall / iptables or SELinux is not blocking any port(s) which is required over here or you don’t have any problem with proper user permission.

To disable SELinux, type the following

setenforce 0

Let’s update the CentOS 7 Linux server first. This is a good practise to keep your server up to date. To do so, issue the below command one after another and wait till it gets updated. It will depends on your internet speed and it will take a long. So, please have patience.

sudo yum clean all
sudo yum -y update

You will see something like below image once you are done with it. Depending on how old your system softwares are or which packages are needs to be updated. The below image indicates an successful update and may require to reboot system as well.

yumupdatedcentos7

Installing Apache as web server

To install Apache on your CentOS 7, issue the below command on your terminal.

sudo yum -y install httpd

This will download and install Apache as a web server on the system.

Let’s start Apache by issuing the below command.

sudo systemctl start httpd

Set Apache at start or booting time so after every reboot, it get started automatically without manual start.

sudo systemctl enable httpd

Test Apache

To test apache issue the below command.

sudo systemctl status httpd

This will show the status of Apache for you.

Or you can open a web browser and type “localhost” without the double quote in to the address bar. You will see something like this.

testing_apache_centos7

It indicates that our web server up and running ?

You may need to enable mod_rewrite module as well. Just open the file located on /etc/httpd/conf/httpd.conf by your faviourute file editor and change the following line

AllowOverride None

to

AllowOverride All

We are done with Apache.

Installing MySQL / MariaDB

To install MySQL / MariaDB on to your system, issue the below command.

sudo yum install mariadb-server mariadb

This will download and install MySQL / MariaDB on to the system.

To start the MariaDB server, issue the below command.

sudo systemctl start mariadb

Now, we need to set the password for the “root” user of MySQL / MariaDB. Let’s do it by typing the following and this is must for security reason.

sudo mysql_secure_installation

You will see something like this. Hit Y to continue and type a complex password and remember it.

CentOS7_security

After setting the root password, you will see something like below image.

afterrootpasswordCentOS7

Now, you will get few prompts on your terminal with Y/N options.

Hit Y for the prompt “Remove anonymous users?”

Hit Y for the prompt “Disallow root login remotely?”

Hit Y for the prompt “Remove test database and access to it?”

Hit Y for the prompt “Reload privilege tables now?”

After finishing all the prompts, you will see something like below.

finishmariadbCentOS7

We are done with MySQL / MariaDB.

Installing PHP 

To install PHP, open a terminal and issue the below command.

sudo yum -y install php php-mysql php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl

This will download and install PHP on your CentOS 7 system along with some others PHP modules which are required for WordPress.

Installing phpMyAdmin

To install phpMyAdmin, issue the below command in the terminal.

sudo yum -y install epel-release

And then issue the below command again.

sudo yum -y install phpmyadmin

After installing PHP, we need to restart the Apache or other web server in order to work with PHP. Type the following to do so.

sudo systemctl restart httpd.service

To test whether you can access phpMyAdmin or not, open any web browser and type the following in the address bar.

localhost/phpmyadmin

You will see something like this.

phpmyadminCentOS7

We are done installing PHP.

Installing WordPress

Download the latest WordPress from here. Or use the below command to download it.

sudo wget https://wordpress.org/latest.zip

After downloading the zip archive file, let’s unzip it by typing the below command on the terminal.

sudo unzip latest.zip

After successful unzipping, you will see a folder named “wordpress”. Now, copy this “wordpress” folder to the /var/www/html folder path by doing the following.

sudo cp -avr wordpress /var/www/html

Now, move to the /var/www/html folder and issue the below two commands.

sudo chmod -R 775 wordpress
sudo chown apache:apache wordpress

Now, type the following in your web browser address bar.

localhost/wordpress

You will see the below image. Click “Let’s go!” for continue.

1stwordpresscentos7

After clicking “Let’s go!” button, you will see something like this.

wordpresssetp2centos7

Now, we need to create a database with a name whatever you wish for installing WordPress.

Let’s create the database then. To do so, open the web browser and type the following.

localhost/phpmyadmin

Then it will ask for a user name & password. Type “root” as user name and the password that you had set earlier while installing MySQL/ MariaDB. I hope that you can remember that. Once you are logged in, you will see something like this.

phpmyadmincenos7

Now click New from the left top corner marked as red in the following image.

phpmyadmincenos7step2

After clicking New, you will see this. Type a database name and click “Create” button. Here, I am typing iftekher for my database name. You can type whatever you wish.

creatingdbcentos7

We are done creating our database for installing WordPress.

Now move back to the WordPress installation.

Type the database name as iftekher (As I set iftekher as my database name), user name as root, root password and leave database host and table prefix as it is. It should look like below image. Click submit button to continue.

settingupcentos7

After this, you will see a similar image like below and you need to click “Run the install” button.

runthecentos7

Then, you will see a welcome screen just like below asking for your WordPress site title, user name, password which are related to your WordPress site. Type your the site title, type admin as user name and choose a hard password and enter your email address and click “Install WordPress”.

welcomewpcentos7

Then you will get a message that WordPress has been successfully installed on your CentOS7.

Now, type the following in your web browser address bar and you will see something like this.

localhost/wordpress

livewpcentos7

So we are done with installing WordPress on our CentOS 7 Linux server.

Have a great day.

Source : How To Install WordPress On CentOS 7 Linux | Unixmen