近些日子经常性的要在Linux下配置apache+php+mysql的环境。以前的时候我总是在centos下使用yum的方式直接安装。方便是很方便。但是总觉得少了什么。而且Centos下的默认的源对PHP只支持到5.1.6要Update必须要换源,前面也找了一些源发现很多都已经不能用了。很是麻烦。所以一狠心。直接使用编译的方式安装了。现在分享下我的安装过程。
首先安装GCC GCC-C++这两个编译器。这两个编译器无所谓版本高低。所以就直接使用yum的方式安装了。
1 | yum install gcc gcc-c++ |
那么我们需要安装的那些个包我这里已经提供了下载。我们可以ba把bao包放在/usr/local/src下
然后我们开始安装MySQL
首先安装下Ncurese
1 | tar -zxvf ncurese-5.9. tar .gz |
安装完成后我们就可以开始安装MySQL了:
1 | tar -zxvf mysql-5.1.68. tar .gz |
2 | ./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 |
安装wan完MySQL我们就可以开始配置MySQL了
配置MySQL
03 | useradd -g mysql -s /sbin/nologin mysql |
05 | chown -R mysql:mysql /usr/ local /mysql/ 把MySQL目录的权限给MySQL用户和组 |
07 | cp /usr/ local /src/mysql-5.1.68/support-files/my-medium.cnf /etc/my.cnf |
10 | 在[mysqld]下添加datadir = 一开始设置的目录/svr/mysqldata |
12 | /usr/ local /mysql/bin/mysql_install_db --user=mysql |
14 | chown -R mysql:mysql /svr/mysqldata |
16 | /usr/ local /mysql/bin/mysqld_safe --user=mysql & |
18 | cp /usr/ local /src/mysql-5.1.68/support-files/mysql.server /etc/init.d/mysqld |
19 | chmod 755 /etc/init.d/mysqld |
20 | chkconfig --add mysqld |
22 | service mysqld restart |
24 | /usr/ local /mysql/bin/mysqladmin -uroot -p password 新密码 |
好,现在我们MySQL的安装就完成了。那么让我们开始Apache的安装
首先我们先安装下apr和apr-util
02 | tar -zxvf apr-1.4.6. tar .gz |
07 | tar -zxvf apr-util-1.5.2. tar .gz |
09 | ./configure --with-apr=/usr/ local /apr/ |
OK然后我们下一步就可以开始安装apache了。
1 | tar -zxvf httpd-2.2.24. tar .gz |
3 | ./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 |
apachee安装完成后我们先不忙着配置。等PHP安装完成后一起配置。那么我们下一步开始安装PHP。
首先安装zlib
1 | tar -zxvf zlib-1.2.7. tar .gz |
然后安装Libmcrypt
1 | tar -zxvf libmcrypt-2.5.8. tar .gz |
7 | ./configure -- enable -ltdl- install |
然后再来安装libpng
1 | tar -zxvf libpng-1.6.1. tar .gz |
然后来安装jpeg6
01 | tar -zxvf jpegsrc.v6b. tar .gz |
03 | mkdir /usr/ local /jpeg6 |
04 | mkdir /usr/ local /jpeg6/bin |
05 | mkdir /usr/ local /jpeg6/lib |
06 | mkdir /usr/ local /jpeg6/include |
07 | mkdir -p /usr/ local /jpeg6/ man /man1 |
08 | ./configure --prefix=/usr/ local /jpeg6/ -- enable -shared -- enable -static |
再来安装freetype
1 | tar -zxvf freetype-2.4.0. tar .gz |
3 | ./configure --prefix=/usr/ local /freetype/ make |
然后安装gd库
1 | tar -zxvf gd-2.0.35. tar .gz |
3 | ./configure --prefix=/usr/ local /gd2/ --with-jpeg=/usr/ local /jpeg6/ --with-freetype=/usr/ local /freetype/ |
再来安装libxml
1 | tar -zxvf libxml2-2.7.3. tar .gz |
最后来安装CURL
1 | tar -zxvf curl-7.29.0. tar .gz |
3 | ./configure --prefix=/usr/ local /curl/ |
安装完成后我们就可以开始安装PHP了
1 | tar -zxvf php-5.2.17. tar .gz |
3 | ./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 |
然后我们创建PHP的配置文件
1 | cp php.ini-dist /usr/ local /php/lib/php.ini |
最后我们来配置Apache的配置文件
01 | vi /usr/ local /apache2/conf/httpd.conf |
03 | AddType application/x-httpd-php .php |
04 | AddType application/x-httpd-php- source .phps |
07 | LoadModule php5_module modules/libphp5.so |
然后ba把Apache加入系统服务
01 | cp /usr/ local /apache2/bin/apachectl /etc/rc.d/init.d/httpd |
02 | vi /etc/rc.d/init.d/httpd |
13 | chcon -c - v -R -u system_u -r object_r -t textrel_shlib_t /usr/ local /apache2/modules/libphp5.so |