Ubantu 安装MySQL+PHP+Redis
本文仅用作记录。
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| sudo apt install software-properties-common sudo add-apt-repository ppa:ondrej/php
sudo apt update sudo apt install php8.2 php8.2-curl php8.2-mysql
sudo apt install redis
sudo apt install mysql-server
sudo apt install nginx
sudo ufw allow 'Nginx Full' sudo ufw status
|
如果系统已经安装 Apache / Httpd,需要先卸载
配置 MySQL
1 2 3 4 5 6
| mysql ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'mynewpassword';
<Ctrl+C>
sudo mysql_secure_installation
|
添加一个账号
1 2 3 4 5 6 7
| mysql -u root -p
CREATE DATABASE TEST;
CREATE USER 'username'@'localhost' IDENTIFIED BY 'strong_password';
GRANT ALL PRIVILEGES ON TEST.* TO 'username'@'localhost' WITH GRANT OPTION;
|
配置 supervisor
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| vim /etc/supervisor/conf.d/test.conf
[program:test] directory=/root/test command=php start.php start autostart=true autorestart=true startretries=3 redirect_stderr=true stdout_logfile=/root/test.log environment=
supervisorctl update supervisorctl start test supervisorctl status test
|
配置 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
| vim /etc/nginx/sites-enabled/test.conf
# 示例1 server {
server_name example.com; root /var/www/html/;
location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php8.2-fpm.sock; } }
# 示例2 server { listen 80; listen [::]:80;
root /root/test/public;
# Add index.php to the list if you are using PHP # index index.php index.html;
server_name test;
location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:8787; }
# deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { #deny all; #} }
sudo nginx -t sudo systemctl restart nginx
|