在lamp基础上安装Wordpress

lamp简单介绍

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

今天,我们就来一起学习一下lamp的各种安装方法,并在此基础上搭建属于自己的个人博客。

下面的每个实验都可以成功搭建博客,任意选择一种即可。yum安装比较容易实现,自己编译软件可能会出错,请选择适合自己的方法。

实验:yum方式安装LAMP应用wordpress,php为模块方式

软件环境:
操作系统:CentOS6/7
两台主机,一台主机A:安装httpd,php,一台主机B:安装mariadb server
当然,也可以都安装在一台主机上

1 A:
yum httpd php php-mysql

vim /etc/php.ini
date.timezone = Asia/Shanghai

vim /etc/httpd/conf/httpd.conf
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>

systemctl restart httpd

vim /var/www/html/index.php
<?php
echo date("Y/m/d H:i:s");
phpinfo();
?>p

2 B
yum install mariadb-server
systemctl start  mariadb

mysql_secure_installation

mysql -uroot -pcentos
>grant all on  *.* to root@'172.17.1.%' identified by 'centos'; 

vim /var/www/html/index2.php 
<?php
$mysqli=new mysqli("localhost","root","centos");
if(mysqli_connect_errno()){
echo "连接数据库失败!";
$mysqli=null;
exit;
}
echo "连接数据库成功!";
$mysqli->close();


测试 http://websrv/

3 A上部署wordpress

mysql -uroot -pcentos -h172.17.1.177
> create database wpdb;
> grant all wpdb.* to wpuser@'172.17.1.%' identified by 'centos';
> flush privileges;

tar xvf wordpress-4.8.1-zh_CN.tar.gz 
cp -r  wordpress   /var/www/html/blog
cd /var/www/html/blog
cp wp-config-sample.php wp-config.php 
vim wp-config.php 
define('DB_NAME', 'wpdb');
define('DB_USER', 'wpuser');
define('DB_PASSWORD', 'centos');
define('DB_HOST', '172.17.1.166'); #这里写mysql服务器ip

测试http://websrv/blog/

实验:LAMP的fastcgi方式应用wordpress

软件环境:
操作系统:CentOS7
两台主机
一台A apache和php-fpm
一台B mariadb server

1
A:yum install httpd  php-fpm php-mysql
systemctl start httpd
systemctl start php-fpm 

B:yum install mariadb-server
systemctl start mariadb
mysql_secure_installation 
mysql -uroot -pcentos


2 A: vim /etc/httpd/conf.d/fcgi.conf 
DirectoryIndex index.php
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/html/$1

systemctl reload httpd

3 A上部署wordpress

mysql -uroot -pcentos
> create database wpdb;
> grant all wpdb.* to wpuser@'172.17.1.%' identified by 'centos';
> flush privileges;

tar xvf wordpress-4.8.1-zh_CN.tar.gz 
cp -r  wordpress   /var/www/html/blog
cd /var/www/html/blog
cp wp-config-sample.php wp-config.php 
vim wp-config.php 
define('DB_NAME', 'wpdb');
define('DB_USER', 'wpuser');
define('DB_PASSWORD', 'centos');
define('DB_HOST', '172.17.1.177');

4 测试性能
http://websrv/blog/

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

软件环境:
一台主机
apr-1.6.2.tar.gz
httpd-2.4.27.tar.bz2
php-7.1.10.tar.xz
apr-util-1.6.0.tar.gz
mariadb-10.2.8-linux-x86_64.tar.gz
wordpress-4.8.1-zh_CN.tar.gz

1 源码编译安装Httpd2.4
yum groupinstall "development tools"
yum install openssl-devel expat-devel pcre-devel 

tar xvf apr-1.6.2.tar.gz 
tar xvf apr-util-1.6.0.tar.gz 
tar xvf httpd-2.4.27.tar.bz2 
cp -r apr-1.6.2 httpd-2.4.27/srclib/apr
cp -r apr-util-1.6.0 httpd-2.4.27/srclib/apr-util
cd httpd-2.4.27/
./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
make -j 4 && make install

