系统redhat enterprise6.0,我这里用apache即web服务器用nginx代替,即广义的lamp。
LAMP架构
一.mysql安装
yum install gcc gcc-c++ make openssl-devel zlib-devel bison ncurses-devel #先安装这些编译所需的工具和编译安装过程中会依赖的包。
安装cmake。
“CMake”这个名字是“cross platform make”的缩写。虽然名字中含有“make”,但是cmake和unix上常见的“make”系统是分开的,而且更为高阶。
编译:
以上参数的含义分别为:制定安装目录为/usr/local/lnmp/mysql/,数据库存放目录,unix socket文件,安装myisam存储引擎,使用utf8字符,检验字符,安装所有扩展字符集
编译完成:
make && make install
cd /var/local/lnmp/mysql
cp support-files/my-large.cnf /etc/my.cnf #根据自己的主机情况拷贝mysql配置文件,support-files中的配置文件:my-small.cnf,my-medium.cnf,my-large.cnf,(Example MySQL config file for large systems.)my-innodb-heavy-4G.cnf,my-huge.cnf等几个等级。
scripts/mysql_install_db —user=mysql —basedir=/usr/local/lnmp/mysql —datadir=/usr/local/lnmp/mysql/data/ #初始化数据库,mysql_install.db是个脚本,This scripts creates the MySQL Server system tables。建立数据库系统的表格。
mysql初始化完成:
cp support-files/mysql.server /etc/init.d/mysqld ##复制mysql程序的开启停止脚本并以常见的管理方式命名为mysqld。mysql-server(MySQL daemon start/stop script)
vim ~/.bash_profile PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin
#编辑root用户的个人配置文件,在变量PATH后加上mysql的可执行文件的目录路径
mysql_secure_installtion #按提示完成mysql安全设置。
ln -s /usr/local/lnmp/mysql/lib/ /usr/local/lnmp/mysql/lib64 #添加软链,不然php编译的时候找不到mysql的库文件
chkconfig mysqld on
/etc/init.d/mysqld start #测试mysql能否成功启动
二.安装nginx
yum install -y pcre-devel
Useradd -M -s /sbin/nologin nginx
tar -zxf nginx-1.0.2.tar.gz
cd nginx-1.0.2
vim auto/cc/gcc
/debug
#CFLAGS="$CFLAGS -g" 注释掉这行,去掉debug模式编译,编译后程序只有几百k
./configure --prefix=/usr/local/lnmp/nginx/ --user=nginx --group=nginx --with-http_stub_status_module —with-http_ssl_module
make && make install
Ln -s /usr/local/lnmp/nginx/sbin/nginx /usr/sbin
Vim /usr/local/lnmp/nginx/etc/nginx.conf #编辑nginx的主配置文件,仅列出修改的部分
User nginx nginx;
Worker_processes 2;
events{
Use epoll;
Worker_connections 1024;
}
Server_name localhost;
Location / {
Root html;
Index index.php index.html index.htm;
}
Location ~\.php${
Root html;
Fastcgi_pass 127.0.0.1;
Fastcgi_index index.php;
Include fastcgi.conf;
}
测试配置文件是否有语法错误:
nginx -t
vim ~/.bash_profile
Nginx #启动nginx
Ps aux #查看nginx启动了两个进程
vim /etc/hosts #在宿主机中编辑此文件,将nginx配置文件中定义的服务器名和对应ip写入
浏览器浏览:
三.安装php
Tar zxf libiconv-1.13.1.tar.gz
Cd libiconv-1.13.1/
./configure —libdir=/usr/local/lib64/
Make && make install
Tar jxf libmcrypt-2.5.8.tar.bz2
Cd libmcrypt-2.5.8
./configure —libdir=/usr/local/lib64/
Make && make install
Cd libltdl
./configure —libdir=/usr/local/lib64/ —enable-ltdl-install
Make && make install
Ldconfig /usr/local/lib64/
Tar zxf mcrypt-2.6.8.tar.gz
Cd mcrypt-2.6.8/
./configure —libdir=/usr/local/lib64/
Make && make install
Yum install net-snmp-devel curl-devel libxml2-devel libpng-devel libjpeg-devel freetype-devel gmp-devel openldap-devel -y
Tar jxf php-5.3.6.tar.bz2
Cd php-5.3.6
./configure --prefix=/usr/local/lnmp/php/ --with-config-file-path=/usr/local/lnmp/php/etc --with-mysql=/usr/local/lnmp/mysql --with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --without-pear --with-gettext --with-gmp --enable-inline-optimization --enable-soap --enable-ftp --enable-sockets --enable-mbstring --with-mysqli=/usr/local/lnmp/mysql/bin/mysql_config --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-libdir=lib64 --with-ldap-sasl —with-mcrypt —with-mhash
#每个参数的含义可以在解压后的目录中用./config --help查看
Make ZEND_EXTRA_LIBS='-liconv'
Mak install
Wget http://pear.php.net/go-pear.php
Cp php.ini-production /usr/local/lnmp/php/etc/php.ini
Vim /usr/local/lnmp/php/etc/php.ini
cgi.fix_pathinfo=0 #防止nginx文件类型错误解析漏洞
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm #拷贝启动脚本
Cd /usr/local/lnmp/php/etc/
Cp php-fpm.conf.default php-fpm.conf
Vim php-fpm.conf
Pid = run/php-fpm.pid
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requents = 500
Service php-fpm start
修改PATH变量
Vim ~/.bash_profile
ource ~/.bash_profile
Cd /usr/local/lnmp/nginx/html/ #到nginx的发布目录
Vim index.php
<? Php
phpinfo();
?>
#一定不要打错,否则会出现空白页
在浏览器中检测: