ArchLinuxでLAMP環境作ってみた

# インストール

```bash:インストール
pacman -Sy apache php php-apache mariadb postfix
```

## apache,php

```diff:conf/httpd.conf
+ LoadModule php5_module       modules/libphp5.so
+ AddHandler php5-script php
+ Include conf/extra/php5_module.conf
```

> Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe.  You need to recompile PHP.の対応

```diff:conf/httpd.conf
- LoadModule mpm_event_module modules/mod_mpm_event.so
+ LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
```

```diff:conf/httpd.conf
- #LoadModule vhost_alias_module modules/mod_vhost_alias.so
+ LoadModule vhost_alias_module modules/mod_vhost_alias.so
- #Include conf/extra/httpd-vhosts.conf
+ Include conf/extra/httpd-vhosts.conf
```

* 適宜`extra/httpd-vhosts.conf`の編集


## php,mysql

```diff:/etc/php/php.ini
- ;date.timezone =
+ date.timezone = Asia/Tokyo
```

> PHP Fatal error:  Call to undefined function mysql_connect()の対応

```diff:/etc/php/php.ini
- ;extension=mysql.so
+ extension=mysql.so
```

mysql.so はphp5.5ではdeprecatedだったような。一時しのぎ

## postfix

> error: open database /etc/postfix/aliases.db: No such file or directory
> alias database unavailable の対応

```bash:
newaliases
```

# サービス登録

```bash:
for s in mysqld httpd postfix
do
  systemctl enable $s
  systemctl start $s
done
```

* DocumentRoot は /srv/http
* mariadbは標準でutf-8

# tips

## cgi-scriptが使いたい場合

```diff:conf/httpd.conf
- #LoadModule cgi_module modules/mod_cgi.so
+ LoadModule cgi_module modules/mod_cgi.so
- #AddHandler cgi-script .cgi
+ AddHandler cgi-script .cgi
```

```diff:conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
    ...
+   <Directory "/srv/http/cgi">
+       Options +ExecCGI
+       Require all granted
+   </Directory>
</VirtualHost>
```

## DocumentRootを変更したい場合

* /srv/http/ から /srv/domainname/ に変更する場合

> PHP Warning:  Unknown: open_basedir restriction in effect. File(/srv/domainname/public/index.php) is not within the allowed path(s): (/srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/) in Unknown on line 0

```diff:/etc/php/php.ini
- open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/
+ ;open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/
```

## digest認証 + .htaccess

```diff:httpd.conf
- #LoadModule auth_digest_module modules/mod_auth_digest.so
+ LoadModule auth_digest_module modules/mod_auth_digest.so
```

```diff:extra/httpd-vhosts.conf
  <Directory "/srv/httpd/admin/">
+   AllowOverride AuthConfig
    Require all granted   
  </Directory>
```

```bash:.htaccess
AuthType Digest
AuthName "member only"
AuthUserFile "/srv/digest/.htdigest"
require valid-user
```

```bash:.htdigest作成
$ htdigest -c /srv/digest/.htdigest "member only" user1
Adding password for user1 in realm member only.
New password:
Re-type new password:
$ cat .htdigest
user1:member only:e9fc3e4e6f5fd3a18be2006b6a1964b9
```

## .htaccessでphp_value値の変更するために

> .htaccess: php_value not allowed here

```diff:extra/httpd-vhosts.conf
  <Directory "/srv/httpd/admin/">
+   AllowOverride Options
    Require all granted   
  </Directory>
```

## .htaccessでアップロードの設定変更

```bash:.htaccess
php_value max_execution_time 600
php_value post_max_size 50M
php_value upload_max_filesize 50M
```

## userdir

* [mod_userdir - Apache HTTP サーバ バージョン 2.4](http://httpd.apache.org/docs/2.4/ja/mod/mod_userdir.html)

```diff:extra/httpd-userdir.conf
  UserDir public_html
+ UserDir disabled
+ UserDir enabled username1 username2
```

```bash:
chown :http /home/username[12]/
chmod g+rx /home/username[12]/
```

public_htmlを`http`ユーザでアクセスできるように権限に気をつける。


# その他

## netstatがない場合

```bash:
pacman -Sy net-tools
```