【CentOS实用篇】之编译LAMP安装wordpress

系统版本:CentOS 6.9

软件包

apr-1.6.2.tar.gz
apr-util-1.6.0.tar.gz
httpd-2.4.27.tar.bz2
mariadb-5.5.57-linux-x86_64.tar.gz
php-5.6.31.tar.bz2
wordpress-4.8.1-zh_CN.zip

编译安装httpd

准备工作
编译软件需要用到开发包组Development tools,在编译httpd中,会依赖openssl-devel pcre-devel expat-devel三个devel包,提前安装,避免过程中报错。

[root@6mini ~]# yum groupinstall "Development tools"
[root@6mini ~]# yum install openssl-devel pcre-devel expat-devel

解压apr-1.6.2.tar.gz、apr-util-1.6.0.tar.gz和httpd-2.4.27.tar.bz2,复制apr-1.6.2到httpd-2.4.27,并改名为apr,复制apr-util-1.6.0到httpd-2.4.27,并改名为apr-util

[root@6mini ~]# tar xvf apr-1.6.2.tar.gz 
[root@6mini ~]# tar xvf apr-util-1.6.0.tar.gz 
[root@6mini ~]# tar xvf httpd-2.4.27.tar.bz2 

编译安装httpd,配置环境变量

[root@6mini httpd-2.4.27]# ./configure --prefix=/app/httpd24 
--enable-so --enable-ssl --enable-rewrite --with-zlib --with-pcre 
--with-included-apr --enable-modules=most 
--enable-mpms-shared=all --with-mpm=prefork
[root@6mini httpd-2.4.27]# make -j 2 && make install

[root@6mini httpd-2.4.27]# vim /etc/profile.d/lamp.sh
PASH=/app/httpd24/bin/:$PASH

[root@6mini httpd-2.4.27]# . /etc/profile.d/lamp.sh
[root@6mini httpd-2.4.27]# echo $PASH
/app/httpd24/bin/:

制作httpd启动程序
复制其他主机上httpd的启动程序到当前主机并改名为httpd24

[root@MiniLinux ~]#scp /etc/init.d/httpd 192.168.163.105:/etc/init.d/
The authenticity of host '192.168.163.105 (192.168.163.105)' can't be established.
RSA key fingerprint is b5:df:3d:28:80:8e:d4:81:3b:f2:56:81:77:6d:7d:8a.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.163.105' (RSA) to the list of known hosts.
root@192.168.163.105's password: 
httpd                                                      100% 3488     3.4KB/s   00:00

[root@6mini httpd-2.4.27]# mv /etc/init.d/httpd /etc/init.d/httpd24

启动httpd24
修改httpd24的启动配置文件

[root@6mini httpd-2.4.27]#vim /etc/init.d/httpd24

apachectl=/app/httpd24/bin/apachectl
httpd=${HTTPD-/app/httpd24/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/app/httpd24/logs/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd24}

把httpd24添加到服务列表

[root@6mini httpd-2.4.27]#chkconfig --add httpd24
[root@6mini httpd-2.4.27]#chkconfig --list
auditd          0:off   1:off   2:on    3:on    4:on    5:on    6:off
blk-availability    0:off   1:on    2:on    3:on    4:on    5:on    6:off
crond           0:off   1:off   2:on    3:on    4:on    5:on    6:off
httpd24         0:off   1:off   2:off   3:off   4:off   5:off   6:off

关闭防火墙和selinux

[root@6mini httpd-2.4.27]#iptables -F
[root@6mini httpd-2.4.27]#iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination   

[root@6mini httpd-2.4.27]#vim /etc/selinux/config
SELINUX=disabled
[root@6mini httpd-2.4.27]#setenforce 0
[root@6mini httpd-2.4.27]#getenforce 
Permissive

检查/app/httpd24/logs/是否生成

[root@6mini httpd-2.4.27]#ll /app/httpd24/logs/
total 8
-rw-r--r--. 1 root root   0 Oct 16 16:37 access_log
-rw-r--r--. 1 root root 246 Oct 16 16:37 error_log
-rw-r--r--. 1 root root   6 Oct 16 16:37 httpd.pid

使用curl检查httpd是否能正常使用

[root@6mini httpd-2.4.27]#curl 192.168.163.105
<html><body><h1>It works!</h1></body></html>

二进制安装mariadb

