在Ubuntu中启用Apache2模块

导论

每次在Ubuntu上配置Apache2时,我总会纠结于”哎呀?怎么操作来着?”,所以我在这里记下备忘录。

每次都忘記的我(帶著警示推動著)。

「a2enmod 了!你想起来了吗?」

环境

操作系统

NAME="Ubuntu"
VERSION="16.04.4 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.4 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial

阿帕奇

$ apache2 -v
Server version: Apache/2.4.18 (Ubuntu)
Server built:   2017-09-18T15:09:02

启用模块

那个?想不起来了吗?安静点,执行 a2enmod。

$ sudo a2enmod
Your choices are: access_compat actions alias allowmethods asis auth_basic auth_digest auth_form auth_mysql authn_anon authn_core authn_dbd authn_dbm authn_file authn_socache authnz_ldap authz_core authz_dbd authz_dbm authz_groupfile authz_host authz_owner authz_user autoindex buffer cache cache_disk cache_socache cgi cgid charset_lite data dav dav_fs dav_lock dbd deflate dialup dir dump_io echo env expires ext_filter file_cache filter headers heartbeat heartmonitor include info lbmethod_bybusyness lbmethod_byrequests lbmethod_bytraffic lbmethod_heartbeat ldap log_debug log_forensic lua macro mime mime_magic mpm_event mpm_prefork mpm_worker negotiation php5 proxy proxy_ajp proxy_balancer proxy_connect proxy_express proxy_fcgi proxy_fdpass proxy_ftp proxy_html proxy_http proxy_scgi proxy_wstunnel ratelimit reflector remoteip reqtimeout request rewrite sed session session_cookie session_crypto session_dbd setenvif slotmem_plain slotmem_shm socache_dbm socache_memcache socache_shmcb speling ssl status substitute suexec unique_id userdir usertrack vhost_alias xml2enc
Which module(s) do you want to enable (wildcards ok)?

谢谢交互式互动!

他正在亲切地询问想要启用哪个模块。

你想启用mod_rewrite吗?输入”rewrite”并按Enter键。

...
Which module(s) do you want to enable (wildcards ok)?
rewrite
Enabling module rewrite.
To activate the new configuration, you need to run:
  service apache2 restart

他一直在引导我重新启动,真是个非常友好的家伙。

$ sudo service apache2 restart

不需要互动也可以吗?我明白了。

$ sudo a2enmod rewrite
$ sudo service apache2 restart

禁用模块

顺便提一下无效化。

$ sudo a2dismod
Your choices are: access_compat alias auth_basic authn_core authn_file authz_core authz_host authz_user autoindex deflate dir env filter mime mpm_event negotiation rewrite setenvif status
Which module(s) do you want to disable (wildcards ok)?
rewrite
Module rewrite disabled.
To activate the new configuration, you need to run:
  service apache2 restart
$ sudo service apache2 restart

或者

$ sudo a2dismod rewrite
$ sudo service apache2 restart
广告
将在 10 秒后关闭
bannerAds