apache2 源码编译 安装 mysql 源码编译安装 php 源码编译安装

参考文档 http://blog.sina.com.cn/s/blog_6294abe70101b4ck.html
http://blog.chinaunix.net/uid-23850972-id-2655932.html
http://blog.csdn.net/xinguan1267/article/details/7361367
enable-module=shared 指令将模块编译为可在运行时加载和卸载的动态共享对象(DSO)

sudo apt-get install libtool
libtool简单来讲是一个用户库安装工具,有以下几个特点
#自动处理库的依赖关系;
#对于共享库,自动加入运行时搜索路径



# 编译和安装 apr 1.5.2
wget http://archive.apache.org/dist/apr/apr-1.5.2.tar.gz
tar -zxvf apr-1.5.2.tar.gz
cd apr-1.5.2
./configure --prefix=/usr/local/apr
make
sudo make install
cd ..

# 编译和安装 apr-util 1.5.4
wget http://archive.apache.org/dist/apr/apr-util-1.5.4.tar.gz
tar -zxvf apr-util-1.5.4.tar.gz
cd apr-util-1.5.4
./configure  --prefix=/usr/local/apr-util  --with-apr=/usr/local/apr
make
sudo make install
cd ..

# 编译和安装 /pcre 8.36 可能需要安装g++
wget http://sourceforge.net/projects/pcre/files/pcre/8.36/pcre-8.36.zip
unzip pcre-8.36.zip
cd pcre-8.36/
./configure --prefix=/usr/local/pcre
make
sudo make install
cd ..


apache2
wget http://mirrors.sohu.com/apache/httpd-2.4.12.tar.gz
tar -zxvf httpd-2.4.12.tar.gz
cd httpd-2.4.12


cd httpd-2.4.12

./configure --prefix=/usr/local/apache2 --enable-module=shared  --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre
make
sudo make install


启动,重启和停止
/usr/local/apache/bin/apachectl -k start  

  (不加参数k也行) 
/usr/local/apache/bin/apachectl -k restart
/usr/local/apache/bin/apachectl -k stop


启动过程中会提示程序“apachectl”尚未安装。 您可以使用以下命令安装: sudo apt-getinstall apache2.2-common  然后在终端输入 sudoapt-get installapache2.2-common 完成后就可以启动了。启动的时候要用sudo 否则会报 (13)Permissiondenied: AH00072: make_sock: could not bind to address 0.0.0.0:80nolistening sockets available错误。还有一个解决办法是  Edit the config fileto change the port Apache uses to a number greater than 1024.

 

简单启动apache命令




配置文件

      gedit /usr/local/apache/conf/httpd.conf
       修改以下配置(当然这些修改是最基本的修改,如果要更高级的,参照其他Ubuntuapache配置手册)


  找到:
  AddType application/x-compress .Z
  AddType application/x-gzip .gz .tgz
  在后面添加:
  AddType application/x-httpd-php .php
  AddType application/x-httpd-php-source .phps



  找到:
 
  DirectoryIndex index.html
 
  在下面添加:
 
  DirectoryIndex index.html index.php
 



  找到:
  #ServerName www.example.com:80
  修改为:
  ServerName 127.0.0.1:80或者ServerNamelocalhost:80
  记得要去掉前面的“#”
  否则会出现以下错误提示:

  httpd: Could not reliably determine theserver's fully qualified domain name, using 127.0.1.1  forServerName  


安装mysql

wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.25.tar.gz

 tar -zxvf mysql-5.6.25.tar.gz
cd mysql-5.6.25

sudo apt-get install cmake 安装cmake


sudo apt-get install openssl
sudo apt-get install libssl-dev
RedHat、centos才是openssl-devel
安装 ncurses
sudo apt-get install libncurses5-dev

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1
make -j 2 && make install

添加mysql用户

sudo groupadd mysql
sudo useradd -s /sbin/nologin -M -g mysql mysql
 
