ubuntu自建PHP,mysql,nginx
systemctl enable nginx
启动nginx
systemctl start nginx
重启nginx:
service nginx restart
重启mysql:
systemctl restart mysql
systemctl stop nginx systemctl reload nginx systemctl status nginx
登入数据库:
mysql -u root -p
检查端口是否被占用
netstat -tnlp
systemctl start php7.4-fpm
如果你不需要 Apache2,可以停止并禁用它:
sudo systemctl stop apache2 sudo systemctl disable apache2
查看数据库:
systemctl status mysql
修改root密码:
alter user "root"@"localhost" identified with mysql_native_password by "root密码"; flush privileges;
修改nginx配制文件:
nano /etc/nginx/sites-available/default
# HTTP 服务器块
server { //80端口 listen 80; //ip或域名 server_name 152.70.100.220; //网站文件目录 root /var/www/html; //默认文档 index index.php index.html index.htm; //定义强制转https:// }
# HTTPS服务器块
server { listen 443 ssl; server_name 152.70.100.220; root /var/www/html; index index.php index.html index.htm; //定义证书位置 ssl_certificate /etc/letsencrypt/live/example.com/certificate.crt; ssl_certificate_key /etc/letsencrypt/live/example.com/private.key; ssl_trusted_certificate /etc/letsencrypt/live/example.com/ca_bundle.crt; //定义404 location / { try_files $uri $uri/ =404; } location ~ \.php$ { //将另一个配置文件的内容包含到当前配置块中 include snippets/fastcgi-php.conf; //用于设置 FastCGI 参数 fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; # 根据你安装的PHP版本调整 //用于设置 FastCGI 参数 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; //将另一个配置文件的内容包含到当前配置块中 include fastcgi_params; } //禁用.开头的文件查看:比如 .htpasswd 或 .htaccess 文件 location ~ /\.ht { deny all; } }
删除PHP mysql nginx phpmyadmin
1. 删除 PHP
首先,删除 PHP 及其相关的扩展:
sudo apt remove --purge php* -y
这将删除所有 PHP 版本及其扩展。然后,删除 PHP 的残留文件和依赖:
sudo apt autoremove --purge -y sudo apt autoclean
删除 MySQL 服务器和客户端
sudo apt remove --purge mysql-server mysql-client mysql-common -y
删除 MySQL 的配置文件和数据库数据:
sudo rm -rf /etc/mysql /var/lib/mysql
删除不再需要的包:
sudo apt autoremove --purge -y sudo apt autoclean
删除 Nginx
sudo apt remove --purge nginx nginx-common nginx-core -y
删除 Nginx 的配置文件和日志文件:
sudo rm -rf /etc/nginx /var/log/nginx
清理系统:
sudo apt autoremove --purge -y sudo apt autoclean
删除 phpMyAdmin
sudo apt remove --purge phpmyadmin -y
删除 phpMyAdmin 的残留文件:
sudo rm -rf /usr/share/phpmyadmin /etc/phpmyadmin
为了确保所有服务都被停止,您可以执行以下命令:
sudo systemctl stop nginx sudo systemctl stop mysql sudo systemctl stop php7.*-fpm
最后检查和清理
sudo apt autoremove --purge -y sudo apt autoclean