LAMP(Linux+Apache+MySQL+PHP)是常见的Web服务栈,以下是管理这些服务进程的方法:
# 启动Apache
sudo systemctl start apache2 # Debian/Ubuntu
sudo systemctl start httpd # CentOS/RHEL
# 停止Apache
sudo systemctl stop apache2
sudo systemctl stop httpd
# 重启Apache
sudo systemctl restart apache2
sudo systemctl restart httpd
# 查看状态
sudo systemctl status apache2
sudo systemctl status httpd
# 设置开机启动
sudo systemctl enable apache2
sudo systemctl enable httpd
sudo service apache2 start|stop|restart|status
sudo service httpd start|stop|restart|status
# 启动MySQL
sudo systemctl start mysql # Debian/Ubuntu
sudo systemctl start mariadb # 一些发行版
sudo systemctl start mysqld # CentOS/RHEL
# 停止MySQL
sudo systemctl stop mysql
# 重启MySQL
sudo systemctl restart mysql
# 查看状态
sudo systemctl status mysql
# 设置开机启动
sudo systemctl enable mysql
sudo service mysql start|stop|restart|status
# 启动PHP-FPM
sudo systemctl start php-fpm # CentOS/RHEL
sudo systemctl start php7.4-fpm # Ubuntu/Debian (版本号可能不同)
# 停止PHP-FPM
sudo systemctl stop php-fpm
# 重启PHP-FPM
sudo systemctl restart php-fpm
# 查看状态
sudo systemctl status php-fpm
# 设置开机启动
sudo systemctl enable php-fpm
ps aux | grep -E 'apache|httpd|mysql|mariadb|php-fpm'
sudo netstat -tulnp | grep -E 'apache|httpd|mysql|php'
# 或使用ss命令
sudo ss -tulnp | grep -E 'apache|httpd|mysql|php'
# 先找到进程ID
ps aux | grep process_name
# 然后杀死
sudo kill -9 PID
Apache日志:
/var/log/apache2/
(Debian/Ubuntu)/var/log/httpd/
(CentOS/RHEL)MySQL日志:
/var/log/mysql/error.log
PHP日志:
/var/log/php_errors.log
Apache:
/etc/apache2/
(Debian/Ubuntu)/etc/httpd/
(CentOS/RHEL)MySQL:
/etc/mysql/
(Debian/Ubuntu)/etc/my.cnf
或 /etc/mysql/my.cnf
(CentOS/RHEL)PHP:
/etc/php/7.x/
(版本号可能不同)可以创建简单的bash脚本来统一管理LAMP服务:
#!/bin/bash
case "$1" in
start)
echo "Starting LAMP stack..."
sudo systemctl start apache2
sudo systemctl start mysql
sudo systemctl start php7.4-fpm
;;
stop)
echo "Stopping LAMP stack..."
sudo systemctl stop apache2
sudo systemctl stop mysql
sudo systemctl stop php7.4-fpm
;;
restart)
echo "Restarting LAMP stack..."
sudo systemctl restart apache2
sudo systemctl restart mysql
sudo systemctl restart php7.4-fpm
;;
status)
echo "Apache2 status:"
sudo systemctl status apache2
echo "MySQL status:"
sudo systemctl status mysql
echo "PHP-FPM status:"
sudo systemctl status php7.4-fpm
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
exit 0
保存为lampctl
,然后赋予执行权限:
chmod +x lampctl
使用方法:
sudo ./lampctl start # 启动所有服务
sudo ./lampctl stop # 停止所有服务
sudo ./lampctl status # 查看状态
希望这些信息能帮助您有效管理LAMP服务进程!