centos7.3实现基于源码编译安装LAMP的wordpress应用

Linux+Apache+Mysql/MariaDB+Perl/PHP/Python一组常用来搭建动态网站或者服务器的开源软件,本身都是各自独立的程序,但是因为常被放在一起使用,拥有了越来越高的兼容度,共同组成了一个强大的Web应用程序平台。随着开源潮流的蓬勃发展,开放源代码的LAMP已经与J2EE.Net商业软件形成三足鼎立之势,并且该软件开发的项目在软件方面的投资成本较低,因此受到整个IT界的关注。从网站的流量上来说,70%以上的访问流量是LAMP来提供的,LAMP是最强大的网站解决方案.

image.png

以上介绍均来自网络

【软件准备】
apr-1.6.2.tar.gz
apr-util-1.6.0.tar.gz
httpd-2.4.27.tar.bz2
php-7.1.10.tar.xz
mariadb-10.2.8-linux-x86_64.tar.gz
wordpress-4.8.1-zh_CN.tar.gz

【环境部署】
centos 7.3
192.168.1.110/24 httpd、php、apr、wordpress
192.168.1.107/24 mariadb

安装顺序:mariadb-->httpd-->php

【源码编译安装httpd2.4】

1.安装"development tools"开发包组等
[root@www ~/src]#yum groupinstall "development tools"
yum install openssl-devel expat-devel pcre-devel
2.解压apr可移植运行库等并编译安装
[root@www ~/src]#tar xvf apr-1.6.2.tar.gz
[root@www ~/src]#tar xvf apr-util-1.6.0.tar.gz
[root@www ~/src]#tar xvf httpd-2.4.27.tar.bz2
3.将apr复制入httpd-2.4.27/srclib并改名
[root@www ~/src]#cp -r apr-1.6.2 httpd-2.4.27/srclib/apr
[root@www ~/src]#cp -r apr-util-1.6.0 httpd-2.4.27/srclib/apr-util

4.进入httpd目录并执行编译安装

./configure --prefix=/app/httpd24 --sysconfdir=/etc/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@www ~/src/httpd-2.4.27]#make -j 4 && make install

5.设置httpd环境变量路径并启动

[root@www /app/httpd24/htdocs]#vim /etc/profile.d/lamp.sh
  1 PATH=/app/httpd24/bin/:$PATH
[root@www /app/httpd24/htdocs]#. /etc/profile.d/lamp.sh 
[root@www /app/httpd24/htdocs]#apachectl 
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

6.ss查看80端口是否开启

[root@www /app/httpd24/htdocs]#ss -tnl
State       Recv-Q Send-Q                     Local Address:Port                                    Peer Address:Port              
LISTEN      0      128                                    *:111                                                *:*                  
LISTEN      0      128                                    *:22                                                 *:*                  
LISTEN      0      128                            127.0.0.1:631                                                *:*                  
LISTEN      0      100                            127.0.0.1:25                                                 *:*                  
LISTEN      0      128                                   :::111                                               :::*                  
LISTEN      0      128                                   :::80                                                :::*                  
LISTEN      0      128                                   :::22                                                :::*                  
LISTEN      0      128                                  ::1:631                                               :::*                  
LISTEN      0      100                                  ::1:25                                                :::*  

7.测试html页面是否正常

image.png

【二进制安装mariadb】
安装编译前确保当前系统无数据库软件
[root@CentOS7 ~]#rpm -ql | grep mariadb
1.解压mariadb并指明路径/usr/local/
[root@CentOS7 ~]#tar xvf mariadb-10.2.8-linux-x86_64.tar.gz -C /usr/local/
2.创建软连接
[root@CentOS7 /usr/local]#ln -s mariadb-10.2.8-linux-x86_64/ mysql

3.创建数据库账户
[root@CentOS7 /usr/local]#useradd -r -m -d /app/mysqldb -s /sbin/nologin mysql

