标签归档:LAMP

LAMP Stack for WordPress

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 to finish the installation.

在VMware上搭建LAMP平台部署WordPress

下面开始在虚拟机下配置LAMP服务器

20130101

用VMware虚拟机安装CentOS系统非常简单,这里省略掉安装过程,注意的是这里得选Bridged Network

20130102

由于被VMware自动识别为CentOS ,所以直接走了快速安装,界面也变成了英文。如果要进行语言切换可以在登录窗口下找到。

20130103

要既然是服务器,必须改变一些规则,主要是开放80端口和21端口。

20130104

更改一下连接方式,因为我是用的路由器,所以ip也改成了私网地址,ip的最后三位任意,不冲突即可,方便记忆我改成了111 。DNS服务器用的Google的两个(实在好记没办法)。

20130105

配置一下Apache服务器,设置为开机启动,只要上面的2~5现实为“启动”说明设置成功。这里也看得到修改后的ip地址。

yum install mysql*
yum install php-mysql
yum install mysql-server

三条yum命令安装MySQL,貌似第三条重复了,当时没注意。

20130106

设置启动MySQL数据库,然后为root账户添加密码(初始状态是没有密码的),改完后“\q”退出。

20130107

设置开机启动,同Apache。

20130108

安装php,用yum就是方便~ 到这一步为止,应该说LAMP的安装和配置就进行的差不多了,然后是安装phpMyAdmin数据库管理,和vsftpd (这个是FTP服务器)。

20130109

居然没法yum install phpmyadmin 。。。 只好去官网上下载 tar.gz源代码包。。。真是蛋疼 。下载完后tar解压。顺带说一句,这里的源代码包是用php写的,所以不用安装什么的。正常的源代码包安装应该的顺序是,先tar解压,然后找到一个./configure 文件进行配置,一般也就是./configure –prefix=/usr/local/softwarename , 然后make编译,然后make install安装。

20130110

用mv命令将得到的./phpMyAdmin/~/ 移动到 /var/www/html/phpmyadmin 下

20130111

上一步完成后,phpMyAdmin还并没有被配置好,需要创建配置文件。phpMyAdmin的配置比较特别,在文件目录下可以找到一个config.sample.inc.php的一个配置文件样例,然后所需要做的就是cp一份配置文件,命名为config.inc.php,然后用vi命令修改配置文件。

20130112

20130113

主要就是改个cookie然后加上用户名和密码(tips: 用:set nu可以显示行号方便查找)

20130114

改下权限(由于只是实验,所以直接改777了,真实条件下是肯定不能给这么高权限的,既然是实验就懒得深究了),事实证明给777是错误的,最后给的是755,下面会说明。 然后用vi命令更改SELinux配置文件,再次奉行懒人思想,直接把SELinux关了。SELinux是Linux的一个安全系统,在这里来说,就是会阻止对phpMyAdmin的访问,和等下对FTP服务器的访问。高级用户可以自行修改规则,我这样的还是直接关了比较简单。

20130115

直接改成disabled关了SELinux。

20130116

然后出错了,访问phpMyAdmin显示一片空白。。。发现是权限的问题,所以改成755

20130117

OK了,正常访问phpMyAdmin了,而且是用的主机(非虚拟机)的浏览器直接访问的http://192.168.1.111/phpmayadmin。可以访问同时说明Apache服务器配置是正确的。

20130118

然后配置FTP服务器,rpm发现没安装vsftpd ,然后果断yum 。 OK了,果然yum无脑一波流。。。

20130119

同理vsftpd开机启动,然后更改一下vsftpd的配置文件

20130120

这个配置很灵活,有许多选项,作为一个懒人,也懒得去改了。但是这个匿名用户访问必须关了,太危险。。到这里,整个服务器的配置算是结束了,下面挂一个WordPress上去试试看看能用不(tip: WordPress是一个基于PHP+MySQL平台的软件,主要用来搭设个人博客)

20130121

tar解压下载好的WordPress***.tar.gz ,然后得到一个wordpress目录,mv命令移动到html的blog目录下。为了防止出现问题,权限直接改777,懒人一波流~

20130122

首先需要创建一个数据库,有了phpMySQL就是方便,点一个创建就OK了,记下数据库名称blog001

20130123

直接访问http://192.168.1.111/blog ,该填的填好,WordPress其实挺无脑的。然后下一步下一步直到安装完成。这些步骤都是在虚拟机外的浏览器中完成的。

20130124

进入WordPress后台管理界面的时候,注意看下上面的地方是不是用的IP地址,上次弄的时候是用的localhost,结果虚拟机外访问的时候图片全挂。。。想来想去应该是路径问题,找了一下终于发现错误在这里

20130125

在WordPress操作中,可能要求连接到FTP服务器,由于刚才安装了vsftpd,所以比较简单了 。主机填ip地址,用户名的话,这里说明一下,默认的vsftpd由四个用户,root、henry(安装CentOS的时候创建的)、ftp、Anonymous。这四个用户前俩密码就是你的开机密码,后俩是系统用户,无密码。vsftpd设置规则里头,root是不能用作登录用户的,而刚才在配置FTP服务器的时候禁止了匿名访问,所以后头俩也是没用的,于是只能用很henry了。

20130126

内网正常访问,大功告成~~