解压二进制安装包到/usr/local/目录,把解压后的mariadb目录改名为mysql或者创建一个名为mysql的软连接

[root@6mini local]#tar xvf mariadb-5.5.57-linux-x86_64.tar.gz -C /usr/local/
[root@6mini ~]#cd /usr/local/
[root@6mini local]#ls
bin  etc  games  include  lib  lib64  libexec  mariadb-5.5.57-linux-x86_64  sbin  share  src
[root@6mini local]#ln -s mariadb-5.5.57-linux-x86_64/ mysql
[root@6mini local]#ls
bin  games    lib    libexec                      mysql  share
etc  include  lib64  mariadb-5.5.57-linux-x86_64  sbin   src

编辑环境变量的配置文件,在文件中添加mysql环境变量

[root@6mini local]#vim /etc/profile.d/lamp.sh 
PASH=/app/httpd24/bin/:/usr/local/mysql/bin/:$PASH
[root@6mini local]#. /etc/profile.d/lamp.sh 
[root@6mini local]#echo $PASH
/app/httpd24/bin/:/usr/local/mysql/bin:/app/httpd24/bin/:

创建mysql用户,指定家目录为 /app/mysqldb,用户类型为系统用户

[root@6mini local]#useradd -r -m -d /app/mysqldb -s /sbin/nologin mysql
[root@6mini local]#getent passwd mysql
mysql:x:498:498::/app/mysqldb:/sbin/nologin

[root@6mini app]#ll -d mysqldb/
drwx------. 2 mysql mysql 4096 Oct 16 17:10 mysqldb/

运行scripts/mysql_install_db脚本,生成mysql文件,指定目录为/app/mysqldb/,指定用户为mysql

[root@6mini mysql]#scripts/mysql_install_db --datadir=/app/mysqldb/ --user=mysql
[root@6mini mysqldb]#ll /app/mysqldb/
total 32
-rw-rw----. 1 mysql mysql 16384 Oct 16 17:21 aria_log.00000001
-rw-rw----. 1 mysql mysql    52 Oct 16 17:21 aria_log_control
drwx------. 2 mysql root   4096 Oct 16 17:21 mysql
drwx------. 2 mysql mysql  4096 Oct 16 17:21 performance_schema
drwx------. 2 mysql root   4096 Oct 16 17:21 test

创建mysql配置文件

[root@6mini mysql]#mkdir /etc/mysql
[root@6mini mysql]#cp support-files/my-large.cnf /etc/mysql/my.cnf
[root@6mini mysql]#vim /etc/mysql/my.cnf
[mysqld]
datadir = /app/mysqldb
innodb_file_per_table = ON
skip_name_resolve = ON

复制mysql启动的服务进程文件到/etc/init.d/,并该名称mysql添加到服务列表

[root@6mini mysql]#cp support-files/mysql.server /etc/init.d/mysqld
[root@6mini mysql]#chkconfig --add mysqld

创建日志文件,并赋予mysql的写权限

[root@6mini mysql]#touch /var/log/mysqld.log
[root@6mini mysql]#chown mysql /var/log/mysqld.log
[root@6mini mysql]#ll /var/log/mysqld.log 
-rw-r--r--. 1 mysql root 0 Oct 16 17:39 /var/log/mysqld.log

启动mysql

[root@6mini mysql]#service mysqld start
Starting MySQL.171016 17:41:04 mysqld_safe Logging to '/var/log/mysqld.log'.
171016 17:41:04 mysqld_safe Starting mysqld daemon with databases from /app/mysqldb
.. SUCCESS! 

使用mysql_secure_installation初始化数据库

[root@6mini bin]#mysql_secure_installation
/usr/local/mysql/bin/mysql_secure_installation: line 393: find_mysql_client: command not found

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

使用root登录数据库,为workpress创建数据库,并授权给用户wpu

[root@6mini bin]#mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 5.5.57-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> CREATE DATABASE wpdb;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> GRANT ALL ON wpdb.* TO wpu@'%' IDENTIFIED BY 'centos';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> QUIT
Bye

使用wpu用户登录数据库,查看并确认数据库wpdb的生成

[root@6mini bin]#mysql -uwpu -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 5.5.57-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| wpdb               |
+--------------------+
2 rows in set (0.00 sec)

MariaDB [(none)]> 

源码编译php

