从零开始手动搭建一个Typecho
本文章实验环境是Centos 7.8,
不依赖任何一键脚本,从头开始搭建一个typecho
1.安装Nginx
yum install nginx -y
systemctl enable nginx --now
2.安装mariadb
yum install mysql mysql-devel mariadb-server -y
systemctl enable mariadb --now
[root@VM-12-8-centos ~]# mysql_secure_installation #初始化mariadb
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] Y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] Y
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] Y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] Y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
[root@VM-12-8-centos ~]# mysql -p 输入刚才设置的密码登陆,创建数据库
MariaDB [(none)]> CREATE DATABASE typecho; #创建用于typecho的数据库
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| typecho |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [(none)]>
3.PHP
sudo yum install epel-release yum-utils
sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm #配置PHP源,Centos7中,官方源只有5.4
yum install php php-fpm php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysqli php-mbstring #安装php,并安装mariadb,crul,mbstring扩展支持
4.安装Typecho本体
cd /var/www/html
wget https://github.com/typecho/typecho/releases/latest/download/typecho.zip
unzip typecho.zip
chown nginx:nginx www/ -R
配置nginx
首先注释掉/etc/nginx/nginx.conf中的server块,在/etc/nginx/conf.d/中创建一个新文件vhost.conf(非必要,可以直接在nginx.conf中配置)
server {
listen 80;
server_name www.ushio.ink;
return 301 https://$host$request_uri; #HTTPS重定向
}
server {
listen 443 ssl;
server_name www.ushio.ink;
ssl_certificate_key "***.key";
ssl_certificate "***.crt";
ssl_session_cache shared:SSL:1m;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
ssl_session_timeout 10m;
root /var/www/html;
index index.php;
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ .*\.php(\/.*)*$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_split_path_info ^(.+?.php)(/.*)$;
include fastcgi_params;
}
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php$1 last;
}
访问服务器
数据库名字密码填入mariadb中创建的,其他根据个人需要修改。至此,Typecho
若安装typecho向导出现上传目录无法写入, 请手动将安装目录下的 /usr/uploads 目录的权限设置为可写然后继续升级 这是由于上面将www文件夹所有权归给nginx用户,而php-fpm默认用户没有访问权限导致。以下解决方案是更改php-fpm的默认运行用户
vim /etc/php-fpm.d/www.conf # 在其中找到user,group并改为nginx