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

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

Apache服务器控命令

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

Apache服务器配置文件路径

1
2
3
4
5
6
7
8
9
/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服务器模块配置

1
2
3
4
5
6
7
# 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

启用模块(安装激活)

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

禁止模块

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

虚拟主机配置

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

开启php的opcache

1
php -v

Open the PHP configuration file with the following command.

If PHP is interpreted using the Apache module:

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

If PHP is interpreted via PHP-FPM / NGINX:

1
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:

1
;opcache.enable=0

with this:

1
opcache.enable=1

remove the; initial if present.

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

Apache:

1
sudo service apache2 restart

PHP-FPM / NGINX:

1
sudo service nginx restart

虚拟主机

www目录

1
/var/www/html

新建虚拟主机目录

1
sudo mkdir -p /var/www/example.com/public_html
1
sudo chown -R www-data: /var/www/example.com
1
vi /etc/apache2/sites-available/example.com.conf

http配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<virtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    ServerAdmin webmaster@example.com
    DocumentRoot /var/www/example.com/public_html

    <directory /var/www/example.com/public_html>
        Options -Indexes +FollowSymLinks
        AllowOverride All
    </directory>

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

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

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

或使用配置工具自动创建

1
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
解决办法:

1
nano /etc/apache2/apache2.conf

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

1
sudo systemctl reload apache2
原文链接:https://xiaohost.com/3723.html,转载请注明出处。
0

评论0

请先