[root@CentOS7 /usr/local]#getent passwd mysql
mysql:x:997:995::/app/mysqldb:/sbin/nologin
[root@CentOS7 /usr/local]#ll /app/mysqldb/ -d
drwx------. 2 mysql mysql 62 Oct 11 15:12 /app/mysqldb/

4.运行数据库脚本,创建数据库文件

[root@CentOS7 /usr/local]#cd mysql/
[root@CentOS7 /usr/local/mysql]#scripts/mysql_install_db --datadir=/app/mysqldb --user=mysql

5.确认数据库正确生成

[root@CentOS7 /usr/local/mysql]#ls /app/mysqldb/
aria_log.00000001  ib_buffer_pool  ib_logfile0  mysql               test
aria_log_control   ibdata1         ib_logfile1  performance_schema

5.准备mysql配置环境文件并修改

[root@CentOS7 /usr/local/mysql]#cp support-files/my-large.cnf  /etc/mysql/my.cnf
[root@CentOS7 /usr/local/mysql]#vim /etc/mysql/my.cnf 
27 [mysqld]
28 datadir = /app/mysqldb  ##指定数据库路径
29 innodb_file_per_table = ON ##将表生成单独的一个文件
30 skip_name_resolve = ON  ##禁止主机名解析

6.准备服务脚本

[root@CentOS7 /usr/local/mysql]#cp support-files/mysql.server  /etc/init.d/mysqld
[root@CentOS7 /usr/local/mysql]#chkconfig --add mysqld
[root@CentOS7 /usr/local/mysql]#chkconfig --list

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off
netconsole      0:off   1:off   2:off   3:off   4:off   5:off   6:off
network         0:off   1:off   2:on    3:on    4:on    5:on    6:off

7.准备日志文件,否则将启动失败

[root@CentOS7 /usr/local/mysql]#mkdir /var/log/mariadb
[root@CentOS7 /usr/local/mysql]#chown mysql /var/log/mariadb/
[root@CentOS7 /usr/local/mysql]#service mysqld start
Starting mysqld (via systemctl):                           [  OK  ]
[root@CentOS7 /usr/local/mysql]#ss -ntl
State       Recv-Q Send-Q                     Local Address:Port                                    Peer Address:Port              
LISTEN      0      128                                    *:22                                                 *:*                  
LISTEN      0      100                            127.0.0.1:25                                                 *:*                  
LISTEN      0      80                                    :::3306                                              :::*                  
LISTEN      0      128                                   :::22                                                :::*                  
LISTEN      0      100                                  ::1:25                                                :::*              

8.添加环境变量

[root@CentOS7 /usr/local/mysql]#vim /etc/profile.d/lamp.sh
  1 PATH=/usr/local/mysql/bin/:$PATH
[root@CentOS7 /usr/local/mysql]#. /etc/profile.d/lamp.sh 

9.安全初始化,并登陆查看是否正确登陆
mysql_secure_installation

[root@CentOS7 ~]#mysql -uroot -pcentos
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 18
Server version: 10.2.8-MariaDB-log 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)]> 

10.创建wpdb数据库,并授权

MariaDB [(none)]> create database wpdb; 
MariaDB [(none)]> grant all on wpdb.* to wpuser@'192.168.1.%' identified by 'centos';
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> grant all on wpdb.* to  wpuser@'127.%' identified by 'centos';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> grant all on wpdb.* to wpuser@'localhost' identified by 'centos';
Query OK, 0 rows affected (0.00 sec)

【源码编译安装php】
1.安装php前准备包组
yum install libxml2-devel bzip2-devel libmcrypt-devel

2.解压php
[root@www ~/src]#tar xvf php-7.1.10.tar.xz

3.编译并安装

./configure \
--prefix=/app/php \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-openssl \
--with-pdo-mysql=mysqlnd \
--enable-mbstring \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-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 \
--enable-maintainer-zts \
--disable-fileinfo

[root@www ~/src/php-7.1.10]#make -j 8 && make install 

4.为php准备配置文件
[root@www ~/src/php-7.1.10]#cp php.ini-production /etc/php.ini

5.编辑apache 配置文件httpd.conf ,以使apache 支持php,在文件尾部添加两行,并重启服务

[root@www /app/httpd24/htdocs]#cd /app/httpd24/htdocs/

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>

[root@www /app/httpd24/htdocs]#apachectl stop
[root@www /app/httpd24/htdocs]#apachectl restart

【测试php和mariadb连接】
1.配置index.php确保成功连接数据库

[root@www /app/httpd24/htdocs]#vim index.php 
  1 <html><body><h1>LAMP</h1></body></html>
  2 <?php
  3 $mysqli=new mysqli("192.168.1.107","wpuser","centos");
  4 if(mysqli_connect_errno()){
  5 echo "连接数据库失败!";
  6 $mysqli=null;
  7 exit;
  8 }
  9 echo "连接数据库成功!";
 10 $mysqli->close();
 11 phpinfo();
 12 ?>                 

2.测试页面

【配置wordpress】
1.解压wordpress并将其改名

[root@www /app/httpd24/htdocs]#unzip wordpress-4.8.2.zip 
[root@www /app/httpd24/htdocs]#cp -r  wordpress /app/httpd24/htdocs/ 
[root@www /app/httpd24/htdocs]#mv wordpress/ blog/
[root@www /app/httpd24/htdocs]#ll
total 8
drwxr-xr-x 5 root root 4096 Oct 11 12:44 blog
-rw-r--r-- 1 root root  249 Oct 11 12:35 index.php

2.wordpress修改config配置文件

[root@www /app/httpd24/htdocs/blog]#vim wp-config.php 
22 /** The name of the database for WordPress */
 23 define('DB_NAME', 'wpdb');
 24 
 25 /** MySQL database username */
 26 define('DB_USER', 'wpuser');
 27 
 28 /** MySQL database password */
 29 define('DB_PASSWORD', 'centos');
 30 
 31 /** MySQL hostname */
 32 define('DB_HOST', '192.168.1.107');

3.登陆并测试性能

image.png
[root@CentOS6 ~]#ab -c 10 -n 100 http://192.168.1.110/blog/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.1.110 (be patient).....done


Server Software:        Apache/2.4.27
Server Hostname:        192.168.1.110
Server Port:            80

Document Path:          /blog/
Document Length:        0 bytes

Concurrency Level:      10
Time taken for tests:   1.945 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Non-2xx responses:      100
Total transferred:      35500 bytes
HTML transferred:       0 bytes
Requests per second:    51.41 [#/sec] (mean)
Time per request:       194.505 [ms] (mean)
Time per request:       19.451 [ms] (mean, across all concurrent requests)
Transfer rate:          17.82 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.5      0       3
Processing:    54  185  33.7    184     307
Waiting:       52  185  33.8    183     307
Total:         57  186  33.6    185     308
ERROR: The median and mean for the initial connection time are more than twice the standard
       deviation apart. These results are NOT reliable.

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

推荐阅读更多精彩内容

  • 1.LAMP介绍  LAM(M)P:L: linuxA: apache (httpd)M: mysql, mar...
    尛尛大尹阅读 1,022评论 0 1
  • 1 概述 LAMP 目前在CentOS6不支持php-fpm的安装,安装高版本的数据库在centos6上也需要通过...
    ghbsunny阅读 346评论 0 0
  • 1、确认搭建LAMP所需的环境是否已经安装: [root@localhost ~]#rpm -q make gcc...
    4e855d444c9f阅读 437评论 0 0
  • 一、LAMP环境的介绍 1.LAMP环境的重要性 思索许久,最终还是决定写一篇详细的LAMP的源码编译安装的实验文...
    endmoon阅读 2,542评论 4 26
  • 文/王大懒 前段时间,我在追old先的《19天》,虽然漫画的更新速度真的很慢,但是追过火影的人对这点小打小闹是不会...
    王大勤阅读 1,587评论 0 0