ソースコードコンパイルインストールApache、Nginx、MySQL、PHP


ソースコンパイルapache
[root@localhost ~]# yum -y install pcre-devel expat-devel gcc gcc-c++
root@localhost ~]# tar -xzf apr-util-1.6.1.tar.gz 
[root@localhost ~]# tar -xzf httpd-2.4.39.tar.gz 
[root@localhost ~]# cd apr-1.7.0/
[root@localhost apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@localhost apr-1.7.0]# make -j4
[root@localhost apr-1.7.0]# make install
[root@localhost apr-1.7.0]# ls /usr/local/apr/
bin  build-1  include  lib
[root@localhost apr-1.7.0]# cd /root/apr-util-1.6.1/
[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@localhost apr-util-1.6.1]# make -j4
[root@localhost apr-util-1.6.1]# make install
[root@localhost apr-util-1.6.1]# ls /usr/local/apr-util/
bin  include  lib
[root@localhost apr-util-1.6.1]# cd /root/httpd-2.4.39/
[root@localhost httpd-2.4.39]# ./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most
[root@localhost httpd-2.4.39]# make -j4
[root@localhost httpd-2.4.39]# make install
[root@localhost httpd-2.4.39]# ls /usr/local/apache/
bin    cgi-bin  error   icons    logs  manual
build  conf     htdocs  include  man   modules
[root@localhost httpd-2.4.39]# cd /usr/local/apache/
[root@localhost apache]# ./bin/apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message                :                
[root@localhost apache]# ./bin/httpd -l
Compiled in modules:
  core.c
  mod_so.c
  http_core.c
  event.c             apache     event.c  

Nginxソースコードコンパイル
[root@localhost ~]# yum -y install gcc gcc-c++ pcre-devel openssl-devel zlib-devel
[root@localhost ~]# tar -xzf nginx-1.15.4.tar.gz 
[root@localhost ~]# cd nginx-1.15.4/
[root@localhost nginx-1.15.4]# useradd -M -s /sbin/nologin nginx
[root@localhost nginx-1.15.4]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module
[root@localhost nginx-1.15.4]# make -j4
[root@localhost nginx-1.15.4]# make install
[root@localhost nginx-1.15.4]# ls /usr/local/nginx/
conf  html  logs  sbin
[root@localhost nginx-1.15.4]# ln -s /usr/local/nginx/sbin/* /usr/sbin/
[root@localhost nginx-1.15.4]# vim /etc/init.d/nginx                                nginx    
[root@localhost nginx-1.15.4]# chmod +x /etc/init.d/nginx 
[root@localhost nginx-1.15.4]# chkconfig --add nginx
[root@localhost nginx-1.15.4]# service nginx start
[root@localhost nginx-1.15.4]# nginx -t                                             nginx    
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@localhost nginx-1.15.4]# nginx                                                nginx  
[root@localhost nginx-1.15.4]# killall -s HUP nginx

Nginx状態クエリーを開く
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
 42         location /status {
 43             stub_status on;
 44         }

nginx起動スクリプト
#! /bin/bash
# desription: this is a script of nginx
# chkconfig: 2345 99 99

CMD="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"

case "$1" in
    start)
        $CMD
        echo "starting...       SUCCESS"
        ;;
    stop)
        kill -s QUIT $(cat $PIDF)
        echo "stopting...       SUCCESS"
        ;;
    reload)
        kill -s HUP $(cat $PIDF)
        echo "reloading...      SUCCESS"
        ;;
    restart)
        $0 stop
        $0 start
        ;;
    status)
        if [ -f $PIDF ]
            then echo "nginx is running now"
        else
            echo "nginx is not running"
        fi
        ;;
    *)
        echo "Usage: $0 { start | stop | restart | reload | status }"
        exit 0
        ;;
esac
exit 0


MySQLソースコンパイルインストール
[root@localhost ~]# yum -y install gcc gcc-c++ cmake bison ncurses-devel
[root@localhost ~]# tar -xzf mysql-5.5.22.tar.gz 
[root@localhost ~]# cd mysql-5.5.22/
[root@localhost mysql-5.5.22]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DWITH_MYISAM_STORAGE_ENGINE=1 -DSYSCONFDIR=/etc
[root@localhost mysql-5.5.22]# make -j4
[root@localhost mysql-5.5.22]# make install
[root@localhost mysql-5.5.22]# useradd -M -s /sbin/nologin mysql
[root@localhost mysql-5.5.22]# ln -s /usr/local/mysql/bin/* /usr/bin/
[root@localhost mysql-5.5.22]# ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/local/lib
[root@localhost mysql-5.5.22]# cd support-files/
[root@localhost support-files]# cp my-large.cnf /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? y
[root@localhost support-files]# cp mysql.server /etc/init.d/mysqld
[root@localhost support-files]# vim /etc/init.d/mysqld                 
 46 basedir=/usr/local/mysql
 47 datadir=/usr/local/mysql/data
