centos 6.2 ubuntu 12.04 上安装apache(httpd2.4) nginx1.2 php5.3.10 mysql5.3

一、安装一些必要的软件。

ubuntu
安装以后,有一些包是没有安装上的。我们需要安装上,否则下面的编译将会出现问题。

复制内容到剪贴板代码:apt-get install binutils cpp fetchmail flex gcc libarchive-zip-perl libc6-dev libpcre3 libpopt-dev lynx m4 make ncftp nmap perl perl-modules unzip zip zlib1g-dev autoconf automake1.9 libtool bison autotools-dev g++ build-essential libpcre3-dev libncurses5-dev libcurl4-openssl-dev openssh-server openssh-client


二、设置安装目录,下载必要的软件。

安装完毕以后,我们建立几个目录,用来进行下一步的安装。

复制内容到剪贴板代码:mkdir /usr/src/lamp (用来存放安装软件)
/usr/local(
安装目录,nginxphp,mysql等都安装在这个目录下)
mkdir /var/www(
发布目录)
下载编译需要的各种软件,全部放到/var/software
mysql-5.5.23.tar.gz
php-5.3.10.tar.gz
nginx-1.2.0.tar.gz

spawn-fcgi-1.6.3.tar.gz(用来加载fastcgi)

//以下为php的依赖库

freetype-2.3.5.tar.gz

jpegsrc.v6b.tar.gz

libiconv-1.11.1.tar.gz

libmcrypt-2.5.8.tar.gz

libpng-1.2.29.tar.gz(注意,大家不要使用1.2.28这个版本,似乎有很多问题)
libxml2-2.6.30.tar.gz

mcrypt-2.6.7.tar.gz

mhash-0.9.9.tar.gz

pcre-8.30.tar.gz

为了方便,我已经已将上面所有的软件包下载后打包


、编译安装PHP所需的支持库。

复制内容到剪贴板代码:

cd /usr/src/lamp/beforephp
tar zxvf libiconv-1.11.1.tar.gz
cd libiconv-1.11.1/
./configure --prefix=/usr/local
make &&make install
cd ..

tar zxvf freetype-2.3.5.tar.gz
cd freetype-2.3.5
./configure
make && make install
cd..

tar zxvf libpng-1.2.29.tar.gz
cd libpng-1.2.29
./configure
###mv scripts/makefile.linux ./makefile
make
make install
cd ..


tar zxvf jpegsrc.v6b.tar.gz
cd jpeg-6b/
./configure --enable-static --enable-shared
make && make install
make install-lib
cd ..

(libxml2会影响php的编译)
tar zxvf libxml2-2.6.30.tar.gz
cd libxml2-2.6.30


打开当前目录下的nanohttp.c,第1588行由
fd = open(filename, O_CREAT | O_WRONLY);
更换为
fd = open(filename, O_CREAT | O_WRONLY,0777);

http://temix.blog.163.com/blog/static/364133200810237854799/

gcc-4.3对语法检查严格的结果,找到出错的那一句,OK
./configure
make&& make install
cd ..



tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8


./configure
make&& make install
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make && make install
cd ../..


tar zxvf mhash-0.9.9.tar.gz


cd mhash-0.9.9


./configure
make&& make install
cd ..

cp /usr/local/lib/libmcrypt.* /usr/lib
##ln-s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2 ()
创建链接时出错,说已经存在,不过好像不影响编译

tar zxvf mcrypt-2.6.7.tar.gz
cd mcrypt-2.6.7
./configure
make&& make install (
这里出现了很多警告,好像不影响)
cd..


四、编译安装MySQL

由于一些Linux操作系统并不自带MySQL数据库,或者有些电脑(如国产龙芯,基于MIPS指令系统)并不支持MySQL官方提供的RPM包的安装,因此需要使用源码进行重编译,然后安装使用

下载地址:http://www.mysql.com/downloads/mysql/进入MySQLCommunity Server下载页面,在SelectPlatform选项中选择SourceCode

选择最后一项.tar.gz的文件,如下图

点击Download进入镜像链接页面,随便选择一个镜像进行下载到本地磁盘


  1. 创建mysql安装目录

