CentOS 5.11 編譯安裝 LAMP Linux + Httpd + MariaDB + PHP
選擇Server安裝(無GUI) cd /usr/local/bin 設定防火牆 vi firewall.sh 變更權限 chmod +x firewall.sh 啟動防火牆 firewall.sh start 設定開機執行 vi /etc/rc.local /usr/local/bin/firewall.sh start 設定 selinux vi /etc/sysconfig/selinux 關閉 selinux SELINUX=disabled 關閉 ip6tables chkconfig ip6tables off yum -y remove bind-* mysql-* postgresql-* httpd-* php-* yum -y install bind97 bind97-chroot bind97-utils yum -y install sendmail sendmail-cf cyrus-sasl cyrus-sasl-gssapi cyrus-sasl-ntlm cyrus-sasl-md5 cyrus-sasl-plain dovecot yum -y install ntp wget lynx nmap crontabs mlocate bzip2 subversion ImageMagick-* boost-* GeoIP-* 重新開機 reboot 查看是否有啟動 chroot vi /etc/sysconfig/named /usr/sbin/rndc-confgen -a /usr/sbin/rndc-confgen > /etc/rndc.conf vi /etc/rndc.key vi /etc/rndc.conf vi /etc/named.conf 將 127.0.0.1 改為 any 將 localhost 改為 any vi /etc/named.rfc1912.zones 最下面加入 zone "odyssey.idv.tw" IN { type master; file "named.odyssey.idv.tw"; allow-update { none; }; }; 快速方法 先把檔案傳到 /var/named/chroot/var/named 再做權限變更 chown root.named named.* chmod 640 named.* 然後移動檔案至 /var/named mv named.* /var/named 啟動 named /etc/rc.d/init.d/named start 開機啟動 chkconfig named on 編輯 dovecot 設定檔 vi /etc/dovecot.conf protocols = imap imaps pop3 pop3s 啟動 pop3 /etc/rc.d/init.d/dovecot start 開機啟動 chkconfig dovecot on 啟動認證 /etc/rc.d/init.d/saslauthd start 開機啟動 chkconfig saslauthd on 複製 sendmail 設定檔 cp /etc/mail/sendmail.mc /usr/share/sendmail-cf/cf/ 編輯設定檔 vi +/TRUST /usr/share/sendmail-cf/cf/sendmail.mc 找到 dnl TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl 改成 TRUST_AUTH_MECH(`EXTERNAL GSSAPI NTLM DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl 找到 dnl define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl 改成 define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI NTLM DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl 找到 DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl 改成 DAEMON_OPTIONS(`Port=smtp,Addr=0.0.0.0, Name=MTA')dnl 找到 dnl MASQUERADE_AS(`mydomain.com')dnl 改成 MASQUERADE_AS(`您的網域名稱')dnl 找到 dnl FEATURE(masquerade_envelope)dnl 改成 FEATURE(masquerade_envelope)dnl 找到 dnl FEATURE(masquerade_entire_domain)dnl 改成 FEATURE(masquerade_entire_domain)dnl 找到 dnl MASQUERADE_DOMAIN(localhost.localdomain)dnl 改成 MASQUERADE_DOMAIN(localhost.localdomain)dnl 切換目錄 cd /usr/share/sendmail-cf/cf/ 編譯設定檔 ./Build sendmail.cf 移動設定檔 mv /etc/mail/sendmail.cf /etc/mail/sendmail.cf.old 複製設定檔 cp sendmail.cf /etc/mail/ 設定接收的網域 vi /etc/mail/local-host-names 設定郵件帳號對應 vi /etc/mail/virtusertable 重新啟動 sendmail 服務 /etc/rc.d/init.d/sendmail restart vi /etc/profile export LD_LIBRARY_PATH=/usr/local/lib export LD_RUN_PATH=/usr/local/lib 安裝編譯所需要的函示庫 yum -y install gcc gcc-c++ make automake autoconf kernel-devel ncurses-devel curl gd file patch mlocate diffutils curl-devel gd-devel gettext-devel glibc-devel glib2-devel libstdc++-devel libjpeg-devel libmcrypt-devel libpng-devel libxslt-devel libxml2-devel openssl-devel pcre-devel zlib-devel bison bison-devel pam-devel libc-client libc-client-devel 重開機 reboot 先切換到目錄 cd /usr/local/src 安裝 libtool http://ftp.gnu.org/gnu/libtool/ lynx http://ftp.gnu.org/gnu/libtool/libtool-2.4.6.tar.gz tar zxf libtool-2.4.6.tar.gz cd libtool-2.4.6 ./configure && make -j2 && make install && make clean cd .. 安裝 libevent http://libevent.org/ lynx https://sourceforge.net/projects/levent/files/libevent/libevent-2.0/libevent-2.0.22-stable.tar.gz (得用瀏覽器下載) tar zxf libevent-2.0.22-stable.tar.gz cd libevent-2.0.22-stable ./configure && make -j2 && make install && make clean cd .. 安裝 memcached http://memcached.org/ lynx http://www.memcached.org/files/memcached-1.4.22.tar.gz tar zxf memcached-1.4.22.tar.gz cd memcached-1.4.22 ./configure --with-libevent && make -j2 && make install && make clean cd .. 開機啟動 vi /etc/rc.local /usr/local/bin/memcached -u daemon -d -l 127.0.0.1 -p 11211 -m 12 安裝 redis http://redis.io/ lynx http://download.redis.io/releases/redis-3.2.1.tar.gz tar zxf redis-3.2.1.tar.gz cd tar zxf redis-3.2.1 make make install -- make 32bit make PREFIX=/usr/local/redis install cd utils ./install_server.sh 啟動 redis /usr/local/bin/redis-server /etc/redis/6379.conf 命令列 /usr/local/bin/redis-cli 下載 cmake http://www.cmake.org/ lynx https://cmake.org/files/v3.5/cmake-3.5.2.tar.gz 安裝 cmake tar zxf cmake-3.5.2.tar.gz cd cmake-3.5.2 ./configure && make -j2 && make install && make clean cd .. 下載 mariadb https://mariadb.org/ lynx http://ftp.yz.yamagata-u.ac.jp/pub/dbms/mariadb//mariadb-10.1.14/source/mariadb-10.1.14.tar.gz 安裝 mariadb tar zxf mariadb-10.1.14.tar.gz cd mariadb-10.1.14 /usr/local/bin/cmake . -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci && gmake -j2 && gmake install && gmake clean 切換到目的目錄 cd /usr/local/mysql 新增 mysql 使用者和群組 useradd -r mysql 變更擁有者 chown -R mysql . 變更群組 chgrp -R mysql . 安裝預設資料 scripts/mysql_install_db --user=mysql 變更程式擁有者為 root chown -R root . 變更資料擁有者為 mysql chown -R mysql data 複製設定檔 cp support-files/my-huge.cnf /etc/my.cnf 編輯設定檔 vi /etc/my.cnf character-set-server = utf8 collation-server = utf8_general_ci default_storage_engine = MyISAM skip-external-locking thread_concurrency skip-networking 啟動 mysql /usr/local/mysql/bin/mysqld_safe --datadir=/var/lib/mysql & 開機啟動 vi /etc/rc.local /usr/local/mysql/bin/mysqld_safe --datadir=/var/lib/mysql & 設定 root 帳號密碼 /usr/local/mysql/bin/mysqladmin -u root password '新密碼' 登入 mysql /usr/local/mysql/bin/mysql -u root -p use mysql; delete from user where Host <> 'localhost' or User <> 'root'; exit; 切換到原始碼目錄 cd /usr/local/src 下載 postgresql http://www.postgresql.org/ lynx https://ftp.postgresql.org/pub/source/v9.5.3/postgresql-9.5.3.tar.bz2 安裝 postgresql tar jxf postgresql-9.5.3.tar.gz cd postgresql-9.5.3 ./configure --prefix=/usr/local/pgsql --without-readline && gmake -j2 && gmake install && gmake clean 新增使用者 postgres useradd postgres 建立資料目錄 mkdir /usr/local/pgsql/data 變更資料擁有者 chown postgres /usr/local/pgsql/data 切換使用者 su - postgres 初始化資料 /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data 編輯設定檔 vi /usr/local/pgsql/data/postgresql.conf vi /usr/local/pgsql/data/pg_ident.conf vi /usr/local/pgsql/data/pg_hba.conf 讓區網或特定IP直接連線(Default Port 5432) host all all 192.168.1.0/24 trust 啟動 pgsql (須用 postgres 使用者啟動) /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start 登入 postgresql /usr/local/pgsql/bin/psql 設定 postgres 密碼 alter role postgres with password '12345678'; 登出 postgresql \q 登出 postgres 使用者 exit 切換目錄 cd /usr/local/src 下載 sqlite https://www.sqlite.org/ lynx https://www.sqlite.org/2016/sqlite-autoconf-3130000.tar.gz 安裝 sqlite tar zxf sqlite-autoconf-3130000.tar.gz cd sqlite-autoconf-3130000 ./configure --prefix=/usr/local/sqlite3 && make -j2 && make install && make clean 執行檔位置 /usr/local/sqlite3/bin/sqlite3 切換目錄 cd /usr/local/src 下載 imap ftp://ftp.cac.washington.edu/imap/ wget ftp://ftp.cac.washington.edu/imap/imap-2007f.tar.gz 安裝 imap tar zxf imap-2007f.tar.gz cd imap-2007f make lr5 PASSWDTYPE=std SSLTYPE=unix.nopwd IP6=4 echo "set disable-plaintext nil" > /etc/c-client.cf mkdir /usr/local/imap-2007f mkdir /usr/local/imap-2007f/include/ mkdir /usr/local/imap-2007f/lib/ chmod -R 077 /usr/local/imap-2007f rm -rf /usr/local/imap-2007f/include/* rm -rf /usr/local/imap-2007f/lib/* cp imapd/imapd /usr/sbin/ cp c-client/*.h /usr/local/imap-2007f/include/ cp c-client/*.c /usr/local/imap-2007f/lib/ cp c-client/c-client.a /usr/local/imap-2007f/lib/libc-client.a 切換目錄 cd /usr/local/src 下載 apr http://apr.apache.org/ lynx ftp://ftp.twaren.net/Unix/Web/apache//apr/apr-1.5.2.tar.bz2 安装 apr tar jxf apr-1.5.2.tar.bz2 cd apr-1.5.2 ./configure --prefix=/usr/local/apr && make -j2 && make install && make clean cd .. 下載 apr-util http://apr.apache.org/ lynx ftp://ftp.twaren.net/Unix/Web/apache//apr/apr-util-1.5.4.tar.bz2 安装 apr-util tar jxf apr-util-1.5.4.tar.bz2 cd apr-util-1.5.4 ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config && make -j2 && make install && make clean cd .. 下載 apr-iconv http://apr.apache.org/ lynx ftp://ftp.twaren.net/Unix/Web/apache//apr/apr-iconv-1.2.1.tar.bz2 安装 apr-iconv tar jxf apr-iconv-1.2.1.tar.bz2 cd apr-iconv-1.2.1 ./configure --prefix=/usr/local/apr-iconv --with-apr=/usr/local/apr/bin/apr-1-config && make -j2 && make install && make clean cd .. 下載 httpd http://httpd.apache.org/ 安裝 httpd 2.4.7 tar zxf httpd-2.4.7.tar.gz cd httpd-2.4.7 ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-apr-iconv=/usr/local/apr-iconv --enable-mods-shared=all --enable-mpms-shared=all --enable-static-support && make -j2 && make install && make clean cd .. 下載 php http://www.php.net/ lynx http://jp2.php.net/distributions/php-5.6.22.tar.bz2 lynx http://jp2.php.net/distributions/php-7.0.7.tar.bz2 安裝參數 ./configure --help 安裝 php-5.6.22 tar jxf php-5.6.22.tar.bz2 cd php-5.6.22 # 自訂版(請自行依當時編譯情況更動) ./configure --prefix=/usr/local/php5 --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-apxs2=/usr/local/apache2/bin/apxs --enable-maintainer-zts --with-tsrm-pthreads --enable-bcmath --with-bz2 --enable-calendar --enable-cgi --enable-cli --enable-ctype --with-curl --enable-dom --without-enchant --enable-exif --enable-fileinfo --enable-filter --enable-ftp --disable-fpm --with-gd --with-gettext --enable-hash --with-iconv --with-imap=/usr/local/imap-2007f --with-imap-ssl=/usr/local/imap-2007f --disable-intl --enable-json --enable-libxml --enable-mbstring --with-mcrypt --with-mhash --enable-mysqlnd --with-mysqli=mysqlnd --with-mysql-sock --enable-opcache --with-openssl --enable-pcntl --without-pear --with-pdo-mysql=mysqlnd --with-pdo-pgsql --with-pgsql=/usr/local/pgsql --enable-phar --enable-posix --enable-session --enable-shmop --enable-simplexml --enable-soap --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-tokenizer --enable-wddx --enable-xml --enable-xmlreader --with-xmlrpc --with-xsl --enable-zip --with-zlib # 完整版 ./configure --prefix=/usr/local/php5 --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-apxs2=/usr/local/apache2/bin/apxs --enable-maintainer-zts --with-tsrm-pthreads --enable-bcmath --with-bz2 --enable-calendar --enable-cgi --enable-cli --enable-ctype --with-curl --enable-dom --without-enchant --enable-exif --enable-fileinfo --enable-filter --enable-ftp --enable-fpm --with-gd --with-gettext --enable-hash --with-iconv --without-imap --disable-intl --enable-json --enable-libxml --enable-mbstring --with-mcrypt --with-mhash --enable-mysqlnd --with-mysqli=mysqlnd --with-mysql-sock --enable-opcache --with-openssl --enable-pcntl --without-pear --with-pdo-mysql=mysqlnd --with-pdo-pgsql --with-pdo-sqlite --with-pgsql=/usr/local/pgsql --enable-phar --enable-posix --enable-session --enable-shmop --enable-simplexml --enable-soap --enable-sockets --with-sqlite3=/usr/local/sqlite3 --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-tokenizer --enable-wddx --enable-xml --enable-xmlreader --with-xmlrpc --with-xsl --enable-zip --with-zlib 安裝 php-7.0.7 tar jxf php-7.0.7.tar.bz2 cd php-7.0.7 # 自訂版(請自行依當時編譯情況更動) ./configure --prefix=/usr/local/php7 --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-apxs2=/usr/local/apache2/bin/apxs --enable-maintainer-zts --with-tsrm-pthreads --enable-bcmath --with-bz2 --enable-calendar --enable-cgi --enable-cli --enable-ctype --with-curl --enable-dom --without-enchant --enable-exif --enable-fileinfo --enable-filter --enable-ftp --disable-fpm --with-gd --with-gettext --enable-hash --with-iconv --with-imap=/usr/local/imap-2007f --with-imap-ssl=/usr/local/imap-2007f --disable-intl --enable-json --enable-libxml --enable-mbstring --with-mcrypt --with-mhash --enable-mysqlnd --with-mysqli=mysqlnd --with-mysql-sock --enable-opcache --with-openssl --enable-pcntl --without-pear --with-pdo-mysql=mysqlnd --with-pdo-pgsql --with-pgsql=/usr/local/pgsql --enable-phar --enable-posix --enable-session --enable-shmop --enable-simplexml --enable-soap --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-tokenizer --enable-wddx --enable-xml --enable-xmlreader --with-xmlrpc --with-xsl --enable-zip --with-zlib # 完整版 ./configure --prefix=/usr/local/php7 --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-apxs2=/usr/local/apache2/bin/apxs --enable-maintainer-zts --with-tsrm-pthreads --enable-bcmath --with-bz2 --enable-calendar --enable-cgi --enable-cli --enable-ctype --with-curl --enable-dom --without-enchant --enable-exif --enable-fileinfo --enable-filter --enable-ftp --enable-fpm --with-gd --with-gettext --enable-hash --with-iconv --without-imap --disable-intl --enable-json --enable-libxml --enable-mbstring --with-mcrypt --with-mhash --enable-mysqlnd --with-mysqli=mysqlnd --with-mysql-sock --enable-opcache --with-openssl --enable-pcntl --without-pear --with-pdo-mysql=mysqlnd --with-pdo-pgsql --with-pdo-sqlite --with-pgsql=/usr/local/pgsql --enable-phar --enable-posix --enable-session --enable-shmop --enable-simplexml --enable-soap --enable-sockets --with-sqlite3=/usr/local/sqlite3 --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-tokenizer --enable-wddx --enable-xml --enable-xmlreader --with-xmlrpc --with-xsl --enable-zip --with-zlib make -j2 make install make clean 複製設定檔 cp php.ini-production /etc/php.ini 編輯 httpd 設定檔 vi /usr/local/apache2/conf/httpd.conf 新增 PHP 支援 LoadModule php5_module modules/libphp5.so SetHandler application/x-httpd-php DirectoryIndex index.php index.htm index.html 變更預設伺服器資訊 ServerAdmin ServerName DirectoryIndex index.php index.htm index.html Include conf/extra/httpd-mpm.conf Include conf/extra/httpd-vhosts.conf Include conf/extra/httpd-default.conf 將 php 加入系統環境變數 vi /etc/profile 在最後面加入 export PATH=$PATH:/usr/local/php5/bin 開機啟動 vi /etc/rc.local /usr/local/apache2/bin/apachectl start 啟動 httpd /usr/local/apache2/bin/apachectl start 下載 php imagick http://pecl.php.net/package/imagick lynx http://pecl.php.net/get/imagick-3.1.2.tgz 安裝 php imagick tar zxf imagick-3.1.2.tgz cd imagick-3.1.2 /usr/local/php5/bin/phpize ./configure --with-php-config=/usr/local/php5/bin/php-config --with-imagick && make -j2 && make install && make clean cd .. vi /etc/php.ini extension=imagick.so 下載 php memcached extension http://pecl.php.net/package/memcache lynx http://pecl.php.net/get/memcache-3.0.8.tgz 安裝 php memcache tar zxf memcache-3.0.8.tgz cd memcache-3.0.8 /usr/local/php5/bin/phpize ./configure --with-php-config=/usr/local/php5/bin/php-config --with-memcached && make -j2 && make install && make clean cd .. vi /etc/php.ini extension=memcache.so 下載 php redis https://github.com/phpredis/phpredis/releases tar zxf phpredis-2.2.8.tar.gz cd phpredis-2.2.8 /usr/local/php5/bin/phpize ./configure --with-php-config=/usr/local/php5/bin/php-config && make -j2 && make install && make clean vi /usr/local/php5/etc/php.ini extension=redis.so 下載 php geoip https://pecl.php.net/package/geoip lynx https://pecl.php.net/get/geoip-1.0.8.tgz 安裝 php geoip tar zxf geoip-1.0.8.tgz cd geoip-1.0.8 /usr/local/php5/bin/phpize ./configure --with-php-config=/usr/local/php5/bin/php-config --with-geoip && make -j2 && make install && make clean cd .. vi /etc/php.ini extension=geoip.so ----------------------------------------------------------------------------------------- 切換 PHP 5 -> 7 版本 編輯 httpd 設定 vi /usr/local/apache2/conf/httpd.conf 加上註解 PHP5 #LoadModule php5_module modules/libphp5.so 取消註解 PHP7 LoadModule php7_module modules/libphp7.so 重新啟動 /usr/local/apache2/bin/apachectl restart ----------------------------------------------------------------------------------------- vi /etc/ssh/sshd_config LoginGraceTime 2m PermitRootLogin yes StrictModes yes MaxAuthTries 6 PasswordAuthentication yes PermitEmptyPasswords no /etc/rc.d/init.d/sshd restart ----------------------------------------------------------------------------------------- vi +/ServerTokens /usr/local/apache2/conf/extra/httpd-default.conf ServerTokens Prod ServerSignature Off vi /usr/local/apache2/conf/extra/httpd-vhosts.conf vi +/expose_php /etc/php.ini expose_php = Off ----------------------------------------------------------------------------------------- Opcache 經查資料似乎須要 Thread Safe 未啟用時才能開啟 opcache.memory_consumption=128 opcache.interned_strings_buffer=8 opcache.max_accelerated_files=4000 opcache.revalidate_freq=60 opcache.fast_shutdown=1 opcache.enable_cli=1
新增時間 2019-12-31
最後更新 2022-02-09