Coder Social home page Coder Social logo

lamp-server's Introduction

A quick guide for setting up a CentOS-based LAMP stack webserver powered by WordPress

This is a quick guide for setting up LAMP stack and installing Wordpress on a CentOS machine. In order to follow this guide, you need to have access to CentOS machine either locally or remotely through ssh connection.

CentOS has long (10 years) release support. Each version of CentOS receives feature enhancements and new hardware support until 7 years, and security updates until 10 years after general availability. However, support for point releases (eg. CentOS 6.3) will be no longer available once a new point release (eg. CentOS 6.4) is available for the same version. At the time of this writing 7.3 is the latest version. However, 6.8 is the final point release for version 6. Hence, it is better use CentOS 6.8 since the final point release for version 7 is yet unknown. CentOS is available in two images: minimal and full DVD (contains all packages available for the respective version). The following instructions assume that you have installed the minimal version.

STEP 1: INITIAL SERVER SETUP

After a fresh install, it is recommended to install updates.

$ sudo yum update

You may want to change the root password. To do that run the following command.

$ sudo passwd root

The following instructions are optional. You can continue from STEP 2.

If you want to create a new user account, eg. john, then run this command.

$ sudo adduser john

Then you can set password for john (eg 123456) as follows

$ sudo passwd john 123456

Even though you login with john's credentials, you still need the root password in order to run some commands (eg. installing packages, making system configuration changes). You can avoid this by adding john into the sodoers group. The sudoers group name in CentOS is wheel.

$ sudo gpasswd -a john wheel

Now every time you run commands with sudo, you will not be prompted for the root password. Make sure that you use a strong password for any user (especially the ones that are in sudoers group).

Step 2: LAMP SERVER SETUP

In this step we will install and configure Apache HTTP server, PHP and MariaDB database server. MariaDB is an enhanced, drop-in replacement for MySQL database server. From now on, all commands need to be executed as root (or with sudo privilege). If you don't want to type sudo for ever command, then switch to the root user.

$ sudo su root

Now the command prompt sign changes from $ to #.

First, install Apache server

# yum install httpd

Start apache server

# systemctl start httpd.service

Enable apache to start on boot

# systemctl enable httpd.service

Configuration file for Apache is located at /etc/httpd/conf/httpd.conf. Open this file and search for "DocumentRoot". By default, you will see the following

DocumentRoot "/var/www/html/"

This means, Apache will serve websites that are hosted in /var/www/html directory. By default, if Apache doesn't find an index file (eg. index.html), it will show directory listing of all files in /var/www/html directory. This will expose all the files in this director to the public. In order to disable directory listing, open /etc/httpd/conf/httpd.conf file and within <Directory "/var/www/html"> directive, remove "Indexes" from the list of Options. Eg. If you find something like the following

Options Indexes, FollowSymLinks

then change it to

Options FollowSymLinks

i.e remove Indexes. You need to restart apache in order to apply configuration changes

# systemctl restart httpd.service

The next step is to install MariaDB database server.

# yum install mariadb-server mariadb

Start the database server

# systemctl start mariadb

By default, MySQL has EMPTY root password and comes with a test database. Run the following script and follow the instructions to override dangerous DEFAULT and lock down access to the database.

# mysql_secure_installation

Enable MariaDB to start on boot

# systemctl enable mariadb.service

Finally, install PHP

# yum install php php-mysql

Restart Apache

# systemctl restart httpd.service

STEP 3: INSTALL WORDPRESS

First, create database for wordpress. To do that, login to mysql server as a root

# mysql -u root -p

Then create a database. For example, the following command creates a database called wp

> CREATE DATABASE wp;

Then create a user account which Wordpress will use to access the database. For example, the following command creates an account with username wpUser and password wpPass123

> CREATE USER wpUser@localhost IDENTIFIED BY 'wpPass123';

Grant the user access to the database we created earlier.

> GRANT ALL PRIVILEGES ON wp.* TO wpUser@localhost IDENTIFIED BY 'wpPass123';

Flush privileges and close the connection.

> FLUSH PRIVILEGES;
> exit;

Install a module that allows wordpress to create tumbnails for uploaded images

# yum install php-gd
# systemctl restart httpd.service

Install wget which is used to download files from the command line. This is a handy tool when you configure your server remotely.

# yum install wget

Then download and extract latest Wordpress source files

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

Extracted files are located at wordpress folder in the current working directory. Copy files from wordpress/* to a directory where you want to host your website. By default, Apache serves files that are hosted in/var/www/html directory. In order to keep this directory clean, create a sub directory /var/www/html/wp and copy Wordpress files to this directory. Use rsyncto copy the files. This is because rsync keeps file permissions.

# mkdir /var/www/html/wp
# rsync -avP wordpress/ /var/www/html/wp

Create folder in wp to store uploaded files.

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

Grant ownership of all files in wp to Apache's user and group.

# chown -R apache:apache /var/www/html/wp/*

Create wordpress configuration file (Copy from the sample).

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

Open wp-config.php and change DB_NAME, DB_USER and DB_PASSWORD accordingly.

Now change Apache's document root directory to the one we created. To do that, open /etc/httpd/conf/httpd.conf and change Apache's document root as follows

DocumentRoot "/var/www/html/wp"

Finally, open a browser and type the server's IP address. If you have local server, then type http://localhost to the URL. Then finish the installation of WordPress throught the web browser.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.