此处的安装目录可以任选,如果是默认安装则在/usr/local/mysql

#mkdir -p /usr/local/mysql/

2、创建数据存放目录

#mkdir -p /usr/local/mysql/data

3、创建用户和用户组与赋予数据存放目录权限

  #groupadd mysql

  #useradd -g mysql mysql

# chown mysql.mysql -R /usr/local/mysql/data

4、安装cmake

mysql5.5以后是通过cmake工具来编译的,CMake是个跨平台的自动化建构系统,它用组态档(生成Makefile文件的特殊脚本)控制建构过程,mysql的源码进行buildProcess(构建),然后生成Makefile文件.

Cmake下载地址:http://www.cmake.org/cmake/resources/software.html

  选择Unix/LinuxSource.tar.gz文件进行下载最新版本,然后将其解压缩到本地,并配置、安装,以下是相关命令

cd..

  tar zxvf cmake-2.8.8.tar.gz

  cd cmake-2.8.8


  ./configure

  make&& make install (这要一到两分钟的时间,反正比前面的编译时间长点)

cd..

5、编译mysql

tar zxvf mysql-5.5.23.tar.gz

cd mysql-5.5.23

进入MySQL解压目录下,使用cmake来对mysql的安装目录、数据存放、配置文件、系统语言等相关信息进行编辑,以下是相关指令:

以下是编辑命令的集合,可以直接拷贝、粘贴并执行,注意的是安装目录与数据目录的位置

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data/ -DMYSQL_UNIX_ADDR=/usr/local/mysql/data/mysqld.sock -DWITH_INNOBASE_STORAGE_ENGINE=1 -DSYSCONFDIR=/etc -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_unicode_ci -DWITH_DEBUG=0

执行以上命令,将构建MySQL源码中的Makefile文件。

选项说明:

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql

mysql安装的主目录,5.5.17版本默认为/usr/local/mysql(可省略)

-DMYSQL_DATADIR=/home/system_username/mysql/mysqldata

mysql数据保存的路径,自定义

-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock

系统Socket文件(.sock)设置,基于该文件路径进行Socket连接,必要为绝对路径

-DSYSCONFDIR=/etc

mysql配置文件my.cnf地址,默认/etc(可省略)

-DMYSQL_TCP_PORT=3306

数据库服务器TCP/IP连接的监听端口,默认为3306(可省略)

-DENABLED_LOCAL_INFILE=1

默认为关闭,这里开启

-DEXTRA_CHARSETS=all

-DDEFAULT_CHARSET=utf8

-DDEFAULT_COLLATION=utf8-general_ci

数据库编码设置

-DWITH_INNOBASE_STORAGE_ENGINE=1

-DWITH_ARCHIVE_STORAGE_ENGINE=1

-DWITH_BLACKHOLE_STORAGE_ENGINE=1

-DWITH_FEDERATED_STORAGE_ENGINE=1

-DWITH_PARTITION_STORAGE_ENGINE=1

存储引擎设置


8、安装MySQL

make&& make install

这将是一个比较漫长的编译过程。。。。。

9、配置MySQL的启动项

cp support-files/my-medium.cnf  /etc/my.cnf //更改配置文件位置

cp support-files/mysql.server  /etc/init.d/mysqld //设置mysql服务器操作路径

(以上两个文件是source下面的)

chmod 755  /etc/init.d/mysqld //更改权限

bash scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ //安装数据库,并设置用户名和数据存放位置

  1. MySQL启动与使用

1、在命令行中输入:

/etc/init.d/mysqld start

启动Mysql服务

2、登录MySQL

ln /usr/local/mysql/bin/mysql  /usr/sbin/mysql(以后直接输入mysql即可以启动登录)

命令行:mysql

使用mySQL数据库的root用户登录,默认无密码,也可以mysql -u root–p

  1. 简单操作

mysql>use mysql ; //使用mysql数据库

//更改root用户的登录密码

mysql>update user set password=PASSWORD("123456") where user='root';

//刷新更新

mysql>FLUSH PRIVILEGES;

  1. 总结

最好将上面的安装指令等写成一个Shell脚本,以避免错误,并使安装更简单。。完毕!


运行以下命令即可启动MySQL服务器:
/etc/init.d/mysqld start
(启动MySQL
bin/mysqladmin -u root password "password_for_root"
(设置mysqlroot密码)
/etc/init.d/mysqld stop
(关闭 MySQL

nano /etc/rc.local

ctrl+O
在最后加入:/etc/init.d/mysqld start(这样开机的时候,mysql就可以自动启动了。)

五、编译安装PHP-5.3.10FastCGI模式)


ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18

(没有这个链接会报错)
cd..
tar zxvf php-5.3.10.tar.gz
cd php-5.3.10


复制内容到剪贴板代码:(用于ubuntu
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql –with-mysqli=/usr/local/mysql --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --disable-ipv6 --enable-soap --with-openssl --with-gettext --disable-rpath
(
编译时间较长,请耐心等待)
                    

 phpfpmcentosphp-fpm cgi启动方式)

      我在 centos6.2下  php5.4.3 make时出现这个问题

          php-5.4.3/ext/xmlreader/php_xmlreader.c:1098: undefined reference to `xmlTextReaderSetup

           因而我  vi ext/xmlreader/php_xmlreader.c   找到1098行 注释掉ret = xmlTextReaderSetup这一行,make与make install时不会报错,编译后的php也可以运行,应该是libxml的版本太高了,并且安装libxml时少装了一个库,反正不怎么用xml,直接注释掉得了,就算用估计也不怎么影响
             #if LIBXML_VERSION >= 20628
                //ret = xmlTextReaderSetup(reader, NULL, uri, encoding, options);



./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path  --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets
make ZEND_EXTRA_LIBS='-liconv'
make install
cpphp.ini-dist /usr/local/php/etc/php.ini


centos  php--with--apache

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets


make
make install
cp php.ini-development /usr/local/php/etc/php.ini

 make ZEND_EXTRA_LIBS='-liconv'


六、编译安装PHP5扩展模块

复制内容到剪贴板代码:

cd ext/gd/
/usr/local/php/bin/phpize
./configure --with-jpeg-dir --with-png-dir --with-zlib-dir --with-ttf --with-freetype-dir --with-php-config=/usr/local/php/bin/php-config
make
make install

cd../../

安装 pdo mysql(也可以安装php时加上--with-pdo-mysql=/usr/local/mysql)

 # tar zxvf PDO_MYSQL-1.0.2.tgz
# cd PDO_MYSQL-1.0.2

/usr/local/php/bin/phpize

./configure --with-pdo-mysql=/usr/local/mysql --with-php-config=/usr/local/php/bin/php-config


、对php进行一些设置,并且为安装nginx做一些准备工作。
1
、修改php.ini文件
手工修改:查找/usr/local/php/etc/php.ini中的extension_dir= "./"
修改为extension_dir="/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/"
并在此行后增加以下几行,然后保存。

复制内容到剪贴板代码:
extension= "gd.so"

自动修改:若嫌手工修改麻烦,可执行以下shell命令,自动完成对php.ini文件的修改:



复制内容到剪贴板代码:
#sed -i 's#extension_dir = "./"#extension_dir ="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"\nextension= "gd.so"\n#' /usr/local/php/etc/php.ini  

2、创建www用户和组,以及其使用的目录。

复制内容到剪贴板代码:/usr/sbin/groupadd www -g 48
/usr/sbin/useradd -u 48 -g www www

/usr/sbin/useradd -u 49 -g www nginx

mkdir /var/www
chmod +w /var/www/
chown -R www:www /var/www/

儿、安装Nginx1.2.0
1
、安装Nginx所需的pcre库。

复制内容到剪贴板代码:

tar zxvf pcre-8.30.tar.gz
cd pcre-8.30/


./configure
make&& make install
cd ../..

2、安装Nginx

复制内容到剪贴板代码:
tar zxvf nginx-1.2.0.tar.gz
cd nginx-1.2.0/
./configure --user=nginx --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/home/xuefen/tar/lnmp/pcre-8.30


#--with-pcre=/ pcre要用源码的目录,我看它代码是找./cofigure
make
make install
cd ..


3
、创建Nginx日志目录。

复制内容到剪贴板代码:
chmod+w /usr/local/nginx/logs
chown -R nginx:www /usr/local/nginx/logs/

4、创建Nginx配置文件。
更改/usr/local/nginx/conf/目录中的nginx.conf文件。


nano /usr/local/nginx/conf/nginx.conf


以下是参考配置

usernginx www;

worker_processes 5;

error_log/usr/local/nginx/logs/nginx_error.log crit;

#pidlogs/nginx.pid;

#Specifies the value for maximum filedescriptors that can be opened by this process.
worker_rlimit_nofile51200;

events
{
use epoll;
worker_connections 51200;
}

http
{
includemime.types;
default_type application/octet-stream;

charsetutf-8;

server_names_hash_bucket_size 128;

#sendfileon;
#tcp_nopush on;

keepalive_timeout 60;

tcp_nodelayon;

gzip on;
gzip_min_length 1k;
gzip_buffers 48k;
gzip_http_version 1.1;
gzip_types text/plainapplication/x-javascript text/css text/htmlapplication/xml;

server
{
listen 80;
server_name servername.com;
index index.html index.htm index.php;
root /usr/local/webserver/webdata;

if (-d$request_filename)
{
rewrite ^/(.*)([^/])$ http://$host/$1$2/permanent;
}

location ~ .*.php?$
{
root /var/www;


fastcgi_pass 127.0.0.1:9999;


fastcgi_index index.php;


fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;


include fastcgi_params;
}

log_format access '$remote_addr -$remote_user [$time_local] "$request" '
'$status$body_bytes_sent "$http_referer" '
'"$http_user_agent"$http_x_forwarded_for';
access_log/usr/local/webserver/logs/access.log access;
}

server
{
listen80;
server_name status.servername.com;

location /{
stub_status on;
access_log off;
}
}
}

保存,退出nano

十一、安装zend

复制内容到剪贴板代码:
tarzxvf ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz
cdZendOptimizer-3.3.3-linux-glibc23-i386
./install

在询问php.ini的路径的时候,填入.

复制内容到剪贴板代码:/usr/local/webserver/php/etc

web服务器选择不是apache

十二、Apache(httpd)的安装

所需的库:(apache有下面三个库)

apr-1.4.6.tar.bz2

apr-util-1.4.1.tar.bz2

httpd-2.4.2.tar.bz2


命令 :

tarjxvf apr-1.4.6.tar.bz2

cdapr-1.4.6

./configure–prefix=/usr/local/apr

make&& make install

cd..

tarjxvf apr-util-1.4.1.tar.bz2

cdapr-util-1.4.1

./configure--prefix=/usr/local/apr-util –with-apr=/usr/local/apr

make&& make install

cd..

tarjxvf httpd-2.4.2.tar.bz2

cdhttpd-2.4.2

./configure--prefix=/usr/local/apache -enable-rewrite --enable-module=so-enable-so --with-apr=/usr/local/apr/--with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local

make&& make install

useraddapache -g www

chmod755 /etc/init.d/httpd

chkconfig--add httpd

chkconfig--lefel 35 httpd on


十三、后续的处理工作

1,nginx防盗链


一般的防盗链如下:


location~* .(gif|jpg|png|swf|flv)$ {


valid_referersnone blocked server_names *.bnxb.com www.bnxb.com;


if($invalid_referer) {


rewrite^/ http://www.bnxb.com/403.html;


#return404;


}


}



2,nginx虚拟目录


Nginx的目录如果是在网站根下建立的话,就可以直接当成目录访问,实现虚拟目录的效果,如果另外


指一个目录建立网站的虚拟目录的话,需要用到以下方法来实现。


nginx虚拟目录配置有两种方法aliasroot。虚拟目录的概念与其它的Web应用一样。


最基本的区别:alias指定的目录是准确的,root是指定目录的上级目录,并且该上级目录要含有


location指定名称的同名目录。另外,根据前文所述,使用alias标签的目录块中不能使用rewrite


break


示例1:


location/abc/ {


alias/home/html/abc/;


}


在这段配置下,http://test/abc/a.html就指定的是/home/html/abc/a.html


示例2:


这段配置亦可改成


location/abc/ {


root/home/html/;


}


/*abc的上级目录*/



示例3:


alias的配置改成:


location/abc/ {


alias/home/html/def/;


}


那么nginx将会从/home/html/def/取数据,这段配置还不能直接使用root配置,如果非要配置,


有在/home/html/下建立一个def->abc的软link(快捷方式)了。


说明:


1、使用alias时目录名后面一定要加/


2nginxresin当虚拟目录名与真实目录同名时,虚拟目录比真实目录优先级要高。




3.配置开机自动启动Nginx+ PHP

vi/etc/rc.local

加入以下内容:

ulimit-SHn 51200

/usr/local/php/sbin/php-fpmstart

/usr/local/nginx/sbin/nginx


4设置mysql开机自动启动服务
cp./support-files/mysql.server /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 345 mysqld on


5打开防火墙80端口

写入规则,保存并重启服务

iptables -I INPUT -p tcp--dport 80 -j ACCEPT

/etc/rc.d/init.d/iptables save

/etc/init.d/iptables restart

查看防火墙信息
/etc/init.d/iptables status

如果显示以下类似信息,即表示已经打开了80端口

1 ACCEPT tcp -- 0.0.0.0/00.0.0.0/0 tcp dpt:80

6编写nginx启动服务

cd /etc/init.d

vim nginx

输入以下代码并保存

#!/bin/sh

#

# nginx - nginx启动与停止,平滑更新nginx配置

# Source function library.

. /etc/rc.d/init.d/functions

# Source networkingconfiguration.

. /etc/sysconfig/network

# Check that networking isup.

[ "$NETWORKING" ="no" ] && exit 0

nginx="/usr/local/nginx/sbin/nginx"

prog=$(basename $nginx)

NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"

lockfile=/var/lock/subsys/nginx

start() {

[ -x $nginx ] || exit 5

[ -f $NGINX_CONF_FILE ]|| exit 6

echo -n $"Starting$prog: "

daemon $nginx -c$NGINX_CONF_FILE

retval=$?

echo

[ $retval -eq 0 ] &&touch $lockfile

return $retval

}

stop() {

echo -n $"Stopping$prog: "

killproc $prog -QUIT

retval=$?

echo

[ $retval -eq 0 ] &&rm -f $lockfile

return $retval

}

restart() {

configtest || return $?

stop

start

}

reload() {

configtest || return $?

echo -n $"Reloading$prog: "

killproc $nginx -HUP

RETVAL=$?

echo

}

force_reload() {

restart

}

configtest() {

$nginx -t -c$NGINX_CONF_FILE

}

rh_status() {

status $prog

}

rh_status_q() {

rh_status >/dev/null2>&1

}

case "$1" in

start)

rh_status_q &&exit 0

$1

;;

stop)

rh_status_q || exit0

$1

;;

restart|configtest)

$1

;;

reload)

rh_status_q || exit7

$1

;;

force-reload)

force_reload

;;

status)

rh_status

;;

condrestart|try-restart)

rh_status_q || exit0

;;

*)

echo $"Usage: $0{start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"

exit 2

esac



保存后,设置权限,并添加到启动服务列表中

chmod755 /etc/init.d/nginx

chkconfig--add nginx

chkconfig--level 345 nginx on

servicenginx start




7安装php-fpm

cp/opt/php/etc/php-fpm.conf.default /opt/php/etc/php-fpm.conf
vim/opt/php/etc/php-fpm.conf

修改以下地方
[global]
pid= run/php-fpm.pid-p
error_log =log/php-fpm.log
emergency_restart_threshold =10
emergency_restart_interval = 1m
process_control_timeout =5s
pm.start_servers = 20
pm.min_spare_servers =5
pm.max_spare_servers = 35

[www]
user = www
group =www

8修改nginx,支持php

vim/opt/nginx/conf/nginx.conf

找到并修改以下代码

location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9999;#
很多网上是配置9000,我上次因zenddebug也用9000,结果折腾了半天
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
include fastcgi_params;
}


9php-fpm作为服务运行

cd /usr/local/src/php-5.3.8
cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod 700 /etc/init.d/php-fpm
chkconfig--add php-fpm
chkconfig --level 345 php-fpm on
服务方式启动php-fpm
service php-fpm restart


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值