参考配置
sudo vim  /etc/my.cnf

# Example MySQL config file for medium systems.

# The following options will be passed to all MySQL clients
[client]
#password   = your_password
port        = 3306
socket      = /tmp/mysql.sock
default-character-set=utf8mb4

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
bind-address=127.0.0.1
port        = 3306
socket      = /tmp/mysql.sock
datadir = /usr/local/mysql/var
collation-server     = utf8mb4_general_ci
character-set-server = utf8mb4
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M

# Replication Master Server (default)
# binary logging is required for replication
log-bin=mysql-bin

# binary logging format - mixed recommended
binlog_format=mixed

# required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id   = 1

# Uncomment the following if you are using InnoDB tables
innodb_data_home_dir = /usr/local/mysql/var
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /usr/local/mysql/var
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
innodb_buffer_pool_size = 16M
innodb_additional_mem_pool_size = 2M
# Set .._log_file_size to 25 % of buffer pool size
innodb_log_file_size = 5M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates
default-character-set=utf8mb4

[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout
 

初始化

/usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/var --user=mysql
chown -R mysql /usr/local/mysql/var
chgrp -R mysql /usr/local/mysql/.
cp support-files/mysql.server /etc/init.d/mysql
chmod 755 /etc/init.d/mysql

cat > /etc/ld.so.conf.d/mysql.conf<<EOF
/usr/local/mysql/lib
/usr/local/lib
EOF
ldconfig

启动

/etc/init.d/mysql start


5.6 报错

Failed to issue method call: Unit mysql.service failed to load: No such file or directory. See system logs and 'systemctl status mysql.service' for details.

解决方法

# systemctl enable mysql.service

后期配置

ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
ln -s /usr/local/mysql/include/mysql /usr/include/mysql
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
ln -s /usr/local/mysql/bin/mysqldump /usr/bin/mysqldump
ln -s /usr/local/mysql/bin/myisamchk /usr/bin/myisamchk
ln -s /usr/local/mysql/bin/mysqld_safe /usr/bin/mysqld_safe

可以登录了 

mysql -u root

修改密码

use mysql;
update user set password=password('$mysqlrootpwd') where user='root';
flush privileges;





安装php

php 源码编译



chinaunix.net

wget http://down1.chinaunix.net/distfiles/libiconv-1.14.tar.gz
tar -zxvf libiconv-1.14.tar.gzcd libiconv-1.14./configuremake -j 2

报错
gcc -DHAVE_CONFIG_H -DEXEEXT=\"\" -I. -I.. -I../lib  -I../intl -DDEPENDS_ON_LIBICONV=1 -DDEPENDS_ON_LIBINTL=1   -g -O2 -c -o width.o `test -f 'uniwidth/width.c' || echo './'`uniwidth/width.c
In file included from progname.c:26:0:
./stdio.h:1010:1: 错误: ‘gets’未声明(不在函数内)
gcc -DHAVE_CONFIG_H -DEXEEXT=\"\" -I. -I.. -I../lib  -I../intl -DDEPENDS_ON_LIBICONV=1 -DDEPENDS_ON_LIBINTL=1   -g -O2 -c xmalloc.c
make[2]: *** [progname.o] 错误 1
make[2]: *** 正在等待未完成的任务....
make[2]:正在离开目录 `/home/lenky/下载/libiconv-1.14/srclib'
make[1]: *** [all] 错误 2
make[1]:正在离开目录 `/home/lenky/下载/libiconv-1.14/srclib'
make: *** [all] 错误 2

解决方法:
lenky@robert-T430S:~/下载/libiconv-1.14$ vi srclib/stdio.h

到1010行,注释掉该行即可:
_GL_CXXALIASWARN (gets);
/* It is very rare that the developer ever has full control of stdin,
so any use of gets warrants an unconditional warning.  Assume it is
always declared, since it is required by C89.  */
//_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
#endif

重新make,OK。


&& make installcd ..

wget http://down1.chinaunix.net/distfiles/libmcrypt-2.5.7.tar.gz
tar -zxvf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
./configure
make -j 2&& make install
ldconfig
cd libltdl/
./configure --enable-ltdl-install
make && make install
cd ../../
 
wget http://down1.chinaunix.net/distfiles/mhash-0.9.3.tar.gz
tar -zxvf mhash-0.9.3.tar.gz
cd mhash-0.9.3
./configure
make -j 2 && make install
cd ../


wget http://mirrors.sohu.com/php/php-5.6.9.tar.gz

 tar -zxvf php-5.6.9.tar.gz

cd php-5.6.9

./configure --prefix=/usr/local/php 
--with-config-file-path=/usr/local/php/etc 
--enable-fpm --with-fpm-user=www 
--with-fpm-group=www 
--with-mysql=mysqlnd 
--with-mysqli=mysqlnd 
--with-pdo-mysql=mysqlnd 
--with-iconv-dir 
--with-freetype-dir 
--with-jpeg-dir 
--with-png-dir 
--with-zlib 
--with-libxml-dir=/usr 
--enable-xml 
--disable-rpath --enable-magic-quotes --enable-safe-mode --enable-bcmath 
--enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring 
--with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl 
--with-mhash --enable-pcntl --enable-sockets --with-xmlrpc 
--enable-zip --enable-soap --without-pear --with-gettext --disable-fileinfo

make -j 2 ZEND_EXTRA_LIBS='-liconv'

Ubuntu安装php即常见错误解决方法

参考 http://blog.sina.com.cn/s/blog_7718e4430101li7a.html 报错 configure: error: jpeglib.h not found
解决方法
sudo apt-get install libjpeg-dev

错误:
configure: error: png.h not found.
解决办法:
# sudo apt-get install libpng-dev

错误:
configure: error: freetype.h not found.
解决办法:
# sudo apt-get install libfreetype6-dev

make install

配置php

cp php.ini-production /usr/local/php/etc/php.ini
sed -i 's/post_max_size = 8M/post_max_size = 50M/g' /usr/local/php/etc/php.ini
sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 50M/g' /usr/local/php/etc/php.ini
sed -i 's/;date.timezone =/date.timezone = PRC/g' /usr/local/php/etc/php.ini
sed -i 's/short_open_tag = Off/short_open_tag = On/g' /usr/local/php/etc/php.ini
sed -i 's/; cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /usr/local/php/etc/php.ini
sed -i 's/; cgi.fix_pathinfo=0/cgi.fix_pathinfo=0/g' /usr/local/php/etc/php.ini
sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /usr/local/php/etc/php.ini
sed -i 's/max_execution_time = 30/max_execution_time = 300/g' /usr/local/php/etc/php.ini
sed -i 's/register_long_arrays = On/;register_long_arrays = On/g' /usr/local/php/etc/php.ini
sed -i 's/magic_quotes_gpc = On/;magic_quotes_gpc = On/g' /usr/local/php/etc/php.ini
sed -i 's/disable_functions =.*/disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server/g' /usr/local/php/etc/php.ini

后期配置

ln -s /usr/local/php/bin/php /usr/bin/php ln -s /usr/local/php/bin/phpize /usr/bin/phpize ln -s /usr/local/php/sbin/php-fpm /usr/bin/php-fpm cd ..

安装ZendGuardLoader

mkdir -p /usr/local/zend/
wget http://downloads.zend.com/guard/5.5.0/ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz
tar -zxvf ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz
cp ZendGuardLoader-php-5.3-linux-glibc23-x86_64/php-5.3.x/ZendGuardLoader.so /usr/local/zend/
cat >>/usr/local/php/etc/php.ini<<EOF
;eaccelerator

;ionCube

[Zend Optimizer] 
zend_extension=/usr/local/zend/ZendGuardLoader.so
zend_loader.enable=1
zend_loader.disable_licensing=0
zend_loader.obfuscation_level_support=3
zend_loader.license_path=
EOF

cd ..

修改php-fpm配置文件




cat >/usr/local/php/etc/php-fpm.conf<<EOF
[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
log_level = notice

[www]
listen = /tmp/php-cgi.sock
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.max_children = 10
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 6
request_terminate_timeout = 100
request_slowlog_timeout = 0
slowlog = var/log/slow.log
EOF


创建php-fpm启动脚本

vim /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm

以下是一份参考:

#! /bin/sh

### BEGIN INIT INFO
# Provides:          php-fpm
# Required-Start:    $remote_fs $network
# Required-Stop:     $remote_fs $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts php-fpm
# Description:       starts the PHP FastCGI Process Manager daemon
### END INIT INFO

prefix=/usr/local/php
exec_prefix=${prefix}

php_fpm_BIN=${exec_prefix}/sbin/php-fpm
php_fpm_CONF=${prefix}/etc/php-fpm.conf
php_fpm_PID=${prefix}/var/run/php-fpm.pid


php_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID"


wait_for_pid () {
    try=0

    while test $try -lt 35 ; do

        case "$1" in
            'created')
            if [ -f "$2" ] ; then
                try=''
                break
            fi
            ;;

            'removed')
            if [ ! -f "$2" ] ; then
                try=''
                break
            fi
            ;;
        esac

        echo -n .
        try=`expr $try + 1`
        sleep 1

    done

}

case "$1" in
    start)
        echo -n "Starting php-fpm "

        $php_fpm_BIN --daemonize $php_opts

        if [ "$?" != 0 ] ; then
            echo " failed"
            exit 1
        fi

        wait_for_pid created $php_fpm_PID

        if [ -n "$try" ] ; then
            echo " failed"
            exit 1
        else
            echo " done"
        fi
    ;;

    stop)
        echo -n "Gracefully shutting down php-fpm "

        if [ ! -r $php_fpm_PID ] ; then
            echo "warning, no pid file found - php-fpm is not running ?"
            exit 1
        fi

        kill -QUIT `cat $php_fpm_PID`

        wait_for_pid removed $php_fpm_PID

        if [ -n "$try" ] ; then
            echo " failed. Use force-quit"
            exit 1
        else
            echo " done"
        fi
    ;;

    force-quit)
        echo -n "Terminating php-fpm "

        if [ ! -r $php_fpm_PID ] ; then
            echo "warning, no pid file found - php-fpm is not running ?"
            exit 1
        fi

        kill -TERM `cat $php_fpm_PID`

        wait_for_pid removed $php_fpm_PID

        if [ -n "$try" ] ; then
            echo " failed"
            exit 1
        else
            echo " done"
        fi
    ;;

    restart)
        $0 stop
        $0 start
    ;;

    reload)

        echo -n "Reload service php-fpm "

        if [ ! -r $php_fpm_PID ] ; then
            echo "warning, no pid file found - php-fpm is not running ?"
            exit 1
        fi

        kill -USR2 `cat $php_fpm_PID`

        echo " done"
    ;;

    *)
        echo "Usage: $0 {start|stop|force-quit|restart|reload}"
        exit 1
    ;;

esac

启动

groupadd www
useradd -s /sbin/nologin -g www www

/etc/init.d/php-fpm start






# 编译和安装 apr-iconv 1.2.1
wget http://archive.apache.org/dist/apr/apr-iconv-1.2.1.tar.gz
tar -zxvf apr-iconv-1.2.1.tar.gz
cd apr-iconv-1.2.1
./configure  
make
sudo make install
cd ..



报错信息如下:

error info:rm: cannot remove `libtoolT': No such file or directory

解决方法如下:

打开configure文件

找到30055(不同的版本可能位置不一样)

将这行代码注释掉

# $RM "$cfgfile"

然后重新编译,问题可以解决



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值