LAMP环境安装WordPress

WEB应用程序基础套件

  • 操作系统(linux)
  • WEB服务器(Apache Nginx)
  • 数据库(MySQL MariaDB PostgreSQL)
  • 应用开发语言(python php perl)

大量开源应用基于LAMP开发

  • wordpress
  • wiki
  • owncloud
  • phpmyadmin

安装LAMP(Linux + Apache + MySQL + PHP)

  • 手动安装

    1
    2
    3
    4
    5
    6
    7
    sudo apt install apache2
    sudo apt install mysql-server
    sudo apt install php libapache2-mod-php php-mysql


    # 测试
    echo "<?php phpinfo();?>" >> /var/www/html/info.php
  • 自动安装

    1
    2
    3
    4
    5
    # 首先安装tasksel    它会自动打包安装软件
    sudo apt install tasksel

    sudo tasksel # 选择想要安装的服务

WordPress介绍

  • 开源免费的个人博客系统
  • 全球1/3的个人博客采用
  • 基于LAMP开发
  • 开箱即用的个人建站首选

安装:

1
2
wget http://wordpress.org/latest.tar.gz
tar -xvf latest.tar.gz -C /var/www/html/

创建数据库

1
2
3
4
create database wpdb;
create user 'wpuser'@'localhost' identified by 'password';
grant all on wpdb.* to 'wpuser'@'localhost';
flush privileges;

修改配置文件

1
2
3
4
5
cd /var/www/html/wordpress/
cp wp-config-sample.php wp-config.php

sudo vi wp-config.php
# 修改库名 用户名 密码

虚拟主机

1
2
3
4
5
6
7
cd /etc/apache2/sites-available/
sudo cp 000-default.conf myblog.conf
sudo vi myblog.conf
# 编辑配置文件

ServerName www.myblog.com
DocumentRoot /var/www/html/wordpress/

启用站点

1
2
3
4
5
6
sudo a2ensite myblog.conf
sudo a2dissite 000-default.conf

# 重启服务
sudo systemctl reload apache2.sercice
sudo systemctl restart apache2.service

之后访问 http://www.myblog.com,进入WordPress管理界面,进行设置。

PhpMyAdmin

  • 基于WEB应用的MySQL管理应用

修改身份验证方式

1
2
select user,host,plugin from mysql.user;

安装PhpMyAdmin

1
sudo apt install phpmyadmin

修改apache2配置文件

1
2
3
4
sudo vi /etc/apache2/apache2.conf

# 读取phpmyadmin,增加如下配置
Include /etc/phpmyadmin/apache.conf

然后重启

1
sudo systemctl restart apache2

这样就可以使用通过 web界面来管理数据库了 输入http://172.16.216.129/phpmyadmin/

安装prestashop 电商平台

  • 开源免费的电商平台系统
  • 全球有25万电商平台使用
  • 基于LAMP套件

安装依赖包

1
sudo apt install php7.2-gd php7.2-xml php7.2-curl php7.2-zip

下载:

1
2
3
4
5
6
wget https://download.prestashop.com/download/releases/prestashop_1.7.6.2.zip

sudo unzip prestashop_1.7.6.2.zip -d /var/www/html/myshop/

# 设置权限
sudo chown www-data:www-data -R myshop/

创建库

1
2
3
4
create database myshop;
create user'myshopuser'@'localhost' identified by 'password';
grant all on myshop.* to 'myshopuser'@'localhost';
flush privileges;

配置

1
2
3
4
5
6
7
8
9
10
11
12
cd /etc/apache2/sites-available
cp 000-defult.conf myshop.conf

sudo vi myshop.conf
# 编辑配置文件
ServerName www.myshop.com
DocumentRoot /var/www/html/myshop/

sudo a2enmod rewirte # 加载rewrite模块
sudo a2ensite myshop.conf
sudo systemctl reload apache2
sudo systemctl restart apache2

LEMP环境安装NextCloud网盘

安装LEMP(Linux + Nginx + MySQL + PHP)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
sudo apt install nginx
sudo apt install mariadb-server mariadb-client

mysql_secure_installation

# LEMP必装模块:
sudo apt install php7.2 php7.2-fpm php7.2-mysql

# 安装nextcloud应用所需的模块
sudo apt install php7.2-mbstring php7.2-xml php7.2-gd php7.2-curl php-imagick php7.2-zip php7.2-bz2 php7.2-intl

# 修改配置文件
sudo vi /etc/php/7.2/fpm/php.ini
# 启用配置,修改时区
cgi.fix_pathinfo=0
date.timezone = Asia/Shanghai

配置Nginx

1
2
3
4
5
6
7
8
9
sudo vi /etc/nginx/sites-available/default
# 编写配置文件
index index.php
loaction ~\.php$ {
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
include snippets/fastcgi-php.conf;
}

测试

1
2
3
4
5
6
cd /var/www/html

sudo vi info.php

# 写入
<?php phpinfo();?>

下载NextCloud

1
2
3
4
5
wget https://download.nextcloud.com/server/releases/nextcloud-17.0.1.zip
sudo unzip nextcloud-17.0.1.zip -d /var/www/html/nextcloud/

# 更改权限
sudo chown www-data:www-data /var/www/html/nextcloud/ -R

创建库

1
2
3
4
create database cloud;
create user user@localhost identified by 'password';
grant all privileges on cloud.* to user@localhost identified by 'password';
flush privileges;

自签名证书

1
sudo openssl req -x509 -days 365 -sha256 -newkey rsa:2048 -nodes -keyout /etc/ssl/private/cloud.key -out /etc/ssl/certs/cloud.pem

配置Nginx文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
cd /etc/nginx/sites-available/

# 新建配置文件
sudo vi mycloud.conf
# 写入配置
server {
listen 80;
server_name www.mycloud.com;
return 301 https://www.mycloud.com$request_uri;
}

server {
listen 443 ssl http2;
ssl_certificate /etc/ssl/certs/cloud.pem;
ssl_certificate_key /etc/ssl/private/cloud.key;

add_header Strict-Transport-Security "max-age=31536000" always;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;

root /var/www/html/nextcloud/;

location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}

location = /.well-known/carddav {
return 301 $scheme://$host/remote.php/dav;
}
location = /.well-known/caldav {
return 301 $scheme://$host/remote.php/dav;
}

location ~ /.well-known/acme-challenge {
allow all;
}

client_max_body_size 512M;
fastcgi_buffers 64 4K;

gzip off;

error_page 403 /core/templates/403.php;
error_page 404 /core/templates/404.php;

location / {
rewrite ^ /index.php$uri;
}

location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {
deny all;
}
location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
deny all;
}

location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[34])\.php(?:$|/) {
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param modHeadersAvailable true;
fastcgi_param front_controller_active true;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_intercept_errors on;
fastcgi_request_buffering off;
}

location ~ ^/(?:updater|ocs-provider)(?:$|/) {
try_files $uri/ =404;
index index.php;
}

location ~* \.(?:css|js)$ {
try_files $uri /index.php$uri$is_args$args;
add_header Cache-Control "public, max-age=7200";
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;
access_log off;
}

location ~* \.(?:svg|gif|png|html|ttf|woff|ico|jpg|jpeg)$ {
try_files $uri /index.php$uri$is_args$args;
access_log off;
}
}



sudo ln -s /etc/nginx/sites-available/mycloud.conf /etc/nginx/sites-enabled/mycloud.conf

创建储存数据的目录

1
2
3
# 建议不要将data文件夹放于nextcloud目录中
sudo mkdir /var/www/html/data
sudo chown www-data:www-data -R /var/www/html/data/

web界面的配置

1
2
3
先设置域名  http://www.mycloud.com

在界面设置用户名、密码、数据库名 储存数据目录

安装客户端:

1
2
sudo add-apt-repository ppa:next-cloud-devs/client
sudo apt install nextcloud-client

基于web的远程管理和监控系统

cockpit

  • 基于web的远程管理应用
  • 将所有组件打包在一起
  • 不依赖单独部署的LAMP或LEMP
  • 可以通过一个web页面管理多台服务器

安装:

1
sudo apt install cockpit cockpit-docker

访问方式:

1
http://yourdomain.com:9090

官网地址:https://cockpit-project.org/

Netdata

  • 基于web建构的Linux系统 实时性能监视工具
  • 监控CPU、内存、硬盘、网络、进程、硬件
  • 占用系统资源少
  • 实时告警

安装依赖包

1
sudo apt install git zlib1g-dev uuid-dev libmnl-dev gcc make autoconf autoconf-archive autogen automake pkg-config curl python python-yaml python-mysqldb python-psycopg2 nodejs lm-sensors netcat

安装:

1
2
3
4
5
6
7
bash <(curl -Ss https://my-netdata.io/kickstart.sh)

# 或者
bash <(curl -Ss https://my-netdata.io/kickstart-static64.sh)

# 访问:
http://yourdomain.com:19999

页面展示: