源码编译安装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

<?php
phpinfo();
?>

[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         }

连接数据库
<?php
$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\n"
?>
论坛部署
[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/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值