编译安装php之前,首先安装php的依赖包libxml2-devel bzip2-devel libmcrypt-devel,再进行编译安装

[root@6mini ~]#yum install libxml2-devel bzip2-devel libmcrypt-devel
[root@6mini ~]#tar xvf php-5.6.31.tar.bz2 
[root@6mini ~]#cd php-5.6.31
[root@6mini php-5.6.31]# ./configure --prefix=/app/php --with-mysql=/usr/local/mysql/ --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-png-dir --with-jpeg-dir --with-freetype-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/app/httpd24/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2

[root@6mini php-5.6.31]# make -j 2 && make install

复制一个php的配置文件,直接改名,不用设置

[root@6mini php-5.6.31]#cp php.ini-production /etc/php.ini

编辑httpd的配置文件,使httpd支持php

[root@6mini php-5.6.31]#vim /app/httpd24/conf/httpd.conf

<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

</Directory>
#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    DirectoryIndex index.php index.html

测试php程序
首先启动httpd24,在主目录里编辑php测试页进行测试

[root@6mini php-5.6.31]#service httpd24 restart
Stopping httpd:                                            [  OK  ]
Starting httpd: AH00557: httpd: apr_sockaddr_info_get() failed for 6mini
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
                                                           [  OK  ]
[root@6mini php-5.6.31]#vim /app/httpd24/htdocs/index.php
<?php
phpinfo();
?>

使用浏览器查看php网页

配置wordpress

解压wordpress到httpd主目录,并改名为blog

[root@6mini ~]#unzip wordpress-4.8.1-zh_CN.zip -d /app/httpd24/htdocs/
[root@6mini ~]#cd /app/httpd24/htdocs
[root@6mini htdocs]#mv wordpress/ blog

利用wordpress的配置模板生成配置文件,并修改数据库的信息,确保数据库正常使用

[root@6mini htdocs]#cd blog/
[root@6mini blog]#mv wp-config-sample.php wp-config.php 
[root@6mini blog]#vim wp-config.php 

<?php
/**
 * WordPress基础配置文件。
 *
 * 这个文件被安装程序用于自动生成wp-config.php配置文件,
 * 您可以不使用网站,您需要手动复制这个文件,
 * 并重命名为“wp-config.php”,然后填入相关信息。
 *
 * 本文件包含以下配置选项:
 *
 * * MySQL设置
 * * 密钥
 * * 数据库表名前缀
 * * ABSPATH
 *
 * @link https://codex.wordpress.org/zh-cn:%E7%BC%96%E8%BE%91_wp-config.php
 *
 * @package WordPress
 */

// ** MySQL 设置 - 具体信息来自您正在使用的主机 ** //
/** WordPress数据库的名称 */
define('DB_NAME', 'wpdb');

/** MySQL数据库用户名 */
define('DB_USER', 'wpu');

/** MySQL数据库密码 */
define('DB_PASSWORD', 'centos');

/** MySQL主机 */
define('DB_HOST', 'localhost');

浏览器登录并配置wordpress站点

http://192.168.163.105/blog

安装完成

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,692评论 6 501
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,482评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 162,995评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,223评论 1 292
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,245评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,208评论 1 299
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,091评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,929评论 0 274
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,346评论 1 311
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,570评论 2 333
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,739评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,437评论 5 344
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,037评论 3 326
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,677评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,833评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,760评论 2 369
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,647评论 2 354

推荐阅读更多精彩内容

  • 一、LAMP环境的介绍 1.LAMP环境的重要性 思索许久,最终还是决定写一篇详细的LAMP的源码编译安装的实验文...
    endmoon阅读 2,614评论 4 26
  • 1、确认搭建LAMP所需的环境是否已经安装: [root@localhost ~]#rpm -q make gcc...
    4e855d444c9f阅读 463评论 0 0
  • php+mysql+apache+centos 编译安装 领导要求先保证php环境稳定,然后再去考虑其他,例如性能...
    dnaEMx阅读 2,199评论 1 16
  • 一、配置防火墙,开启80端口、3306端口 CentOS 7.0默认使用的是firewall作为防火墙,这里改为i...
    ArleyDu阅读 2,088评论 0 0
  • 离别时 你说的话还在耳畔萦绕 你的背影渐渐消失在我的眼眸 走得那么决绝 我还没有告诉你: 最后一刻其实我还没有走 ...
    君末寒笑阅读 288评论 8 6