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

 环境准备:

内网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论坛搭建_第1张图片

   二、安装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论坛搭建_第2张图片

 

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


    AllowOverride none
    #Require all denied
    Require all granted

CentOS7.6搭建LAMP-wordpress论坛搭建_第3张图片

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


    DirectoryIndex index.php index.html

 ④ 添加支持的类型

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

CentOS7.6搭建LAMP-wordpress论坛搭建_第4张图片

  ⑤添加一个php的测试页

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

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

CentOS7.6搭建LAMP-wordpress论坛搭建_第5张图片

 

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

 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

4433> ServerAdmin [email protected] DocumentRoot "/usr/local/httpd24/htdocs/wordpress" #ServerName www.wp.com ErrorLog "logs/wordpress-error_log" CustomLog "logs/wordpress-access_log" common

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论坛搭建_第6张图片

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

CentOS7.6搭建LAMP-wordpress论坛搭建_第7张图片

 

 按照提示继续安装即可

 

你可能感兴趣的:(CentOS7.6搭建LAMP-wordpress论坛搭建)