vim /etc/profile.d/lamp.sh
PATH=/app/httpd24/bin/:$PATH
. /etc/profile.d/lamp.sh
apachectl 
ss -tnl

2 二进制安装mariadb 
tar xvf mariadb-10.2.8-linux-x86_64.tar.gz  -C /usr/local/
cd /usr/local
ln -s mariadb-10.2.8-linux-x86_64/ mysql
useradd -r -m -d /app/mysqldb -s /sbin/nologin mysql 
cd mysql/
scripts/mysql_install_db --datadir=/app/mysqldb --user=mysql
mkdir /etc/mysql
cp support-files/my-large.cnf   /etc/mysql/my.cnf

vim /etc/mysql/my.cnf
[mysqld]
datadir = /app/mysqldb
innodb_file_per_table = ON
skip_name_resolve = ON

cp support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --list 
service mysqld start

mkdir /var/log/mariadb
chown mysql /var/log/mariadb/
service mysqld start

vi /etc/profile.d/lamp.sh 
PATH=/app/httpd24/bin/:/usr/local/mysql/bin/:$PATH
. /etc/profile.d/lamp.sh

mysql_secure_installation

mysql -uroot -pcentos
create datebase wpdb;
grant all on wpdb.* to wpuser@'172.17.1.%' identified by 'centos';
grant all on wpdb.* to wpuser@'127.%' identified by 'centos';
grant all on wpdb.* to wpuser@'localhost' identified by 'centos';

3 源码编译安装Php--模块方式
yum install libxml2-devel bzip2-devel libmcrypt-devel 
tar xvf php-7.1.10.tar.xz 
cd php-7.1.10/

./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 

make && make install

cp php.ini-production /etc/php.ini

vim /etc/httpd24/httpd.conf
在文件尾部加两行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
修改下面行
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>
apachectl stop
apachectl 

4 测试php和mariadb连接

vim /app/httpd24/htdocs/index.php 
<html><body><h1> LAMP</h1></body></html>
<?php
$mysqli=new mysqli("localhost","root","centos");
if(mysqli_connect_errno()){
echo "连接数据库失败!";
$mysqli=null;
exit;
}
echo "连接数据库成功!";
$mysqli->close();
phpinfo();
?>


5 配置wordpress

tar xvf wordpress-4.8.1-zh_CN.tar.gz  -C /app/httpd24/htdocs
cd /app/httpd24/htdocs
mv wordpress/ blog/

cd /app/httpd24/htdocs/blog/
cp wp-config-sample.php  wp-config.php
vim wp-config.php
define('DB_NAME', 'wpdb');

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

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

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

6 登录测试
http://websrv/blog 
测试性能
ab -c 10 -n 100 http://websrv/blog/

实验:CentOS6编译LAMP基于FPM模式的应用wordpress

软件版本
ls /root/src
apr-1.6.2.tar.gz      
apr-util-1.6.0.tar.gz  
httpd-2.4.28.tar.bz2 
mariadb-5.5.57-linux-x86_64.tar.gz  
php-5.6.31.tar.xz
wordpress-4.8.1-zh_CN.tar.gz
xcache-3.2.0.tar.gz

1
yum groupinstall "development tools"
yum install openssl-devel expat-devel pcre-devel bzip2-devel libxml2-devel libmcrypt-devel

2 编译httpd2.4
tar xvf apr-1.6.2.tar.gz 
tar xvf apr-util-1.6.0.tar.gz 
tar xvf httpd-2.4.28.tar.bz2 
mv apr-1.6.2 httpd-2.4.28/srclib/apr
mv apr-util-1.6.0 httpd-2.4.28/srclib/apr-util

cd /root/src/httpd-2.4.28
./configure --prefix=/app/httpd24 \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--with-included-apr \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=prefork

make -j 4 && make install

vim /etc/profile.d/lamp.sh
PATH=/app/httpd24/bin:/usr/local/mysql/bin/:/app/php/bin/:$PATH

 . /etc/profile.d/lamp.sh
 cp /etc/init.d/httpd  /etc/init.d/httpd24
