温馨提示×

centos lamp怎么重启服务

小樊
51
2026-10-15 00:47:45
栏目: 智能运维

在 CentOS 上重启 LAMP(Linux + Apache + MySQL/MariaDB + PHP)相关服务,通常是对 Apache 和 MySQL/MariaDB 分别操作。下面分常见版本说明。


一、CentOS 7 / 8(使用 systemd,推荐)

1. 重启 Apache

sudo systemctl restart httpd

2. 重启 MySQL / MariaDB

如果是 MariaDB(CentOS 默认):

sudo systemctl restart mariadb

如果是 MySQL:

sudo systemctl restart mysqld

3. 同时重启(LAMP)

sudo systemctl restart httpd mariadb

二、CentOS 6 及更早(使用 service)

sudo service httpd restart
sudo service mysqld restart
# 或
sudo service mariadb restart

三、设置开机自启(可选)

sudo systemctl enable httpd
sudo systemctl enable mariadb

四、查看服务状态

systemctl status httpd
systemctl status mariadb

五、常见问题

  • Apache 起不来:看日志
    journalctl -xe
    
  • 端口被占用:确认 80 / 3306 端口
    netstat -tunlp | grep :80
    

如果你告诉我 CentOS 具体版本(如 7.9 / 8 / Stream)以及用的是 MySQL 还是 MariaDB,我可以给你更精确命令。

0 踩