[root@localhost support-files]# chmod +x /etc/init.d/mysqld 
[root@localhost support-files]# /usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
[root@localhost support-files]# chkconfig --add mysqld
[root@localhost support-files]# service mysqld start
Starting MySQL.. SUCCESS! 
[root@localhost support-files]# mysqladmin -uroot password 123.com
[root@localhost support-files]# mysql -uroot -p123.com

PHPソースコードコンパイルインストール
[root@localhost ~]# yum -y install libxml2-devel libjpeg-devel libpng-devel gd zlib-devel opnessl-devel pcre-devel gcc gcc-c++
[root@localhost ~]# tar -xzf php-7.2.0.tar.gz 
[root@localhost ~]# cd php-7.2.0/
[root@localhost php-7.2.0]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --with-jpeg-dir=/usr/lib --with-zlib --with-gd --enable-mbstring --enable-fpm
--with-apxs2=/usr/local/apache/bin/apxs                      LAMP     
[root@localhost php-7.2.0]# make
[root@localhost php-7.2.0]# make install
[root@localhost php-7.2.0]# cp php.ini-development /usr/local/php/php.ini
[root@localhost php-7.2.0]# vim /usr/local/php/php.ini                               off   On
 192 short_open_tag = On
[root@localhost php-7.2.0]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-7.2.0]# chmod +x /etc/init.d/php-fpm 
[root@localhost php-7.2.0]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@localhost php-7.2.0]# vim /usr/local/php/etc/php-fpm.conf              
 17 pid = run/php-fpm.pid                 pid  
 24 error_log = log/php-fpm.log             
 48 emergency_restart_threshold = 10                    
 56 emergency_restart_interval = 20s                
 69  process.max = 128                            
 85 rlimit_files = 1024                           
100 events.mechanism = epoll            php  epll  
[root@localhost php-7.2.0]# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

LAMPでのPHP取付
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --with-jpeg-dir=/usr/lib --with-zlib --with-gd --enable-mbstring --enable-fpm --with-apxs2=/usr/local/apache/bin/apxs

[root@localhost php-7.2.0]# vim /usr/local/apache/conf/httpd.conf       apache     
252     DirectoryIndex index.php index.html
390     AddType application/x-httpd-php .php
      apache
[root@localhost ~]# cp -r DiscuzX/upload/* /usr/local/apache/htdocs/
[root@localhost ~]# chmod -R 777 /usr/local/apache/htdocs/*
[root@localhost ~]# firefox 127.0.0.1/install

LNMPでのPHP取付
[root@localhost php-7.2.0]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --with-jpeg-dir=/usr/lib --with-zlib --with-gd --enable-mbstring --enable-fpm
[root@localhost php-7.2.0]# vim /usr/local/nginx/conf/nginx.conf                       
[root@localhost php-7.2.0]# /etc/init.d/php-fpm start
Starting php-fpm  done
[root@localhost php-7.2.0]# service nginx restart
stopting...	SUCCESS
starting...	SUCCESS
root@localhost php-7.2.0]# vim /usr/local/nginx/html/test.php



[root@localhost php-7.2.0]# vim /usr/local/nginx/conf/nginx.conf 
 43         location / {
 44             root   html;
 45             index index.php index.html index.htm;
 46         }
 65         location ~ \.php$ {
 66             root           html;
 67             fastcgi_pass   127.0.0.1:9000;
 68             fastcgi_index  index.php;
 69             fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script    _name;
 70             include        fastcgi.conf;
 71         }


データベースの接続

$conn = new mysqli("127.0.0.1","root","123.com","test");
if (!$conn)
        die("connect error:" .mysqli_connect_error());
else
        echo "connect mysql server successfully
"
?>

フォーラムの導入
[root@localhost ~]# mv /usr/local/nginx/html/* /opt/
[root@localhost ~]# unzip ComsenzDiscuz-DiscuzX-master.zip     
[root@localhost ~]# cp -R DiscuzX/upload/* /usr/local/nginx/html/
[root@localhost ~]#  chmod -R  777 /usr/local/nginx/html/*
[root@localhost ~]# firefox http://127.0.0.1/install/