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
浏览器访问,这里使用命令行测试一下
二、安装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端口)
② 找到directory参数,在require all denied
前面添加#
,然后添加require all granted
<directory /> allowoverride none #require all denied require all granted </directory>
③ 找到directoryindex index.html
,将它替换为directoryindex index.php index.html
<ifmodule dir_module> directoryindex index.php index.html </ifmodule>
④ 添加支持的类型
addtype application/x-httpd-php .php addtype application/x-httpd-php-source .phps
⑤添加一个php的测试页
vim /usr/local/httpd24/htdocs/index.php <?php phpinfo(); ?>
5、重启apache服务,访问php测试页,ip:端口
要确保上面的测试页可以访问再继续部署网站
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或者域名
这里用的是4433端口所以访问时要带端口 x.x.x.x:4433
按照提示继续安装即可
推荐阅读
-
从零学习node.js之利用express搭建简易论坛(七)
-
基于Windows 7(本地)和CentOS7.6(云端)的Minecraft服务器(无Forge/有Forge)搭建方法
-
LNMP小项目搭建,Centos7.6环境搭建Linux+nginx+mysql+php,wordpress个人博客的搭建(完整搭建步骤)
-
从零学习node.js之利用express搭建简易论坛(七)
-
LAMP平台部署及论坛搭建
-
解答:建设企业论坛有何好处?怎么样快速搭建呢?
-
lamp论坛搭建
-
从零开始 教你如何搭建Discuz!4.1论坛(图)
-
阿里云ecs centos7.6 开发环境搭建
-
LAMP架构搭建详解与论坛的部署