在Ubuntu中安装WordPress (Apache、php、MariaDB)
目录
0x01 安装 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 /*移除配置文件*/
0x02 安装php,php-fpm
sudo apt install -y php7.2 php7.2-fpm php7.2-mysqli php7.2-mbstring php7.2-zip php7.2-xml php7.2-gd /*版本号通过 apt install php 获得*/
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> …… # 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" …… </VirtualHost>
重启:
sudo systemctl restart apache2
0x03 安装 MariaDB
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相同*/
默认root只能本地登录,为了使用phpmyadmin,新建一个管理员用户,赋予最大权限。
CREATE USER '[username]'@'%' IDENTIFIED BY '[password]'; GRANT ALL PRIVILEGES ON *.* TO '[username]'@'%' IDENTIFIED BY '[password]' WITH GRANT OPTION; FLUSH PRIVILEGES;
0x04 安装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;
下载 WordPress 并解压
修改权限 (不修改,wordpress无法创建config.php)
sudo chown -R www-data:www-data /var/www/html