Skip to content
On this page

搭建 LAMP

php

sudo apt update

sudo apt -y install lsb-release apt-transport-https ca-certificates 
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg

echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list

sudo apt install php7.4
sudo apt install libapache2-mod-php7.4 php7.4-mysql

mysql

sudo apt update
sudo apt install mariadb-server

sudo systemctl start mariadb

sudo mysql_secure_installation

創建 mysql 數據庫/用戶/賦權

create database ego_hera;
create user 'newuser'@'localhost' IDENTIFIED BY 'user_password';
GRANT ALL PRIVILEGES ON ego_hera.* TO 'newuser'@'localhost';

按需安装扩展

sudo apt install php7.4-xxx

安装指定版本 swoole

sudo apt install php7.4-dev
sudo pecl install swoole-4.8.11

创建 30-swoole.ini

目录 /etc/php/7.4/apache2/conf.d 及 /etc/php/7.4/cli/conf.d

extension=swoole.so

反向代理

启用模块

sudo a2enmod proxy proxy_wstunnel proxy_http

修改 /etc/apache2/sites-available 下 xxx.conf 配置文件 80 节点

ProxyRequests Off
ProxyPreserveHost On
ProxyPass /ws ws://127.0.0.1:59998
ProxyPassReverse /ws ws://127.0.0.1:59998

如果设置了ssl,则在 443 节点下修改

SSLProxyEngine On
ProxyRequests Off
ProxyPreserveHost On
ProxyPass /wss ws://127.0.0.1:59998
ProxyPassReverse /wss ws://127.0.0.1:59998

重启 apache

sudo systemctl reload apache2

安装 redis

安装 redis-server

sudo apt update
sudo apt install redis-server

查看 redis 状态

systemctl status redis-server

安装 php redis 扩展

sudo apt install php7.4-redis

安装 wp 插件 Redis Object Cache

在 wp-config.php 中加入以下设置,并给 /wp-content 写的权限

// adjust Redis host and port if necessary 
define( 'WP_REDIS_HOST', '127.0.0.1' );
define( 'WP_REDIS_PORT', 6379 );

// change the prefix and database for each site to avoid cache data collisions
define( 'WP_REDIS_PREFIX', 'ego_hera');
define( 'WP_REDIS_DATABASE', 0 ); // 0-15

// reasonable connection and read+write timeouts
define( 'WP_REDIS_TIMEOUT', 1 );
define( 'WP_REDIS_READ_TIMEOUT', 1 );

安装序列化扩展

sudo pecl install igbinary

添加 extension=igbinary.so/etc/php/7.4/apache2/php.ini,并重启 apache2

Released under the MIT License.