欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

CentOS7.6搭建LAMP-wordpress论坛搭建

程序员文章站 2022-03-16 21:36:41
环境准备: 内网IP:192.168.0.36 软件包版本/下载地址: mysql软件包: wget https://dev.mysql.com/get/Downloads/mysql-5.6.24.tar.gzapache软件包: wget https://mirrors.aliyun.com/a ......

 环境准备:

内网ip:192.168.0.36

软件包版本/下载地址:

mysql软件包:
wget https://dev.mysql.com/get/downloads/mysql-5.6.24.tar.gz
apache软件包:
       wget https://mirrors.aliyun.com/apache/httpd/httpd-2.4.38.tar.gz        wget https://mirrors.aliyun.com/apache/apr/apr-1.6.5.tar.gz        wget https://mirrors.aliyun.com/apache/apr/apr-util-1.6.1.tar.gz
php软件包:        wget http://cn2.php.net/get/php-7.0.32.tar.bz2/from/this/mirror

 

 一、搭建apache

1、下载httpd、apr、apr-utils 软件包:

2、解压软件包并编译安装apache服务

① 解压软件包,把apr和apr-utils移动到httpd目录下的srclib文件夹下,一起进行编译

tar xf apr-util-1.6.1.tar.gz 
tar xf apr-1.6.5.tar.gz 
tar xf httpd-2.4.38.tar.gz 
mv apr-1.6.5 httpd-2.4.38/srclib/apr
mv apr-util-1.6.1 httpd-2.4.38/srclib/apr-util

②  安装相关的依赖包、库文件等

yum groupinstall -y "development tools"  && yum install libtool  expat-devel pcre pcre-devel openssl-devel -y

③ 检查编译环境、并安装

./configure --prefix=/usr/local/apache24 \
--enable-ssl \
--enable-so \
--with-mpm=event \
--with-included-apr \
--enable-cgi \
--enable-rewrite \
--enable-mods-shared=most \
--enable-mpms-shared=all && make -j6 && make install

3、添加httpd的环境变量

echo "export path=$path:/usr/local/apache24/bin" > /etc/profile.d/httpd.sh
source /etc/profile.d/httpd.sh

4、添加apache的启动配置文件

vim /usr/lib/systemd/system/httpd.service
[unit] description=the apache http server after=network.target [service] type=forking execstart=/usr/local/apache24/bin/apachectl -k start execreload=/usr/local/apache24/bin/apachectl -k graceful execstop=/usr/local/apache24/bin/apachectl -k graceful-stop pidfile=/usr/local/apache24/logs/httpd.pid privatetmp=false [install] wantedby=multi-user.target

因为添加或修改了启动文件所以需要先加载一下,再进行启动

systemctl daemon-reload && systemctl start httpd
# 查看一下apache的80端口是否监听了
# 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 128 :::80 :::* listen 0 128 :::22 :::* listen 0 100 ::1:25 :::*

这里修改一下监听端口,修改为4433,因为80端口需要备案才可以从外网进行访问

vim /usr/local/apache24/conf/httpd.conf 
52 listen 4433
202 servername localhost:4433    # servername不修改启动时会有提醒,但是不影响启动和访问

重启httpd服务

systemctl restart httpd

浏览器访问,这里使用命令行测试一下

CentOS7.6搭建LAMP-wordpress论坛搭建

   二、安装mysql服务

1、安装依赖插件库文件

yum install -y  ncurses-devel bison gnutls-devel cmake 

2、准备mysql数据存放目录,创建mysql用户

mkdir -p /data/mysql 
groupadd -r mysql
useradd -r -g mysql -s /sbin/nologin mysql

3、运行以下命令更改数据目录属主和属组

chown -r mysql:mysql  /data/mysql

4、解压软件包,检查编译环境、编译安装

tar xvf mysql-5.6.24.tar.gz -c  /usr/local/src/
cd /usr/local/src/mysql-5.6.24
cmake . -dcmake_install_prefix=/usr/local/mysql56 \
-dmysql_datadir=/mnt/data \
-dsysconfdir=/etc \
-dwith_innobase_storage_engine=1 \
-dwith_archive_storage_engine=1 \
-dwith_blackhole_storage_engine=1 \
-dwith_readline=1 \
-dwith_ssl=system \
-dwith_zlib=system \
-dwith_libwrap=0 \
-dmysql_tcp_port=3306 \
-ddefault_charset=utf8 \
-dmysql_unix_addr=/usr/local/mysql/mysql.sock \
-ddefault_collation=utf8_general_ci \
-dwith_systemd=1 \
-dinstall_systemd_unitdir=/usr/lib/systemd/system && make -j6 && make install

5、修改安装目录的属主属组为mysql

chown -r mysql:mysql /usr/local/mysql56/

6、初始化数据库并复制配置文件

cd /usr/local/mysql56/
/usr/local/mysql56/scripts/mysql_install_db --user=mysql --datadir=/data/mysql
mv /etc/my.cnf /etc/my.cnf.bak
cp /usr/local/mysql56/support-files/my-default.cnf /etc/my.cnf

7、修改配置文件中的安装路径及数据目录存放路径

echo -e "basedir = /usr/local/mysql56\ndatadir = /data/mysql\n" >> /etc/my.cnf

8、修改mysql的启动配置文件

vim /usr/lib/systemd/system/mysql.service

[unit]
description=mysql community server
after=network.target
after=syslog.target

[install]
wantedby=multi-user.target
alias=mysql.service

[service]
user=mysql
group=mysql
permissionsstartonly=true
execstart=/usr/local/mysql56/bin/mysqld
timeoutsec=600
restart=always
privatetmp=false

9、设置mysql的path环境变量

echo "export path=$path:/usr/local/mysql56/bin" > /etc/profile.d/mysql.sh
source /etc/profile.d/mysql.sh

10、启动mysql服务并设置开机自启动

systemctl daemon-reload && systemctl enable mysql
systemctl start mysql 

11、修改mysql的root用户密码

mysqladmin -u root password

12、测试登录mysql数据库

mysql -uroot -p 

三、安装php环境

1、安装相关的依赖包

yum install -y libmcrypt libmcrypt-devel mhash mhash-devel libxml2 libxml2-devel bzip2 bzip2-devel 

2、下载php的软件包

wget http://cn2.php.net/get/php-7.0.32.tar.bz2/from/this/mirror

重命名一下

cp mirror php-7.0.32.tar.bz2

解压软件包

tar xf php-7.0.32.tar.bz2 -c /usr/local/src/ && echo ok

3、编译安装php7.0.32

说明:若ecs实例规格内存较小,配置时可关闭不需要的php扩展,节省内存。例如,在./configure命令中添加--disable-fileinfo选项,关闭fileinfo扩展

cd /usr/local/src/php-7.0.32
./configure --prefix=/usr/local/php7 \
--with-config-file-scan-dir=/etc/php.d \
--with-apxs2=/usr/local/httpd24/bin/apxs \
--with-config-file-path=/etc \
--with-pdo-mysql=mysqlnd \--enable-mbstring \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--with-openssl \
--enable-xml \
--enable-sockets \
--enable-fpm \
--with-bz2 && make -j6 && make install

拷贝php的配置文件

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

4、修改apache的配置文件

① 找到servername参数,添加servername localhost:4433  (这里web使用4433端口)

CentOS7.6搭建LAMP-wordpress论坛搭建

 

 ② 找到directory参数,在require all denied前面添加#,然后添加require all granted

<directory />
    allowoverride none
    #require all denied
    require all granted
</directory>

CentOS7.6搭建LAMP-wordpress论坛搭建

  ③ 找到directoryindex index.html,将它替换为directoryindex index.php index.html

<ifmodule dir_module>
    directoryindex index.php index.html
</ifmodule>

CentOS7.6搭建LAMP-wordpress论坛搭建

 ④ 添加支持的类型

addtype application/x-httpd-php .php
addtype application/x-httpd-php-source .phps

CentOS7.6搭建LAMP-wordpress论坛搭建

  ⑤添加一个php的测试页

vim /usr/local/httpd24/htdocs/index.php 
<?php
    phpinfo();
?>

5、重启apache服务,访问php测试页,ip:端口

CentOS7.6搭建LAMP-wordpress论坛搭建

 

要确保上面的测试页可以访问再继续部署网站

 apache虚拟主机,搭建wordpress站点

1、修改apache主配置文件

vim /usr/local/httpd24/conf/httpd.conf   找到虚拟主机,打开注释即可,或者在目录下新建虚拟主机的配置文件,然后在主配置文件中使用 include 引用

# virtual hosts
include conf/extra/httpd-vhosts.conf

2、编辑虚拟主机配置文件:

vim /usr/local/httpd24/conf/extra/httpd-vhosts.conf

<virtualhost *:4433> serveradmin xu@peter.com documentroot "/usr/local/httpd24/htdocs/wordpress" #servername www.wp.com errorlog "logs/wordpress-error_log" customlog "logs/wordpress-access_log" common </virtualhost>

3、解压wordpress论坛压缩包到刚刚虚拟主机中定义的目录下

cd /usr/local/httpd24/htdocs/
[root@server1 htdocs]# tar xf /usr/local/src/wordpress-5.0.4-zh_cn.tar.gz 

重启服务,然后浏览器访问ip或者域名

CentOS7.6搭建LAMP-wordpress论坛搭建

  这里用的是4433端口所以访问时要带端口 x.x.x.x:4433

CentOS7.6搭建LAMP-wordpress论坛搭建

 

 按照提示继续安装即可