FreeBSD - установка, настройка Apache, PHP, MySQL

Apache

Добавляем строки в ''/etc/make.conf''

 # ----------------- Apache ---------------------------------
 .if ${.CURDIR} == /usr/ports/www/apache22
 WITHOUT_CACHE=yes
 WITHOUT_DAV=yes
 WITHOUT_EXPERIMENTAL=yes
 WITHOUT_LDAP=yes
 WITHOUT_MISC=yes
 WITHOUT_PROXY=yes
 WITHOUT_SSL=yes
 WITHOUT_THREADS=yes
 WITH_SUEXEC=yes
 SUEXEC_DOCROOT=/home/www
 .endif
 # ----------------------------------------------------------

Запускаем сборку

 # cd /usr/ports/www/apache22
 # make config

Включаем в сборку следующие модули:

 # make install clean

Сборка ''mod_fcgid''

 # cd /usr/ports/www/mod_fcgid
 # make install clean
 
 # echo "apache22_enable="YES"" >> /etc/rc.conf
 # echo "apache22_http_accept_enable="YES"" >> /etc/rc.conf

Удалим лишние конфигурационные файлы apache:

 # cd /usr/local/etc/apache22
 # rm -rf Includes/ extra/

/usr/local/etc/apache22/httpd.conf

 
 ServerRoot "/usr/local"
 
 Listen 127.0.0.1:80
 Listen x.x.x.x:80
 
 Timeout 120
 KeepAlive On
 MaxKeepAliveRequests 100
 KeepAliveTimeout 5
 UseCanonicalName Off
 AccessFileName .htaccess
 ServerTokens Full
 ServerSignature On
 HostnameLookups Off
 PidFile "/var/run/httpd.pid"
 LockFile "/var/log/accept.lock"
 
 # prefork MPM
 # StartServers: number of server processes to start
 # MinSpareServers: minimum number of server processes which are kept spare
 # MaxSpareServers: maximum number of server processes which are kept spare
 # MaxClients: maximum number of server processes allowed to start
 # ServerLimit: maximum value for MaxClients for the lifetime of the server
 # MaxRequestsPerChild: maximum number of requests a server process serves
 <IfModule mpm_prefork_module>
         StartServers            5
         MinSpareServers         5
         MaxSpareServers         10
         MaxClients              100
         ServerLimit             100
         MaxRequestsPerChild     0
 </IfModule>
 
 
 LoadModule authn_file_module libexec/apache22/mod_authn_file.so
 LoadModule authz_host_module libexec/apache22/mod_authz_host.so
 LoadModule auth_digest_module libexec/apache22/mod_auth_digest.so
 LoadModule charset_lite_module libexec/apache22/mod_charset_lite.so
 LoadModule log_config_module libexec/apache22/mod_log_config.so
 LoadModule env_module libexec/apache22/mod_env.so
 LoadModule mime_magic_module libexec/apache22/mod_mime_magic.so
 LoadModule unique_id_module libexec/apache22/mod_unique_id.so
 LoadModule mime_module libexec/apache22/mod_mime.so
 LoadModule status_module libexec/apache22/mod_status.so
 LoadModule autoindex_module libexec/apache22/mod_autoindex.so
 LoadModule asis_module libexec/apache22/mod_asis.so
 LoadModule info_module libexec/apache22/mod_info.so
 LoadModule suexec_module libexec/apache22/mod_suexec.so
 LoadModule negotiation_module libexec/apache22/mod_negotiation.so
 LoadModule dir_module libexec/apache22/mod_dir.so
 LoadModule actions_module libexec/apache22/mod_actions.so
 LoadModule alias_module libexec/apache22/mod_alias.so
 LoadModule rewrite_module libexec/apache22/mod_rewrite.so
 LoadModule fcgid_module libexec/apache22/mod_fcgid.so
 
 User www
 Group www
 
 ServerAdmin root@localhost
    
 AddDefaultCharset UTF-8
 
 <Directory />
      AllowOverride None
      Order deny,allow
      Deny from all
 </Directory>
 
 <Directory "/home/www/*/public_html">
      Options FollowSymLinks
      AllowOverride All
      Order allow,deny
      Allow from all
 </Directory>
 
 <Directory "/home/www/*/cgi-bin">
      AllowOverride None
      Options None
      Order allow,deny
      Allow from all
 </Directory>
 
 <IfModule dir_module>
      DirectoryIndex index.html index.htm index.php
 </IfModule>
 
 <FilesMatch "^\.ht">
      Order allow,deny
      Deny from all
      Satisfy All
 </FilesMatch>
 
 ErrorLog "/var/log/httpd-error.log"
 
 LogLevel warn
 
 <IfModule log_config_module>
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
      LogFormat "%h %l %u %t \"%r\" %>s %b" common
 
      <IfModule logio_module>
              # You need to enable mod_logio.c to use %I and %O
              LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
      </IfModule>
 
      CustomLog "/var/log/httpd-access.log" combined
 </IfModule>
 
 DefaultType text/plain
 
 <IfModule mime_module>
      TypesConfig etc/apache22/mime.types
 
      AddType application/x-compress .Z
      AddType application/x-gzip .gz .tgz
 </IfModule>
 
 # ----------------- apache status ----------------------------------------------------------------------------
 <Location /server-status>
      SetHandler server-status
      Order deny,allow
      Deny from all
      Allow from localhost
 </Location>
 
 ExtendedStatus On
 # ------------------------------------------------------------------------------------------------------------
 
 # ------------------- Virtual hosts --------------------------------------------------------------------------
 NameVirtualHost *:80
 Include etc/apache22/vhosts/*.conf
 # ------------------------------------------------------------------------------------------------------------

/usr/local/etc/apache22/vhosts/vukor.tomsk.ru.conf

 <VirtualHost *:80>
      ServerAdmin vukor@localhost
      DocumentRoot "/home/www/vukor.tomsk.ru/public_html"
      ServerName vukor.tomsk.ru
      ServerAlias www.vukor.tomsk.ru
      SuexecUserGroup vukor vukor
 
      <Directory "/home/www/vukor.tomsk.ru/public_html">
             <IfModule mod_fcgid.c>
                      <Files ~ (\.php)>
                              SetHandler fcgid-script
                              FCGIWrapper /home/www/vukor.tomsk.ru/cgi-bin/php.sh .php
                              Options +ExecCGI
                       </Files>
              </IfModule>
      </Directory>
 
      ErrorLog "/usr/home/www/vukor.tomsk.ru/error_log"
      CustomLog "/usr/home/www/vukor.tomsk.ru/access_log" common
 </VirtualHost>

Создадим новый класс webuser

добавим строки в /etc/login.conf:

 webuser:\
      :copyright=/etc/COPYRIGHT:\
      :welcome=/etc/motd:\
      :setenv=MAIL=/var/mail/$,BLOCKSIZE=K,EDITOR=ee:\
      :path=/bin /usr/bin /usr/local/bin:\
      :manpath=/usr/share/man /usr/local/man:\
      :nologin=/sbin/nologin:\
      :cputime=5m:\
      :datasize=512M:\
      :stacksize=4M:\
      :memorylocked=64M:\
      :memoryuse=256M:\
      :filesize=512M:\
      :coredumpsize=0:\
      :openfiles=1024:\
      :maxproc=64:\
      :sbsize=unlimited:\
      :priority=20:\
      :requirehome:\
      :umask=026:\
      :tc=default:

пересоберём классы:

 # cap_mkdb -v /etc/login.conf

Создание вебюзера

 # mkdir /home/www
 # pw group add vukor
 # pw group mod vukor -m www
 # pw user add vukor -L webuser -s /bin/sh -d /home/www/vukor.tomsk.ru -g vukor
 # mkdir -m 750 /home/www/vukor.tomsk.ru && chown vukor:vukor /home/www/vukor.tomsk.ru
 # su - vukor
 
 $ mkdir -m 750 cgi-bin
 $ touch cgi-bin/php.sh && chmod 750 cgi-bin/php.sh
 $ mkdir -m 750 public_html
 $ mkdir -m 750 tmp
 $ exit
 
 # chsh -s /sbin/nologin vukor

/home/www/vukor.tomsk.ru/cgi-bin/php.sh

 #!/bin/sh
 
 PHP_FCGI_CHILDREN=0
 export PHP_FCGI_CHILDREN
 
 PHP_FCGI_MAX_REQUESTS=500
 export PHP_FCGI_MAX_REQUESTS
 
 exec /usr/local/bin/php-cgi

Запускаем apache

 
 # /usr/local/etc/rc.d/apache22 start

PHP

 # cd /usr/ports/lang/php5
 # make config

Включаю в сборку следующие модули:

 [X] CLI        Build CLI version 
 [X] CGI        Build CGI version
 [ ] APACHE     Build Apache module
 [ ] DEBUG      Enable debug
 [X] SUHOSIN    Enable Suhosin protection system (not for jails)
 [X] MULTIBYTE  Enable zend multibyte support
 [ ] IPV6       Enable ipv6 support
 [X] MAILHEAD   Enable mail header patch
 [X] REDIRECT   Enable force-cgi-redirect support (CGI only)
 [X] DISCARD    Enable discard-path support (CGI only)
 [X] FASTCGI    Enable fastcgi support (CGI only)
 [X] PATHINFO   Enable path-info-check support (CGI only)
 # make install clean
 

Проверяем PHP

 # echo '<?php echo "test string \n"; ?>' | php-cgi
 X-Powered-By: PHP/5.2.12
 Content-type: text/html
 
 test string

Выполним

 # cp /usr/local/etc/php.ini-recommended /usr/local/etc/php.ini
 # cd /usr/ports/lang/php5-extensions
 # make config

Включаю в сборку следующие модули

 ┌────────────────────────────────────────────────────────────────────┐ 
 │ │   [ ] BCMATH      bc style precision math functions            │ │
 │ │   [X] BZ2         bzip2 library support                        │ │
 │ │   [ ] CALENDAR    calendar conversion support                  │ │
 │ │   [X] CTYPE       ctype functions                              │ │
 │ │   [ ] CURL        CURL support                                 │ │
 │ │   [ ] DBA         dba support                                  │ │
 │ │   [ ] DBASE       dBase library support                        │ │
 │ │   [X] DOM         DOM support                                  │ │
 │ │   [ ] EXIF        EXIF support                                 │ │
 │ │   [ ] FILEINFO    fileinfo support                             │ │
 │ │   [X] FILTER      input filter support                         │ │
 │ │   [ ] FRIBIDI     FriBidi support                              │ │
 │ │   [ ] FTP         FTP support                                  │ │
 │ │   [X] GD          GD library support                           │ │
 │ │   [ ] GETTEXT     gettext library support                      │ │
 │ │   [ ] GMP         GNU MP support                               │ │
 │ │   [X] HASH        HASH Message Digest Framework                │ │
 │ │   [X] ICONV       iconv support                                │ │
 │ │   [ ] IMAP        IMAP support                                 │ │
 │ │   [ ] INTERBASE   Interbase 6 database support (Firebird)      │ │
 │ │   [ ] JSON        JavaScript Object Serialization support      │ │
 │ │   [ ] LDAP        OpenLDAP support                             │ │
 │ │   [X] MBSTRING    multibyte string support                     │ │
 │ │   [ ] MCRYPT      Encryption support                           │ │
 │ │   [ ] MHASH       Crypto-hashing support                       │ │
 │ │   [ ] MING        ming shockwave flash support                 │ │
 │ │   [ ] MSSQL       MS-SQL database support                      │ │
 │ │   [X] MYSQL       MySQL database support                       │ │
 │ │   [ ] MYSQLI      MySQLi database support                      │ │
 │ │   [ ] NCURSES     ncurses support (CLI only)                   │ │
 │ │   [ ] ODBC        unixODBC support                             │ │
 │ │   [ ] OPENSSL     OpenSSL support                              │ │
 │ │   [ ] PCNTL       pcntl support (CLI only)                     │ │
 │ │   [X] PCRE        Perl Compatible Regular Expression support   │ │
 │ │   [ ] PDF         PDFlib support (implies GD)                  │ │
 │ │   [X] PDO         PHP Data Objects Interface (PDO)             │ │
 │ │   [ ] PDO_SQLITE  PDO sqlite driver                            │ │
 │ │   [ ] PGSQL       PostgreSQL database support                  │ │
 │ │   [X] POSIX       POSIX-like functions                         │ │
 │ │   [ ] PSPELL      pspell support                               │ │
 │ │   [ ] READLINE    readline support (CLI only)                  │ │
 │ │   [ ] RECODE      recode support                               │ │
 │ │   [X] SESSION     session support                              │ │
 │ │   [ ] SHMOP       shmop support                                │ │
 │ │   [X] SIMPLEXML   simplexml support                            │ │
 │ │   [ ] SNMP        SNMP support                                 │ │
 │ │   [ ] SOAP        SOAP support                                 │ │
 │ │   [ ] SOCKETS     sockets support                              │ │
 │ │   [X] SPL         Standard PHP Library                         │ │
 │ │   [ ] SQLITE      sqlite support                               │ │
 │ │   [ ] SYBASE_CT   Sybase database support                      │ │
 │ │   [ ] SYSVMSG     System V message support                     │ │
 │ │   [ ] SYSVSEM     System V semaphore support                   │ │
 │ │   [ ] SYSVSHM     System V shared memory support               │ │
 │ │   [ ] TIDY        TIDY support                                 │ │
 │ │   [ ] TOKENIZER   tokenizer support                            │ │
 │ │   [ ] WDDX        WDDX support (implies XML)                   │ │
 │ │   [X] XML         XML support                                  │ │
 │ │   [ ] XMLREADER   XMLReader support                            │ │
 │ │   [ ] XMLRPC      XMLRPC-EPI support                           │ │
 │ │   [ ] XMLWRITER   XMLWriter support                            │ │
 │ │   [ ] XSL         XSL support (Implies DOM)                    │ │
 │ │   [ ] YAZ         YAZ support (ANSI/NISO Z39.50)               │ │
 │ │   [X] ZIP         ZIP support                                  │ │
 │ │   [X] ZLIB        ZLIB support                                 │ │
 ├─└────────────────────────────────────────────────────────────────┘─┤

MySQL

Добавляем строки в /etc/make.conf

 # ----------------- MySQL ----------------------------------
 DEFAULT_MYSQL_VER=51
 
 .if ${.CURDIR} == /usr/ports/databases/mysql51-server
 BUILD_OPTIMIZED=yes
 BUILD_STATIC=yes
 WITHOUT_INNODB=yes
 .endif
 # ----------------------------------------------------------

Выполняем сборку

 # cd /usr/ports/databases/mysql51-server
 # make install clean
 # echo "mysql_enable="YES"" >> /etc/rc.conf

Создаем /usr/local/etc/my.cnf

 [client]
 port            = 3306
 socket          = /tmp/mysql.sock
 
 # The MySQL server
 [mysqld]
 port           = 3306
 socket         = /tmp/mysql.sock
 log-error      = /var/log/mysqld.log
 log            = /tmp/mysql-query.log # log queries
 skip-locking
 key_buffer_size = 16K
 max_allowed_packet = 1M
 table_open_cache = 4
 sort_buffer_size = 64K
 read_buffer_size = 256K
 read_rnd_buffer_size = 256K
 net_buffer_length = 2K
 thread_stack = 128K
 
 skip-networking
 server-id       = 1
 
 [mysqldump]
 quick
 max_allowed_packet = 16M
 
 [mysql]
 no-auto-rehash
 
 [myisamchk]
 key_buffer_size = 8M
 sort_buffer_size = 8M
 
 [mysqlhotcopy]
 interactive-timeout

Примеры конфигурационных файлов

 # pkg_info -L -x mysql-server |grep cnf
 /usr/local/share/mysql/my-huge.cnf
 /usr/local/share/mysql/my-innodb-heavy-4G.cnf
 /usr/local/share/mysql/my-large.cnf
 /usr/local/share/mysql/my-medium.cnf
 /usr/local/share/mysql/my-small.cnf

Выполняем

 # mysql --database=mysql --execute="SELECT COUNT(*) FROM user;"
 +----------+
 | COUNT(*) |
 +----------+
 |        5 |
 +----------+
 # mysql --database=mysql --execute="DELETE FROM user WHERE User='';"
 # mysql --database=mysql --execute="DELETE FROM user WHERE Host != 'localhost';"
 # mysql --database=mysql --execute="SELECT COUNT(*) FROM user"
 +----------+
 | COUNT(*) |
 +----------+
 |        1 |
 +----------+
 # mysql --database=mysql --execute="drop database test;"
 # mysql --database=mysql --execute="UPDATE user SET Password = PASSWORD('пароль для рута');"
 # mysql --database=mysql --execute="FLUSH privileges;"

Установка mysqltuner

 # cd /usr/ports/databases/mysqltuner && make install clean
 # mysqltuner.pl

Cсылки

Комментарии

 
blog/2011/12/07-freebsd_-_установка_настройка_apache_php_mysql.txt · Последние изменения: 2011/12/07 17:58 — Антон Бугреев · []