vim /etc/init.d/httpd24
chkconfig --add httpd24
service httpd24 start

3 二进制安装mariadb-5.5.57
mkdir /app
useradd -d /app/mysqldb -r -m -s /sbin/nologin mysql
tar xf /root/mariadb-5.5.57-linux-x86_64.tar.gz -C /usr/local/
ln -s /usr/local/mariadb-5.5.57-linux-x86_64 /usr/local/mysql
cd /usr/local/mysql/
mkdir /etc/mysql/
cp support-files/my-huge.cnf  /etc/mysql/my.cnf
vim /etc/mysql/my.cnf
[mysqld]
datadir = /app/mysqldb  这一行必须添加
innodb_file_per_table = on 数据库引擎,每个表单独一个文件,不是必须要添加的,只是为了方便管理
skip_name_resolve = on  忽略名字解析,加快访问速度,这一行不是必须要添加的

scripts/mysql_install_db  --user=mysql --datadir=/app/mysqldb 
cp  support-files/mysql.server  /etc/init.d/mysqld
chkconfig --add mysqld
touch /var/log/mysqld.log
chown mysql  /var/log/mysqld.log
echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
service mysqld start
mysql_secure_installation   #安全初始化
#创建博客所需的数据库wpdb和账号wpuser
mysql -uroot -pcentos
> create database wpdb;
> grant all wpdb.* to wpuser@'192.168.37.%' identified by 'centos';
> flush privileges;

4 编译安装php-5.6.31 
tar xvf  php-5.6.31.tar.xz
cd /root/src/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-freetype-dir \
--with-jpeg-dir  \
--with-png-dir  \
--with-zlib  \
--with-libxml-dir=/usr \
--enable-xml \
--enable-sockets \
--enable-fpm \
--with-mcrypt  \
--with-config-file-path=/etc/php/  \
--with-config-file-scan-dir=/etc/php.d  \
--with-bz2

make -j 4 && make install 

cp php.ini-production /etc/php/php.ini
cp sapi/fpm/init.d.php-fpm  /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm 
chkconfig --add php-fpm

cp /app/php/etc/php-fpm.conf.default  /app/php/etc/php-fpm.conf 

service php-fpm start
ss -ntl


5 配置httpd支持php 
vim /app/httpd24/conf/httpd.conf
去掉下面两行注释
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

修改下面行
DirectoryIndexindex.phpindex.html

加下面四行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/app/httpd24/htdocs/$1

6 布署wordpress
tar xvf wordpress-4.8.1-zh_CN.tar.gz 
cp -r  wordpress   /app/httpd24/htdocs/blog
cd /app/httpd24/htdocs/blog
cp wp-config-sample.php wp-config.php 
vim wp-config.php 
define('DB_NAME', 'wpdb');
define('DB_USER', 'wpuser');
define('DB_PASSWORD', 'centos');
define('DB_HOST', '172.17.1.177');

ab 测试性能

7 编译安装xcache  #提高服务器上的 PHP 性能

tar xvf xcache-3.2.0.tar.gz 
cd xcache-3.2.0
./configure  --enable-xcache --with-php-config=/app/php/bin/php-config 
make && make install 
mkdir /etc/php.d/
cp xcache.ini  /etc/php.d/
ls /app/php/lib/php/extensions/no-debug-non-zts-20131226/
vim /etc/php.d/xcache.ini 
extension = /app/php/lib/php/extensions/no-debug-non-zts-20131226/xcache.so 修改此行

service php-fpm restart

8 测试
phpinfo() 确认xcache 已加载
ab 测试性能

在浏览器地址栏输入你的web服务器ip,我这次搭建的博客是在网站主目录下的blog目录,所以在地址栏内输入:172.17.1.177/blog/,回车,就可以看到下图,这时wordpress搭建完成,只需要注册一下站点标题,用户,密码,邮箱,最后点击“安装WordPress”
这里写图片描述

看到这张图代表你已经成功了!!
博客首页

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值