基础篇:源码 Linux+Apache+PHP+MySQL环境配置方法-08CMS网站

来源:互联网 发布:ubuntu 主分区大少 编辑:程序博客网 时间:2024/05/16 04:55

前言

朋友公司用到了一个08cms系统,最近换系统,那边新来的程序员不会搭建环境,在此我转摘了网络上一些相关资料,望能对其所有帮助,08CMS 是一套以 PHP 为编程语言,以 MySQL 为数据库,并使用 Apache/IIS/Nginx(任意一种即可) 提供 web 服务的产品。要搭建 08CMS 站点,服务器必须安装由 PHP、MySQL、Apache/IIS/Nginx 构成的环境。其中,IIS 主要用于 Windows 服务器,Apache、Nginx 多用于 Linux 服务器(即 LAMP 和 LNMP)。

本篇是源码方式安装lamp

Linux 服务器部署时,需要按照一定的部署顺序,即:

系统环境初始化 -> Apache/Nginx、MySQL、PHP 程序包下载 -> Apache/Nginx、MySQL、PHP 安装。

下面以在 RedHat/CentOS 服务器上部署 Apache、MySQL、PHP 为例,演示搭建环境的具体过程。

系统约定

软件源代码包存放位置/usr/local/src

Apache、MySQL、PHP 源码包编译安装位置(prefix)/usr/local/server

脚本以及维护程序存放位置/usr/local/server/software_name/sbin

MySQL 数据库位置/data/mysql(可按情况设置)

Apache 网站根目录/data/wwwroot(可按情况设置)

Apache 虚拟主机日志根目录/data/wwwroot/logs(可按情况设置)

Apache 运行账户www:www

系统环境检查以及准备所需软件

检查系统是否正常

more /var/log/messages(检查有无系统级错误信息)

dmesg (检查硬件设备是否有错误信息)

cat /proc/cpuinfo (检查 CPU 频率是否正常)

top (按 1 检测 CPU 核数是否正常,内存大小是否正常)

ifconfig(检查网卡设置是否正确)

ping www.qq.com(检查网络是否正常)

关闭不需要的服务

执行 ntsysv 命令:

ntsysv

在服务设置界面,设置各项服务的开关。以下仅列出需要启动的服务,未列出的服务一律推荐关闭:

atd

crond

irqbalance

microcode_ctl

network

sendmail

sshd

syslog

操作方法如下:

用空格键(最长的那个)选中或取消服务。选中时,服务的前面的方括号里是“*”,反之则表示取消。设置完毕后,按“Tab”到“ok”回车结束配置。

关闭 SElinux ,关闭方法如下:

修改 /etc/selinux/config 文件中的 SELINUX= 为 disabled。然后执行命令:setenforce 0

设置时区和自动校时

rm -rf /etc/localtime

ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

yum install -y ntp

ntpdate -u pool.ntp.org

date

#设置定时校正服务器时钟,编辑计划任务:

crontab –e

加入下面一行:

*/30 * * * * ntpdate 210.72.145.44 > /dev/null 2>&1

#编辑完成后,保存即可。

查看系统是否安装过 MySQL+Apahce+PHP 并卸载

rpm -qa|grep  httpd

rpm -e httpd

rpm -qa|grep mysql

rpm -e mysql

rpm -qa|grep php

rpm -e php

yum -y remove httpd*

yum -y remove php*

yum -y remove mysql-server mysql

yum -y remove php-mysql

更换快速下载源

yum -y install yum-fastestmirror

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.old

cd /etc/yum.repos.d/

wget http://mirrors.sohu.com/help/CentOS-Base-sohu.repo

mv CentOS-Base-sohu.repo CentOS-Base.repo

yum clean

yum -y update

lsb_release -a

yum -y erase mysql

yum -y erase php

yum -y erase httpd

使用 yum 程序安装所需开发包(以下为标准的 RPM 包名称)

yum -y install ntp make openssl openssl-devel pcre pcre-devel libpng libpng-devel libtiff-devel libjpeg-6b libjpeg-devel-6b freetype freetype-devel gd gd-devel \

fontconfig-devel zlib zlib-devel libevent-devel gcc gcc-c++ flex bison bzip2-devel libXpm libXpm-devel ncurses ncurses-devel libmcrypt libmcrypt-devel \

libxml2 libxml2-devel imake autoconf automake screen sysstat compat-libstdc++-33 curl curl-devel

下载程序包

Apache:

推荐稳定版 2.2.9,下载地址为 http://archive.apache.org/dist/httpd/httpd-2.2.9.tar.gz

PHP:

推荐稳定版 5.3.6,下载地址为 http://museum.php.net/php5/php-5.3.6.tar.gz

Mysql:

推荐稳定版 5.5.3,下载地址为 http://cdn.mysql.com/Downloads/MySQL-5.5/mysql-5.5.31-linux2.6-i686.tar.gz

Zend:

Zend Optimizer (32位),下载地址为http://downloads.zend.com/optimizer/3.3.9/ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz

Zend Optimizer (64位),下载地址为http://downloads.zend.com/optimizer/3.3.9/ZendOptimizer-3.3.9-linux-glibc23-x86_64.tar.gz

Zend Guard Loader (32位),下载地址为http://downloads.zend.com/guard/5.5.0/ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gz

Zend Guard Loader (64位),下载地址为http://downloads.zend.com/guard/5.5.0/ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz

警告

Zend Optimizer 是在 Linux + PHP5.2.X 及以下版本环境中安装的。

Zend Guard Loader 是在 Linux + PHP5.3.X 及以上版本环境中安装的。

Memcache:

libevent,下载地址为http://www.monkey.org/~provos/libevent-1.4.11-stable.tar.gz

memcached,下载地址为http://danga.com/memcached/dist/memcached-1.4.0.tar.gz

PHP的memcache扩展,下载地址为http://pecl.php.net/get/memcache-2.2.5.tgz

创建 web 运行用户

groupadd www

useradd -g www www

mkdir -p /data/wwwroot

chmod +w /data/wwwroot

chown www:www /data/wwwroot -R

重新启动

init 6

安装 MySQL

cd /usr/local/src

tar zxvf cmake-2.8.5.tar.gz

cd cmake-2.8.5/

./configure

gmake

gmake install

groupadd mysql

useradd -g mysql mysql

mkdir -p /data/mysql

chown -R mysql:mysql /data/mysql

cd /usr/local/src

tar zxvf mysql-5.5.3.tar.gz

cd mysql-5.5.3

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/server/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/usr/local/server/etc/ -DWITH_BLACKHOLE_STORAGE_ENGINE=1

make

make install

cd /usr/local/server/mysql

./scripts/mysql_install_db --user=mysql

cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld

chmod 755 /etc/rc.d/init.d/mysqld

chkconfig --add mysqld

chkconfig --level 3 mysqld on

编辑 /etc/rc.d/init.d/mysqld,找到

basedir=

datadir=

改成

basedir=/usr/local/server/mysql

datadir=/data/mysql

然后在 Comsenz 目录下创建 etc 目录,并将 MySQL 配置文件拷贝到该目录下:

mkdir -p /usr/local/server/etc

cp ./support-files/my-huge.cnf /usr/local/server/etc/my.cnf

编辑配置文件 /usr/local/server/etc/my.cnf,在 [mysqld] 段增加

datadir = /data/mysql

wait-timeout = 10

max_connections = 512

max_connect_errors = 10000000

local-infile=0

在 [mysqld] 段修改

max_allowed_packet = 16M

thread_cache_size = CPU个数*2

将 log-bin 注释

