Debian 9 系统LAMP(Apache)服务器配置及控制命令

作者: 站长 上传时间: 浏览: N/A 下载: N/A 格式: N/A 评分: N/A

注意Ubuntu 及 Debian系统中Apache服务器的服务为apache2,CentOS系统中为httpd

Apache服务器控命令

sudo systemctl start|stop|restart|reload|status apache2

Apache服务器配置文件路径

/etc/apache2/apache2.conf

# configurations in this order:
Include /etc/apache2/mods-enabled/*.load
Include /etc/apache2/mods-enabled/*.conf
Include /etc/apache2/httpd.conf
Include /etc/apache2/ports.conf
Include /etc/apache2/conf.d/[^.#]*
Include /etc/apache2/sites-enabled/[^.#]*

Apache服务器模块配置

# Files related to Apache modules
/etc/apache2/mods-enabled/*.load
/etc/apache2/mods-enabled/*.conf
/etc/apache2/mods-available/*.load
/etc/apache2/mods-available/*.conf
/usr/sbin/a2enmod
/usr/sbin/a2dismod

启用模块(安装激活)

a2enmod ${module}
/etc/init.d/apache2 force-reload

禁止模块

a2dismod ${module}
/etc/init.d/apache2 force-reload

虚拟主机配置

# Files related to Apache virtual hosts
/etc/apache2/sites-enabled/[^.#]*
/etc/apache2/sites-available/*
/usr/sbin/a2ensite
/usr/sbin/a2dissite

开启php的opcache

php -v

Open the PHP configuration file with the following command.

If PHP is interpreted using the Apache module:

sudo nano /etc/php/7.2/apache2/php.ini

If PHP is interpreted via PHP-FPM / NGINX:

sudo nano /etc/php/7.2/fpm/php.ini

To enable the use of OPcache, all you need to do is enable the related item, by changing the following line:

;opcache.enable=0

with this:

opcache.enable=1

remove the; initial if present.

At this point, OPcache will already be enabled, when restarting the web server:

Apache:

sudo service apache2 restart

PHP-FPM / NGINX:

sudo service nginx restart

虚拟主机

www目录
/var/www/html

新建虚拟主机目录

sudo mkdir -p /var/www/example.com/public_html

sudo chown -R www-data: /var/www/example.com

vi /etc/apache2/sites-available/example.com.conf

http配置


ServerName example.com
ServerAlias www.example.com
ServerAdmin [email protected]
DocumentRoot /var/www/example.com/public_html


Options -Indexes +FollowSymLinks
AllowOverride All

ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined

手动创建虚拟主机配置文件软连接

sudo ln -s /etc/apache2/sites-available/example.com.conf /etc/apache2/sites-enabled/

或使用配置工具自动创建

sudo a2ensite example.com

故障排查
1、重启Apache报错
apache2: Could not reliably determine the server’s fully qualified domain name, using ::1. Set the ‘ServerName’ directive globally to suppress this message
解决办法:

nano /etc/apache2/apache2.conf

添加内容ServerName localhost
重新加载应该就解决了

sudo systemctl reload apache2

Leave a Comment