LAMP是指在许多web 服务器上使用的一个软件组合:Linux,Apache,MySQL/MariaDB以及PHP。本文档描述了怎样在Archlinux系统上安装设置Apache网页服务器。以及选择安装PHP和MariaDB并集成到Apache服务器中。 如果只是用来开发和测试, Xampp 可能更简便一些。 Contents[hide]
安装# pacman -S apache php php-apache mariadb 你可以只单独安装Apache,PHP或者mariadb(MySQL),也可以安装所有包。这个文档假设你安装全部,当然你可以忽略任何部分。 配置Apache
出于安全原因,Apache以root用户身份启动(直接的或者通过启动脚本)后将立即切换为
# grep http /etc/passwd
# useradd -d /srv/http -r -s /bin/false -U http
# systemctl start httpd
Include conf/extra/httpd-userdir.conf
# systemctl enable httpd 用户目录
Include conf/extra/httpd-userdir.conf
$ chmod o+x ~ $ chmod o+x ~/public_html
$ usermod -aG piter http
$ chmod g+xr-w /home/yourusername $ chmod -R g+xr-w /home/yourusername/public_html 并重启httpd. SSL创建自签名的证书(你可以改变密钥长度和有效天数) # cd /etc/httpd/conf # openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:4096 -out server.key # openssl req -new -key server.key -out server.csr # cp server.key server.key.org # openssl rsa -in server.key.org -out server.key # openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
在 Include conf/extra/httpd-ssl.conf 并重启httpd。 Virtual Hosts如果你需要不止一个主机,确保你有 # Virtual hosts Include conf/extra/httpd-vhosts.conf
在
参考下面的例子,在 NameVirtualHost *:80 #this first virtualhost enables: http://127.0.0.1, or: http://localhost, #to still go to /srv/http/*index.html(otherwise it will 404_error). #the reason for this: once you tell httpd.conf to include extra/httpd-vhosts.conf, #ALL vhosts are handled in httpd-vhosts.conf(including the default one), # E.G. the default virtualhost in httpd.conf is not used and must be included here, #otherwise, only domainname1.dom & domainname2.dom will be accessible #from your web browser and NOT http://127.0.0.1, or: http://localhost, etc. # <VirtualHost *:80> DocumentRoot "/srv/http" ServerAdmin root@localhost ErrorLog "/var/log/httpd/127.0.0.1-error_log" CustomLog "/var/log/httpd/127.0.0.1-access_log" common <Directory /srv/http/> DirectoryIndex index.htm index.html AddHandler cgi-script .cgi .pl Options ExecCGI Indexes FollowSymLinks MultiViews +Includes AllowOverride None Order allow,deny allow from all </Directory> </VirtualHost> <VirtualHost *:80> ServerAdmin your@domainname1.dom DocumentRoot "/home/username/yoursites/domainname1.dom/www" ServerName domainname1.dom ServerAlias domainname1.dom <Directory /home/username/yoursites/domainname1.dom/www/> DirectoryIndex index.htm index.html AddHandler cgi-script .cgi .pl Options ExecCGI Indexes FollowSymLinks MultiViews +Includes AllowOverride None Order allow,deny allow from all </Directory> </VirtualHost> <VirtualHost *:80> ServerAdmin your@domainname2.dom DocumentRoot "/home/username/yoursites/domainname2.dom/www" ServerName domainname2.dom ServerAlias domainname2.dom <Directory /home/username/yoursites/domainname2.dom/www/> DirectoryIndex index.htm index.html AddHandler cgi-script .cgi .pl Options ExecCGI Indexes FollowSymLinks MultiViews +Includes AllowOverride None Order allow,deny allow from all </Directory> </VirtualHost> 将你的虚拟主机的名称添加到你的 /etc/hosts 文件(如果bind已经在为这些域名服务了,则非必需,但是加上也无妨): 127.0.0.1 domainname1.dom 127.0.0.1 domainname2.dom 并重启httpd。 如果你将虚拟主机设定在你的用户目录中,有时这会干扰Apache的'Userdir'设定。注释掉以下行以避免此问题: # User home directories #Include conf/extra/httpd-userdir.conf 如上所述,确保你有合适的权限: # chmod 0775 /home/yourusername/
如果你有非常多的虚拟主机并且希望轻松的激活或禁用他们,建议你为每一个虚拟主机创建一个配置文件并且将所有的这些配置文件存储到一个文件夹中,如: 首先创建这个文件夹: # mkdir /etc/httpd/conf/vhosts 然后将单个的配置文件放到里面: # nano /etc/httpd/conf/vhosts/domainname1.dom # nano /etc/httpd/conf/vhosts/domainname2.dom ...
最后一步,"Include"单个的配置文件们到你的 #Enabled Vhosts: Include conf/vhosts/domainname1.dom #Include conf/vhosts/domainname1.dom 你可以通过注释或去注释来激活或禁用单个的虚拟主机。 高级选项
你也许会对 # Listen 80 这是Apache监听的端口。为了跨路由器的访问,你需要转发这个端口。 如果你只是用于本地开发,你可能希望她只能被你自己的计算机访问。那么将这一行改为: # Listen 127.0.0.1:80 这是管理员的电子邮件地址,该地址可以在错误页面等处见到: # ServerAdmin sample@sample.com 这是存放你的网页文件的目录: # DocumentRoot "/srv/http" 如果愿意,可以修改,不过不要忘了同时修改 <Directory "/srv/http"> 为你所修改的文档根目录,否则当你试图访问新的文档根目录时可能会得到一个403错误(缺少权限)。不要忘记修改"Deny from all"行,否则你也可能遇到403错误。 # AllowOverride None
PHP
LoadModule php7_module modules/libphp7.so
Include conf/extra/php7_module.conf
LoadModule mpm_event_module modules/mod_mpm_event.so
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
TypesConfig conf/mime.types
MIMEMagicFile conf/magic
application/x-httpd-php7 php php7
open_basedir=/srv/http/:/home/:/tmp/:/usr/share/pear/:/path/to/documentroot
<?php phpinfo(); ?>
如果还不行,检查<IfModule mime_module>部分中 AddHandler application/x-httpd-php .php 高级选项
date.timezone = Asia/Shanghai
display_errors=On
extension=gd.so
extension=mcrypt.so
DirectoryIndex index.php index.phtml index.html 与apache2-mpm-worker和mod_fcgid一起使用php7
取消 HTTPD=/usr/sbin/httpd.worker
取消 Include conf/extra/httpd-mpm.conf 安装mod_fcgid和php-cgi包: # pacman -S mod_fcgid php-cgi
创建 # Required modules: fcgid_module <IfModule fcgid_module> AddHandler php-fcgid .php AddType application/x-httpd-php .php Action php-fcgid /fcgid-bin/php-fcgid-wrapper ScriptAlias /fcgid-bin/ /srv/http/fcgid-bin/ SocketPath /var/run/httpd/fcgidsock SharememPath /var/run/httpd/fcgid_shm # If you don't allow bigger requests many applications may fail (such as WordPress login) FcgidMaxRequestLen 536870912 PHP_Fix_Pathinfo_Enable 1 # Path to php.ini – defaults to /etc/phpX/cgi DefaultInitEnv PHPRC=/etc/php/ # Number of PHP childs that will be launched. Leave undefined to let PHP decide. #DefaultInitEnv PHP_FCGI_CHILDREN 3 # Maximum requests before a process is stopped and a new one is launched #DefaultInitEnv PHP_FCGI_MAX_REQUESTS 5000 <Location /fcgid-bin/> SetHandler fcgid-script Options +ExecCGI </Location> </IfModule> 为PHP包装器创建需要的目录和符号链接: # mkdir /srv/http/fcgid-bin # ln -s /usr/bin/php-cgi /srv/http/fcgid-bin/php-fcgid-wrapper
编辑 #LoadModule php5_module modules/libphp5.so LoadModule fcgid_module modules/mod_fcgid.so Include conf/extra/php5_fcgid.conf
确保 cgi.fix_pathinfo=1 并重启 httpd。 MariaDB
;extension=pdo_mysql.so ;extension=mysqli.so
(责任编辑:IT) |