Linux学完lamp的架构之后,就可以搭建自己的博客了,搭建自己的博客有几个好处:
今天我们就来跟大家一起搭建一个属于自己的博客,之前我们学的都是yum安装,今天我们来使用编译安装lamp,编译安装的难度就算整个运维学习中最难的部分了。
如果这部分你都觉得不难,那基本没有什么可以难住你的技术了。
我使用的是:
华为云: 2核4G云服务器
域名 : www.zmkjedu.cn
系统:centos7
本次使用的架构是LAMP, 以后可以在升级
[root@ecs-c13b ~]# yum -y install make gcc gcc-c++ openssl openssl-devel expat-devel
[root@ecs-c13b ~]# wget http://archive.apache.org/dist/apr/apr-1.6.2.tar.gz
[root@ecs-c13b ~]# tar xf apr-1.6.2.tar.gz
[root@ecs-c13b ~]# cd apr-1.6.2
[root@ecs-c13b apr-1.6.2]# ./configure --prefix=/usr/local/apr
[root@ecs-c13b apr-1.6.2]# make && make install
[root@ecs-c13b ~]# wget http://archive.apache.org/dist/apr/apr-util-1.6.0.tar.gz
[root@ecs-c13b ~]# tar xf apr-util-1.6.0.tar.gz
[root@ecs-c13b ~]# cd apr-util-1.6.0
[root@ecs-c13b apr-util-1.6.0]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config
[root@ecs-c13b apr-util-1.6.0]# make && make install
[root@ecs-c13b ~]# tar xf pcre-8.41.tar.gz
[root@ecs-c13b pcre-8.41]# cd pcre-8.41
root@ecs-c13b pcre-8.41]# ./configure --prefix=/usr/local/pcre
root@ecs-c13b pcre-8.41]# ./configure --prefix=/usr/local/pcre
[root@ecs-c13b ~]# wget https://mirrors.aliyun.com/apache/httpd/httpd-2.4.43.tar.gz
[root@ecs-c13b ~]# tar xf httpd-2.4.43.tar.gz
[root@ecs-c13b ~]# cd httpd-2.4.43
[root@ecs-c13b httpd-2.4.43]#
[root@ecs-c13b httpd-2.4.43]# ./configure --prefix=/usr/local/apache --enable-so --enable-rewrite --enable-ssl --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre --enable-modules=most --enable-mpms-shared=all --with-mpm=event
选项说明:
参数 | 说明 |
---|---|
–prefix=/usr/local/apache | 安装路径 |
–enable-so | 支持动态加载模块 |
–enable-rewrite | 支持网站地址重写 |
–enable-ssl | 支持SSL加密 |
–with-pcre=/usr/local/pcre | pcre路径 |
–with-apr=/usr/local/apr | apr路径 |
–with-apr-util=/usr/local/apr-util | apr-util路径 |
[root@ecs-c13b httpd-2.4.43]# make && make install
配置文件路径: /usr/local/apache2/conf/httpd.conf
网站根目录: /usr/local/apache/htdocs/
root@ecs-c13b ~]# cp /usr/local/apache/bin/apachectl /etc/init.d/
[root@ecs-c13b ~]# chmod +x /etc/init.d/apachectl
[root@ecs-c13b ~]#
[root@ecs-c13b ~]# /etc/init.d/apachectl restart ## 启动方法一(简单快捷)
vim /usr/lib/systemd/system/apache.service
[Unit]
Description=apache
After=network.target
[Service]
Type=forking
ExecStart=/etc/init.d/apachectl start
ExecReload=/etc/init.d/apachectl restart
ExecStop=/etc/init.d/apachectl stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
systemctl start apache.service
[root@ecs-c13b ~]# lsof -i:80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
httpd 1579 root 4u IPv6 58850 0t0 TCP *:http (LISTEN)
httpd 1580 daemon 4u IPv6 58850 0t0 TCP *:http (LISTEN)
httpd 1581 daemon 4u IPv6 58850 0t0 TCP *:http (LISTEN)
httpd 1582 daemon 4u IPv6 58850 0t0 TCP *:http (LISTEN)
[root@ecs-c13b ~]#
[root@ecs-c13b ~]# wget http://www.mysql.com/Downloads/MySQL-5.7/mysql-5.7.19.tar.gz
MySQL从5.7版本之后,boost是必须的,建议把系统自带的boost库卸载,源码编译安装高版本
[root@ecs-c13b ~]# ls boost_1_59_0.tar.gz
boost_1_59_0.tar.gz
[root@ecs-c13b ~]# yum install -y cmake make gcc gcc-c++ bison ncurses ncurses-devel
[root@ecs-c13b ~]# groupadd mysql
[root@ecs-c13b ~]# useradd -M -s /sbin/nologin -r -g mysql mysql
[root@ecs-c13b ~]# tar xf boost_1_59_0.tar.gz -C /usr/local/src/
[root@ecs-c13b ~]# tar xf mysql-5.7.19.tar.gz -C /usr/local/src/
规划安装目录:
安装目录: /var/lib/mysql
数据目录: /var/lib/mysql/data
创建规划目录并给权限:
[root@ecs-c13b ~]# mkdir -p /var/lib/mysql/data
[root@ecs-c13b ~]# chown -R mysql:mysql /var/lib/mysql/
[root@ecs-c13b ~]#
进入相应目录
[root@ecs-c13b ~]# cd /usr/local/src/
[root@ecs-c13b src]# pwd
/usr/local/src
[root@ecs-c13b src]# cd mysql-5.7.19/
[root@ecs-c13b mysql-5.7.19]#
cmake:
cmake -DCMAKE_INSTALL_PREFIX=/var/lib/mysql \
-DMYSQL_DATADIR=/var/lib/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/local/src/boost_1_59_0
参数从哪里找:
http://www.mysql.com→→Documentation→→选择对应的版本(5.7)Installation & Upgrades→→Installing MySQL from Source →→MySQL Source-Configuration Options
直接点击url: https://dev.mysql.com/doc/refman/5.7/en/source-configuration-options.html
[root@ecs-c13b mysql-5.7.19]# make -j 4
[root@ecs-c13b mysql-5.7.19]# make install
[root@ecs-c13b ~]# cat /etc/my.cnf
[mysqld]
basedir=/var/lib/mysql
datadir=/var/lib/mysql/data
port=3306
socket=/var/lib/mysql/mysql.sock
character-set-server=utf8
log-error=/var/log/mysqld.log
pid-file=/tmp/mysqld.pid
[mysql]
socket=/var/lib/mysql/mysql.sock
[client]
socket=/var/lib/mysql/mysql.sock
[root@ecs-c13b ~]#
[root@ecs-c13b ~]# cat !$
cat /etc/profile.d/mysql.sh
export PATH=/var/lib/mysql/bin:$PATH
root@ecs-c13b ~]# . /etc/profile.d/mysql.sh
[root@ecs-c13b ~]# cp /var/lib/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@ecs-c13b ~]# chmod +x /etc/init.d/mysqld
[root@ecs-c13b ~]#
[root@ecs-c13b ~]# chown -R mysql:mysql /var/lib/mysql
[root@ecs-c13b ~]# /var/lib/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/var/lib/mysql --datadir=/var/lib/mysql/data
[root@ecs-c13b ~]# /etc/init.d/mysqld start
Starting MySQL.. ERROR! The server quit without updating PID file (/tmp/mysqld.pid).
[root@ecs-c13b ~]# cd /var/lib/mysql/data/
[root@ecs-c13b data]# ls
auto.cnf ib_buffer_pool ibdata1 ib_logfile0 ib_logfile1
[root@ecs-c13b data]# rm -rf ./*
[root@ecs-c13b data]# /var/lib/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/var/lib/mysql --datadir=/var/lib/mysql/data
[root@ecs-c13b data]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!
这里第一次启动失败了,然后删除data目录下的内容,重新初始化,之后启动成功
[root@ecs-c13b ~]# mysql
mysql> set password for root@localhost=password('12345678');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
[root@ecs-c13b ~]# wget http://jp2.php.net/distributions/php-7.1.24.tar.gz
[root@ecs-c13b ~]# yum -y install php-mcrypt libmcrypt libmcrypt-devel autoconf freetype gd libmcrypt libpng libpng-devel libjpeg libxml2 libxml2-devel zlib curl curl-devel re2c php-pear
[root@zmgaosh ~]# tar xf php-7.1.24.tar.gz -C /usr/local/src
[root@zmgaosh ~]# cd /usr/local/src/php-7.1.24/
[root@ecs-c13b php-7.1.24]# ./configure --prefix=/usr/local/php/ --with-apxs2=/usr/local/apache/bin/apxs --enable-mbstring --with-curl --with-gd --enable-fpm --enable-mysqlnd --with-pdo-mysql=mysqlnd --with-config-file-path=/usr/local/php/etc/ --with-mysqli=mysqlnd --with-mysql-sock=/var/lib/mysql/mysql.sock --enable-maintainer-zts
[root@ecs-c13b php-7.1.24]# make -j 4 && make install
root@ecs-c13b php-7.1.24]# cp php.ini-production /usr/local/php/etc/php.ini
编译apache配置文件,使其支持php
[root@ecs-c13b php-7.1.24]# vim /usr/local/apache/conf/httpd.conf
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
DirectoryIndex index.php index.html
[root@ecs-c13b php-7.1.24]# cd /usr/local/apache/htdocs/
[root@ecs-c13b htdocs]# pwd
/usr/local/apache/htdocs
[root@ecs-c13b htdocs]# vim index.php
[root@ecs-c13b htdocs]# /etc/init.d/apachectl restart
[root@ecs-c13b htdocs]# cat index.php
<?php
phpinfo();
?>
[root@ecs-c13b htdocs]# ls
index.html index.php wordpress-5.4.2-zh_CN.zip
[root@ecs-c13b htdocs]#
[root@ecs-c13b htdocs]# unzip wordpress-5.4.2-zh_CN.zip
[root@ecs-c13b blog]# mv wordpress blog
blog/wp-amdin/setup-config.php
这里在点击提交前,先创建一个数据库叫blog
[root@ecs-c13b blog]# mysql -p12345678
mysql> create database blog;
Query OK, 1 row affected (0.00 sec)
创建完后点击提交
[root@ecs-c13b blog]# vim wp-config.php
创建这个文件,然后把上图中的文本框内容复制进去
保存退出
然后点击现在安装
博客做完了,是不是花费了你将近一两个小时,下一篇文章我们开始设置域名