sudo apt update && sudo apt install apache2
sudo ufw app list
output:
Available applications:
Apache
Apache Full
Apache Secure
OpenSSH
添加防火墙规则:
sudo ufw allow in "Apache Full"
激活防火墙:
sudo ufw enable
查看防火墙状态:
sudo ufw status
output:
Status: active
To Action From
-- ------ ----
Apache Full ALLOW Anywhere
Apache Full (v6) ALLOW Anywhere (v6)
sudo service apache2 status
output:
● apache2.service - LSB: Start/stop apache2 web server
Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled)
Active: active (running) since Thu 2020-02-06 19:48:48 CST; 4min 16s ago
Docs: man:systemd-sysv-generator(8)
Tasks: 55
Memory: 2.3M
CPU: 124ms
CGroup: /system.slice/apache2.service
├─4141 /usr/sbin/apache2 -k start
├─4144 /usr/sbin/apache2 -k start
└─4145 /usr/sbin/apache2 -k start
Feb 06 19:48:46 ecs-sn3-medium-2-linux-20191115143253 systemd[1]: Starting LSB: Start/stop apache2 web server...
Feb 06 19:48:46 ecs-sn3-medium-2-linux-20191115143253 apache2[4115]: * Starting web server apache2
Feb 06 19:48:48 ecs-sn3-medium-2-linux-20191115143253 apache2[4115]: *
Feb 06 19:48:48 ecs-sn3-medium-2-linux-20191115143253 systemd[1]: Started LSB: Start/stop apache2 web server.
在浏览器中输入ip地址若打开Apache界面说明安装成功。
对了,按q
退出。
sudo apt install mysql-server
期间遇到了下面问题:
mysql-server : Depends: mysql-server-5.5 but it is not going to be installed
从网上找各种方法,最终只有一个管用,换源:
sudo vim /etc/apt/sources.list
将全部内容换成以下:
deb http://archive.ubuntu.com/ubuntu xenial main restricted universe
deb http://archive.ubuntu.com/ubuntu xenial-updates main restricted universe
deb http://security.ubuntu.com/ubuntu xenial-security main restricted universe multiverse
deb http://archive.canonical.com/ubuntu xenial partner
vim删除全部命令:“ :0,$d ”
一路Enter
,安完测试一下:
sudo service mysql status
如果output如下,说明安装成功:
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2020-02-06 20:27:43 CST; 2min 44s ago
Main PID: 10158 (mysqld)
CGroup: /system.slice/mysql.service
└─10158 /usr/sbin/mysqld
Feb 06 20:27:42 ecs-sn3-medium-2-linux-20191115143253 systemd[1]: Starting MySQL Community Server...
Feb 06 20:27:43 ecs-sn3-medium-2-linux-20191115143253 systemd[1]: Started MySQL Community Server.
安装 phpmyadmin
:
sudo apt-get install phpmyadmin -y
sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin
sudo service mysql restart
sudo /etc/init.d/apache2 restart
sudo mysql_secure_installation
output:
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
Press y|Y for Yes, any other key for No:
回车后进行密码设置,同时一路y
走下去就设置好了。
sudo apt install php libapache2-mod-php php-mysql
看下php版本:
php -version
安装php扩展:
sudo apt install php-curl php-gd php-xml php-mbstring php-xmlrpc php-zip php-soap php-intl
重启Apache:
sudo systemctl restart apache2
sudo vim /var/www/html/info.php
添加代码:
浏览器输入:服务器IP/info.php
能看懂php的信息表示安装好了了。
登录mysql
:
mysql -u root -p
新建数据库DB
:
CREATE DATABASE DB DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
新建数据库管理员User
专门负责数据库DB
:
GRANT ALL ON DB.* TO ' User '@'localhost' IDENTIFIED BY '你的密码';
刷新一下:
FLUSH PRIVILEGES;
退出:
EXIT;
若你的服务器可以科学上网,按下面步骤,否则看下面的注意。
cd /tmp
curl -O https://wordpress.org/latest.tar.gz
解压文件:
tar xzvf latest.tar.gz
复制文件:
cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php
全部转移过来:
sudo rsync -avP /tmp/wordpress/. /var/www/html
建议转移到
html
下新建的一个文件夹中,这样就可以多创建几个网站了。
注意:
因为 wordpress.org
需要科学上网才能登录,而服务器不一定能把 wordpress
下载下来。所以,需要先科学上网去官网将压缩包下载到本地,通过 xftp
上传到服务器上。
官网下载
我下载好上传到 网盘下载
更改文件所有权,使Apache可以使用:
sudo chown -R www-data:www-data /var/www/html
赋予权限:
sudo find /var/www/html/ -type d -exec chmod 750 {} \;
sudo find /var/www/html/ -type f -exec chmod 640 {} \;
有关安全性的操作:
curl -s https://api.wordpress.org/secret-key/1.1/salt/
会得到一堆输出,复制下来,打开文件,删除里面相同的内容,替换进去:
sudo vim /var/www/html/wp-config.php
对应着二.2部分更改内容:
define('DB_NAME', 'DB');
define('DB_USER', 'User');
define('DB_PASSWORD', '你的密码');
define('DB_HOST', 'localhost');
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', '');
同时在文件最后添加:
define('FS_METHOD', 'direct');
重启apache和mysql:
systemctl restart apache2.service
systemctl restart mysql.service
添加配置文件:
sudo vim /etc/apache2/sites-available/000-default.conf
添加内容:
AllowOverride All
按下操作:
sudo a2enmod rewrite
sudo apache2ctl configtest
sudo systemctl restart apache2
重启Apache:
sudo service apache2 restart
注意: 将 /var/www/html
下的 index.html
删掉
在浏览器中输入:
https://服务器IP
然后使用wordpress界面进行安装就可以了。
Install and configure WordPress
解决mysql-server : Depends: mysql-server-5.5 but it is not going to be installed
Apache部署多个站点