lnmp搭建个人博客centos7
1. nginx的安装
使用的是yum的安装所以首先要保证虚拟机有网络,前边博客有写nginx安装,这里就直接写安装过程
第一步:
vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
第二步:
yum -y install nginx
第三步:
useradd www -s /sbin/nologin -M
sed -i '/^user/c user www;' /etc/nginx/nginx.conf
grep "^user" /etc/nginx/nginx.conf
第四步:
systemctl start nginx
systemctl enable nginx
2. MySQL(mariadb)安装
第一步:
yum install mariadb-server mariadb -y
第二步:启动数据库
systemctl strat mariadb
systemctl enable mariadb
第三步:设置密码
参数说明
/application/mysql/bin/mysqladmin -u root password 'new-password' --- 给本地数据库设置密码
/application/mysql/bin/mysqladmin -u root -h web01 password 'new-password' --- 给远程数据库设置密码
mysqladmin -uroot password 123456
登录:
mysql -uroot -p123456
[root@web02 17:27:44 /var/log/nginx]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.68-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
3. php安装
第一步:更新yum源,卸载自带的php
yum remove php-mysql php php-fpm php-common
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
第二步安装:
yum install -y php71w php71w-cli php71w-common php71w-devel php71w-embedded php71w-gd php71w-mcrypt php71w-mbstring php71w-pdo php71w-xml php71w-fpm php71w-mysqlnd php71w-opcache php71w-pecl-memcached php71w-pecl-redis php71w-pecl-mongodb
第三步:编写配置文件
vim /etc/php-fpm.d/www.conf
user = www nginx---www
group = www
PS: 保证nginx进程的管理用户和php服务进程的管理用户保持一致
第四步: 启动php服务
systemctl start php-fpm
[root@web02 17:33:46 /var/log/nginx]# systemctl start php-fpm
[root@web02 17:33:53 /var/log/nginx]# ps -ef |grep php
root 10950 1 0 17:33 ? 00:00:00 php-fpm: master process (/etc/php-fpm.conf)
www 10951 10950 0 17:33 ? 00:00:00 php-fpm: pool www
www 10952 10950 0 17:33 ? 00:00:00 php-fpm: pool www
www 10953 10950 0 17:33 ? 00:00:00 php-fpm: pool www
www 10954 10950 0 17:33 ? 00:00:00 php-fpm: pool www
www 10955 10950 0 17:33 ? 00:00:00 php-fpm: pool www
root 10963 9532 0 17:34 pts/2 00:00:00 grep --color=auto php
4. lnmp之间建立联系(只是测试,可以直接第五步)
4.1 nginx与php
server {
listen 80;
server_name blog.yq.com;
location / {
root /html/blog;
index index.php index.html;
}
location ~ \.php$ {
root /html/blog;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
}
}
编写动态资源文件
cat /html/blog/test_php.php
<?php
phpinfo();
?>
访问测试:
blog.yq.com/test_php.php
4.2 php与mysql之间建立关系
编写文件
vim test_mysql.php
<?php
$servername = "localhost";
$username = "root";
$password = "123456";
$link_id=mysql_connect('主机名','用户','密码');
$conn = mysqli_connect($servername, $username, $password);
if ($conn) {
echo "mysql successful by root !\n";
}else{
die("Connection failed: " . mysqli_connect_error());
}
?>
5. 博客的搭建(第四步只是测试,可以直接第五步)
5.1blog网站页面:
https://cn.wordpress.org/
下载上传到站点目录
解压:
tar xf wordpress-5.8.1-zh_CN.tar.gz
移动到/html/blog目录下
mv wordpress/* blog/
修改目录属主属组
[root@web02 17:58:16 /html]# chown -R www.www blog/
[root@web02 17:58:19 /html]# ll blog/
total 208
-rw-r--r-- 1 www www 405 Feb 6 2020 index.php
-rw-r--r-- 1 www www 19915 Jan 1 2021 license.txt
-rw-r--r-- 1 www www 7346 Jul 6 20:23 readme.html
-rw-r--r-- 1 www www 7165 Jan 21 2021 wp-activate.php
drwxr-xr-x 9 www www 4096 Sep 17 16:00 wp-admin
-rw-r--r-- 1 www www 351 Feb 6 2020 wp-blog-header.php
-rw-r--r-- 1 www www 2328 Feb 17 2021 wp-comments-post.php
-rw-r--r-- 1 www www 3004 May 21 18:40 wp-config-sample.php
drwxr-xr-x 5 www www 69 Sep 17 16:00 wp-content
-rw-r--r-- 1 www www 3939 Jul 31 2020 wp-cron.php
drwxr-xr-x 25 www www 8192 Sep 17 16:00 wp-includes
-rw-r--r-- 1 www www 2496 Feb 6 2020 wp-links-opml.php
-rw-r--r-- 1 www www 3900 May 16 01:38 wp-load.php
-rw-r--r-- 1 www www 45463 Apr 7 02:39 wp-login.php
-rw-r--r-- 1 www www 8509 Apr 14 2020 wp-mail.php
-rw-r--r-- 1 www www 22297 Jun 2 07:09 wp-settings.php
-rw-r--r-- 1 www www 31693 May 8 04:16 wp-signup.php
-rw-r--r-- 1 www www 4747 Oct 9 2020 wp-trackback.php
-rw-r--r-- 1 www www 3236 Jun 9 2020 xmlrpc.php
5.2 配饰文件的设置
nginx的配置文件
vim /etc/nginx/conf.d/blog.conf
server {
listen 80;
server_name blog.yq.com;
location / {
root /html/blog;
index index.php index.html;
}
location ~ \.php$ {
root /html/blog;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
}
}
systemctl restart nginx
5.3 网站的配置
上边的步骤好了,打开浏览器访问:
blog.yq.com
前提你要配置hosts
访问:
192.168.246.8 blog.yq.com
选择中文,现在就开始
下一步:
这里我们要创建数据库;授权一个用户
mysql -uroot -p123456
create database wordpress;
grant all on wordpress.* to wordpress@'localhost' indentified by '123456';
MariaDB [(none)]> select user,host from mysql.user;
+-----------+-----------+
| user | host |
+-----------+-----------+
| root | 127.0.0.1 |
| root | ::1 |
| | localhost |
| root | localhost |
| wordpress | localhost |
| | web02 |
| root | web02 |
+-----------+-----------+
7 rows in set (0.00 sec)
创建好了数据库之后,填写
下一步:
下一步:
安装WordPress:
根据自己的账号面登录即可: