1 安装Apache
安装Apache
sudo apt install apache2 libapache2-mod-fcgid -y /*安装*/
sudo systemctl start apache2.service /*启动*/
sudo systemctl enable apache2.service /*允许开机启动*/
sudo systemctl stop apache2.service /*停止*/
sudo systemctl status apache2.service /*查看状态*/
sudo systemctl restart apache2.service /*重启*/
设置工作目录
sudo vim /etc/apache2/sites-available/000-default.conf /*此文件中保存默认的站点配置*/
设置多站点
sudo vim /etc/apache2/sites-available/[newsite].conf /*建立配置文件*/
ln -s /etc/apache2/sites-available/[newsite].conf /etc/apache2/sites-enabled/[newsite].conf /*建立软连接*/
rm -rf /etc/apache2/sites-enabled/[newsite].conf /*移除配置文件*/
修改设置以后,重启服务以生效。
2 安装PHP(fpm)
安装php
sudo apt install -y php7.2 php7.2-fpm php7.2-mysqli php7.2-mbstring php7.2-zip php7.2-xml php7.2-gd
service php7.2-fpm start
配置Apache支持php-fpm
sudo a2enmod actions fcgid alias proxy_fcgi
sudo vim /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
……
<FilesMatch \.php$>
# 2.4.10+ can proxy to unix socket
SetHandler "proxy:unix:/var/run/php/php7.2-fpm.sock|fcgi://localhost/"
# Else we can just use a tcp socket:
#SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>
……
</VirtualHost>
sudo systemctl restart apache2
检查
sudo vim /var/www/html/phpinfo.php
<?php
phpinfo();
?>
浏览器访问之
PHP启闭模块
教程:https://tecadmin.net/enable-disable-php-modules-ubuntu/
phpenmod –开启模块
phpdismod –关闭模块
phpquery –显示模块状态
举例:
phpenmod mbstring
phpdismod mbstring
选项-v指定应用于特定的php版本,选项-s指定应用于全部php版本。(如果安装了多个版本)
3 MariaDB
安装MariaDB(MySQL)
sudo apt install mariadb-server /*安装*/
sudo systemctl start mariadb /*启动服务*/
sudo systemctl enable mariadb/*设置开机启动*/
sudo systemctl status mariadb /*查看服务状态,绿色的active (running) 为正在运行*/
sudo mysql_secure_installation /*安全设置,见“MariaDB的安全设置”*/
sudo mysql -u root -p /*登录root账户,命令与mysql相同*/
MariaDB的安全设置
[root@server ~]mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, 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 MySQL
root user without the proper authorisation.
Set root password? [Y/n] <– 是否设置root用户密码,输入y并回车或直接回车
New password: <– 设置root用户的密码
Re-enter new password: <– 再输入一次你设置的密码
Password updated successfully!
Reloading privilege tables..
… Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL 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] <– 是否删除匿名用户,生产环境建议删除,所以直接回车
… 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]<–是否禁止root远程登录,根据自己的需求选择Y/n并回车,建议禁止
… Success!
By default, MySQL 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] <– 是否删除test数据库,直接回车
- 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] <– 是否重新加载权限表,直接回车
… Success!
Cleaning up…
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
[root@server ~]#
重置root密码
忘记root密码以后,重置办法:
net stop mysql
mysqld --skip-grant-tables
保持该窗口。
重开一个cmd窗口,运行命令:
mysql
MariaDB [(none)]>use mysql
update user set password=password('123456') where user='root';
关掉第一个窗口,并杀掉其进程。
重新启动mysql:
net start mysql
使用新密码登陆。
建立远程管理用户
默认root只能本地登录,为了使用phpmyadmin,新建一个管理员用户,赋予最大权限。
服务器上本步省略。
CREATE USER '[username]'@'%' IDENTIFIED BY '[password]';
GRANT ALL PRIVILEGES ON *.* TO '[username]'@'%' IDENTIFIED BY '[password]' WITH GRANT OPTION;
FLUSH PRIVILEGES;
允许远程访问
mariadb默认只监听本地3306端口,为了远程访问需要修改设置。
vim /etc/mysql/mariadb.conf.d/50-server.cnf
第29行注释掉:
#bind-address = 127.0.0.1
重启服务
辅助:
netstat -an | grep 3306 /*查看3306端口监听情况*/
cd /etc/mysql
grep -rn "skip-networking" * /*查找设置项所在位置*/
4 使用phpMyAdmin
下载phpMyAdmin-4.8.2-all-languages.zip,上传到~/package。
cd ~/package
sudo unzip -o phpMyAdmin-4.8.2-all-languages.zip
sudo mv phpMyAdmin-4.8.2-all-languages /var/www/html/phpMyAdmin
配置文件现在需要一个短语密码
sudo vim /var/www/html/phpMyAdmin/libraries/config.default.php
$cfg['blowfish_secret'] = 'qwertyuiopasdfghjklzxcvbnm1234567890';
$cfg['TempDir'] (./tmp/) 读取失败且不能建立缓存
sudo chown -R www-data /var/www/html
5 安装Wordpress
- 准备数据库
sudo mysql -u root -p /*登录*/
/*以下命令在mysql提示符下执行*/
CREATE DATABASE [WordPressDir];
CREATE USER '[WordPressDir]'@'%' IDENTIFIED BY '[password]';
//这种写法会导致有一句失败,以后研究
GRANT select ON *.* TO '[WordPressDir]'@'%';
FLUSH PRIVILEGES;
GRANT all privileges ON ‘[WordPressDir]’.* TO '[WordPressDir]'@'%';
FLUSH PRIVILEGES;
/*查询是否成功*/
show databases;
use mysql;
show tables;
select user, host from user;
show grants for [WordPressDir];
6 安装Wordpress
下载wordpress-4.9.4.tar.gz,上传到~/package。
cd ~/package
tar -xvf wordpress-4.9.4-zh_CN.tar.gz
sudo mv wordpress /var/www/html/[WordPressDir]
sudo chown -R www-data /var/www/html
通过浏览器访问该路径,进行安装。
如果用户权限不足,会导致创建数据库失败可用phpMyAdmin解决。
对[WordPressDir]设置权限
sudo chown -R www-data:www-data /var/www/html/[WordPressDir]
否则会由于权限不足而无法上传文件。