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

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

centos7.3实现基于源码编译安装LAMP的wordpress应用_第1张图片
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页面是否正常

centos7.3实现基于源码编译安装LAMP的wordpress应用_第2张图片
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

DirectoryIndex index.php index.html


[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 

LAMP

2 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.登陆并测试性能

centos7.3实现基于源码编译安装LAMP的wordpress应用_第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)

你可能感兴趣的:(centos7.3实现基于源码编译安装LAMP的wordpress应用)