mv /usr/local/server/mysql/data/* /data/mysql

service mysqld start

bin/mysqladmin -u root password 'admin999'

其中 admin999 是要设置的 root 密码。

安装 Apache

cd /usr/local/src/

tar zxvf httpd-2.2.21.tar.gz

cd httpd-2.2.21

./configure --prefix=/usr/local/server/apache --enable-module=rewrite --disable-access --disable-auth --disable-charset-lite --disable-include --disable-log-config --disable-env --disable-setenvif --disable-mime --disable-status --disable-autoindex --disable-asis --disable-cgid --disable-cgi --disable-negotiation --disable-dir --disable-actions --disable-userdir --disable-alias --enable-so --enable-mods-shared='access auth auth_anon auth_dbm auth_digest dav dav_fs actions alias asis autoindex cache cern_meta cgi charset_lite deflate dir disk_cache env expires file_cache headers include info log_config logio mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias'

make

make install

cd /usr/local/src/

mv /usr/local/server/apache/conf/httpd.conf /usr/local/server/apache/conf/httpd.conf.old

cp -f /usr/local/src/httpd.conf /usr/local/server/apache/conf/httpd.conf

cp -f /usr/local/src/httpd /etc/init.d/httpd

chmod 755 /etc/init.d/httpd

chkconfig --add httpd

chkconfig httpd on

安装PHP

cd /usr/local/src

tar zxvf php-5.2.17.tar.gz

cd php-5.2.17

./configure --prefix=/usr/local/server/php5 --with-config-file-path=/usr/local/server/etc --enable-mbstring --enable-ftp --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --enable-magic-quotes --with-mysql=/usr/local/server/mysql --with-pear --enable-sockets --with-ttf --with-freetype-dir=/usr --enable-gd-native-ttf --with-zlib --enable-sysvsem --enable-exif --enable-sysvshm --with-libxml-dir=/usr --with-apxs2=/usr/local/server/apache/bin/apxs --with-iconv=/usr/local/libiconv --with-iconv-dir=/usr/local --with-xmlrpc --enable-xml --enable-shmop --enable-zip --with-mhash --with-mcrypt --enable-discard-path --enable-bcmath --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --with-openssl

make

make install

./libtool --finish /usr/local/src/php-5.2.17/libs

cp php.ini-dist /usr/local/server/etc/php.ini

echo 'ulimit -SHn 65535' >> /etc/rc.local

安装 Zend

安装 Zend Optimizer

进入 /usr/local/src 文件夹

tar zxvf ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz

mkdir -p /usr/local/zend/

cp ZendOptimizer-3.3.9-linux-glibc23-i386/data/5_2_x_comp/ZendOptimizer.so /usr/local/server/zend/

cat >>/usr/local/server/etc/php.ini<<EOF

[Zend Optimizer]

zend_optimizer.optimization_level=1

zend_extension="/usr/local/server/zend/ZendOptimizer.so"

EOF

Zend Optimizer 安装完成后需要重启 Apache 或 Nginx 服务,重启完成后需要再次打开 IE 浏览器窗口,查看 phpinfo.php 支持信息,观察是否包含了 Zend Optimizer 支持信息,如有则安装成功,果没有,则说明 Zend Optimizer 没有安装成功!

安装 Zend GuardLoader

进入 /usr/local/src 文件夹

tar zxvf ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz

mkdir -p /usr/local/zend/

cp ZendGuardLoader-php-5.3-linux-glibc23-i386/php-5.3.x/ZendGuardLoader.so /usr/local/server/zend/

cat >>/usr/local/server/etc/php.ini<<EOF

[Zend GuardLoader]

zend_extension="/usr/local/server/zend/ZendGuardLoader.so"

EOF

Zend GuardLoader 安装完成后需要重启 Apache 或 Nginx 服务,重启完成后需要再次打开 IE 浏览器窗口,查看 phpinfo.php 支持信息,观察是否包含了 Zend GuardLoader 支持信息,如有则安装成功,如果没有,则说明 Zend GuardLoader 没有安装成功!

安装 Memcache

Memcached是一套分布式的快取或缓存系统。强烈建议安装!安装过程比较简单,因而此处不再进行截图说明。

1、Memcache服务端安装 进入 /usr/local/src 文件夹

tar -zxvf libevent-1.4.11-stable.tar.gz

cd libevent-1.4.11-stable

make clean

./configure --prefix=/usr/local

make;make install

tar zxvf memcached-1.4.0.tar.gz

cd memcached-1.4.0

./configure --prefix=/usr/local/server/memcached --with-libevent=/usr/local

make;make install

安装完成,启动

/usr/local/server/memcached/bin/memcached -d -m 512 -u apache -p 11211 -c 25600

-d 以守护进程方式启动

-m 512 是指分配512M内存

-u apache 是用apache用户启动

-p 11211 使用11211端口

-c 25600 最大的迸发连接数

2、让PHP支持memcache 进入 /usr/local/src 文件夹

tar zxvf memcache-2.2.5.tgz

cd memcache-2.2.5

/usr/local/server/php/bin/phpize

./configure --enable-memcache --with-php-config=/usr/local/server/php/bin/php-config --with-zlib-dir

make;make install

cp /usr/local/server/php/lib/php/extensions/no-debug-zts-20060613/memcache.so /usr/local/server/memcached/

在php.ini的最后添加如下几行, vi /usr/local/server/etc/php.ini

[memcache]

extension=/usr/local/server/memcached/memcache.so

重启apache

service httpd restart

Memcache 安装完成后需要重启 Apache 或 Nginx 服务,重启完成后需要再次打开 IE 浏览器窗口,查看 phpinfo.php 支持信息,观察是否包含了 Memcache 支持信息,如有则安装成功,如果没有,则说明 Memcache 没有安装成功!

重要

安装好后,需要在网站目录 /data/wwwroot/08cms.com 下base.inc.php文件中设置:

$ex_memcache_server = 'localhost';网站才能开启缓存:

提升 PHP 安全性

保存以下内容为 info.php 到 /data/www/08cms.com,检查 phpinfo 中的各项信息是否正确。

<?

phpinfo();

?>

确认 PHP 能够正常工作后,编辑 /usr/local/server/etc/php.ini 进行设置提升 PHP 安全性。

查找disable_functions =

修改成

disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,escapeshellcmd,escapeshellarg,shell_exec,proc_get_status,ini_alter,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,leak,popepassthru,stream_socket_server,popen

然后重启 web 服务: service httpd restart

0 0
原创粉丝点击