linux php编译安装mysql_Linux下编译安装apche+php+mysql

近些日子经常性的要在Linux下配置apache+php+mysql的环境。以前的时候我总是在centos下使用yum的方式直接安装。方便是很方便。但是总觉得少了什么。而且Centos下的默认的源对PHP只支持到5.1.6要Update必须要换源,前面也找了一些源发现很多都已经不能用了。很是麻烦。所以一狠心。直接使用编译的方式安装了。现在分享下我的安装过程。

首先安装GCC GCC-C++这两个编译器。这两个编译器无所谓版本高低。所以就直接使用yum的方式安装了。

yum install gcc gcc-c++

那么我们需要安装的那些个包我这里已经提供了下载。我们可以ba把bao包放在/usr/local/src下

然后我们开始安装MySQL

首先安装下Ncurese

tar -zxvf ncurese-5.9.tar.gz

cd ncurese-5.9

./configure

make && make install

安装完成后我们就可以开始安装MySQL了:

tar -zxvf mysql-5.1.68.tar.gz

./configure --prefix=/usr/local/mysql --sysconfdir=/etc --datadir=/svr/mysqldata --with-charset=utf8 --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-ssl --with-embedded-server --enable-local-infile --enable-assembler --with-plugins=innobase --with-plugins=partition

make && make install

安装wan完MySQL我们就可以开始配置MySQL了

配置MySQL

#1.新建mysql的用户和用户组

groupadd mysql

useradd -g mysql -s /sbin/nologin mysql

#2.配置路劲信息

chown -R mysql:mysql /usr/local/mysql/ 把MySQL目录的权限给MySQL用户和组

#3.创建配置文件

cp /usr/local/src/mysql-5.1.68/support-files/my-medium.cnf /etc/my.cnf

#然后编辑/etc/my.cnf

vi /etc/my.cnf

在[mysqld]下添加datadir = 一开始设置的目录/svr/mysqldata

#4.初始化数据库

/usr/local/mysql/bin/mysql_install_db --user=mysql

#5.将mysqldata的数据库目录权限给mysql用户

chown -R mysql:mysql /svr/mysqldata

#6.启动mysql

/usr/local/mysql/bin/mysqld_safe --user=mysql &

#7.将mysql加入service

cp /usr/local/src/mysql-5.1.68/support-files/mysql.server /etc/init.d/mysqld

chmod 755 /etc/init.d/mysqld

chkconfig --add mysqld

chkconfig mysqld on

service mysqld restart

#8.给Root加上密码

/usr/local/mysql/bin/mysqladmin -uroot -p password 新密码

好,现在我们MySQL的安装就完成了。那么让我们开始Apache的安装

首先我们先安装下apr和apr-util

#apr的安装

tar -zxvf apr-1.4.6.tar.gz

cd apr-1.4.6

./configure

make && make install

#apr-util的安装

tar -zxvf apr-util-1.5.2.tar.gz

cd apr-util-1.5.2

./configure --with-apr=/usr/local/apr/

make && make install

OK然后我们下一步就可以开始安装apache了。

tar -zxvf httpd-2.2.24.tar.gz

cd httpd-2.2.24

./configure --prefix=/usr/local/apache2 --enable-so --enable-rewrite --enable-mods-shared=most --enable-dav --with-apr=/usr/local/apr/bin/apr-1-config --with-apr-util=/usr/local/apr/bin/apu-1-config --enable-modules=so --enable-maintainer-mode

make && make install

apachee安装完成后我们先不忙着配置。等PHP安装完成后一起配置。那么我们下一步开始安装PHP。

首先安装zlib

tar -zxvf zlib-1.2.7.tar.gz

cd zlib-1.2.7

./configure

make && make install

然后安装Libmcrypt

tar -zxvf libmcrypt-2.5.8.tar.gz

cd libmcrypt-2.5.8

./configure

make

make install

cd libltdl

./configure --enable-ltdl-install

make

make install

然后再来安装libpng

tar -zxvf libpng-1.6.1.tar.gz

cd libpng-1.6.1

./configure

make && make install

然后来安装jpeg6

tar -zxvf jpegsrc.v6b.tar.gz

cd jpeg-6b

mkdir /usr/local/jpeg6

mkdir /usr/local/jpeg6/bin

mkdir /usr/local/jpeg6/lib

mkdir /usr/local/jpeg6/include

mkdir -p /usr/local/jpeg6/man/man1

./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static

make

make install

再来安装freetype

tar -zxvf freetype-2.4.0.tar.gz

cd freetype-2.4.0

./configure --prefix=/usr/local/freetype/make

make install

然后安装gd库

tar -zxvf gd-2.0.35.tar.gz

cd gd-2.0.35

./configure --prefix=/usr/local/gd2/ --with-jpeg=/usr/local/jpeg6/ --with-freetype=/usr/local/freetype/

make

make install

再来安装libxml

tar -zxvf libxml2-2.7.3.tar.gz

cd libxml2-2.7.3

./configure

make

make install

最后来安装CURL

tar -zxvf curl-7.29.0.tar.gz

cd curl-7.29.0

./configure --prefix=/usr/local/curl/

make

make install

安装完成后我们就可以开始安装PHP了

tar -zxvf php-5.2.17.tar.gz

cd php-5.2.17

./configure --prefix=/usr/local/php/ --with-apxs2=/usr/local/apache2/bin/apxs --disable-debug --enable-safe-mode --enable-xml --with-mysql=/usr/local/mysql --with-gd=/usr/local/gd2 --with-zlib --with-zlib-dir=/usr/local/lib --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock --disable-posix --with-config-file-path=/usr/local/lib --with-jpeg-dir=/usr/local/jpeg6 --with-curl=/usr/local/curl/ --enable-zip --enable-mbstring --enable-pdo --with-pdo_mysql=/usr/local/mysql/ --enable-soap --with-png-dir=/usr/local/lib --with-freetype-dir=/usr/local/freetype --enable-zip --enable-json --enable-sockets --with-iconv

make

make install

然后我们创建PHP的配置文件

cp php.ini-dist /usr/local/php/lib/php.ini

最后我们来配置Apache的配置文件

vi /usr/local/apache2/conf/httpd.conf

#添加:

AddType application/x-httpd-php .php

AddType application/x-httpd-php-source .phps

#注意将这两行添加在其它AddType后面

#确保文件中有下面一段,如果没有地话就添加在所有LoadModule之后

LoadModule php5_module modules/libphp5.so

#由于我装地版本较高所以是php5,如果是LoadModule php4_module #modules/libphp4.so地话也可以

#找到DirectoryIndex index.html index.html.var 这一行,在其后面写上index.php 一般在424行

#保存退出

然后ba把Apache加入系统服务

cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd

vi /etc/rc.d/init.d/httpd

#找到“#!/bin/sh”,另起一行,增加:

# chkconfig: 35 70 30

# description: Apache

#保存退出

chkconfig --add httpd

chkconfig httpd on

service httpd start

#这个时候如果报错。并且报错的信息如下

#Cannot load /usr/local/apache2/modules/libphp5.so into server: /usr/local/apache2/modules/libphp5.so: cannot restore segment prot after reloc: Permission denied

#那么请执行

chcon -c -v -R -u system_u -r object_r -t textrel_shlib_t /usr/local/apache2/modules/libphp5.so

#然后再

service httpd start

#成功开启后如果发现访问不了。请在防火墙中开启80端口和3306端口的访问

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值