系统:CentOS release 6.4 (Final)php
1、安装apachehtml
一、下载安装mysql
yum install zlib-devel -y wget http://mirror.bit.edu.cn/apache/httpd/httpd-2.2.31.tar.gz tar xf httpd-2.2.31.tar.gz cd httpd-2.2.31 ./configure \ --prefix=/application/apache2.2.31 \ --enable-deflate \ --enable-expires \ --enable-headers \ --enable-modules=most \ --enable-so \ --with-mpm=worker \ --enable-rewrite make make install ln -s /application/apache2.2.31/ /application/apache ls -l /application/
二、启动服务、检查linux
/application/apache/bin/apachectl start netstat -lntup|grep httpd
三、配置基于域名的虚拟主机c++
cd /application/apache/conf/ vim httpd.conf 修改98行 ServerName 127.0.0.1:80 修改132 <Directory "/application/apache2.2.31/html"> 修改378 Include conf/extra/httpd-mpm.conf 修改396 Include conf/extra/httpd-vhosts.conf 在文件末尾加入如下配置 <Directory "/application/apache2.2.31/html"> Options none AllowOverride None Order allow,deny Allow from all </Directory>
修改虚拟主机配置文件web
[root@web02 conf]# cd extra/ [root@web02 extra]# vim httpd-vhosts.conf <VirtualHost *:80> ServerAdmin admin@sellsa.com DocumentRoot "/application/apache2.2.31/html/www" ServerName www.etiantian.org ServerAlias sellsa.com ErrorLog "/app/logs/www-error_log" CustomLog "/app/logs/www-access_log" common </VirtualHost> <VirtualHost *:80> ServerAdmin admin@sellsa.com DocumentRoot "/application/apache2.2.31/html/bbs" ServerName bbs.sellsa.com ErrorLog "/app/logs/bbs-error_log" CustomLog "/app/logs/bbs-access_log" common </VirtualHost> <VirtualHost *:80> ServerAdmin admin@sellsa.com DocumentRoot "/application/apache2.2.31/html/blog" ServerName blog.sellsa.com ErrorLog "/app/logs/blog-error_log" CustomLog "/app/logs/blog-access_log" common </VirtualHost>
建立站点目录及测试文件目sql
mkdir -p /application/apache2.2.31/html/{www,bbs,blog} echo www.sellsa.com >/application/apache2.2.31/html/www/index.html echo bbs.sellsa.com >/application/apache2.2.31/html/bbs/index.html echo blog.sellsa.com >/application/apache2.2.31/html/blog/index.html mkdir /app/logs -p /application/apache/bin/apachectl -t /application/apache/bin/apachectl graceful
**********************************************************************数据库
2、安装mysqlapache
一、下载安装vim
wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.47-linux2.6-x86_64.tar.gz yum install -y libaio-devel tar zxf mysql-5.5.47-linux2.6-x86_64.tar.gz -C /usr/local/ cd /usr/local/ ln -s mysql-5.5.47-linux2.6-x86_64 mysql ls -ld mysql
二、建立mysql组和用户
groupadd -r -g 306 mysql useradd -g 306 -u 306 mysql id mysql chown mysql.mysql /usr/local/mysql/*
三、建立mysql数据存放目录(默认是存放在mysql安装目录的data目录里面,如使用默认的则不用建立)
mkdir -p /mysql/data chown -R mysql.mysql /mysql/data/
四、初始化
cd /usr/local/mysql scripts/mysql_install_db --datadir=/mysql/data/ --user=mysql
chown -R root /usr/local/mysql/*
五、为mysql提供主配置文件(根据实际状况选择相应的配置文件)
cd /usr/local/mysql/support-files/ cp my-medium.cnf /etc/my.cnf
六、修改my.cnf指定mysql数据文件的存放位置
# vim /etc/my.cnf [mysqld] datadir = /mysql/data
七、将mysql添加为系统服务,可以使用service启动,并可以使用chkconfig加载服务列表
cp mysql.server /etc/init.d/mysqld chmod +x /etc/init.d/mysqld chkconfig --add mysqld chkconfig mysqld on
八、修改PATH环境变量,让系统能够直接使用mysql的相关命令
#vim /etc/profile.d/mysql.sh export PATH=$PATH:/usr/local/mysql/bin #source /etc/profile
九、启动MySQL
service mysqld start netstat -lnt |grep 3306
十、默认没有密码,咱们设置一个管理员密码,并登陆
mysqladmin -uroot password '463951510' mysql -uroot -p'463951510'
**********************************************************************
3、安装php
一、安装编译所须要的依赖包
yum -y install libxslt-devel libjpeg libjpeg-devel libpng libpng-devel \ freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc \ glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel \ curl curl-devel e2fsprogs e2fsprogs-devel krb5-devel libidn libidn-devel \ openssl openssl-devel pcre pcre-devel libtermcap libtermcap-devel gcc gcc-c++
二、让编译的php支持mcrypt、mhash扩展
wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.6.tar.gz wget wget http://nchc.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz tar zxf libmcrypt-2.5.6.tar.gz cd libmcrypt-2.5.6 ./configure make && make install cd tar zxf mhash-0.9.9.9.tar.gz cd mhash-0.9.9.9 ./configure make && make install
三、下载安装php
wget http://mirrors.sohu.com/php/php-5.4.25.tar.gz tar zxf php-5.4.25.tar.gz cd php-5.4.25 ./configure \ --prefix=/usr/local/php5.4.25 \ --with-apxs2=/application/apache/bin/apxs \ --with-mysql=/usr/local/mysql \ --enable-mbstring \ --with-freetype-dir \ --with-jpeg-dir \ --with-png-dir \ --with-zlib \ --with-libxml-dir=/usr \ --enable-xml \ --enable-sockets \ --with-bz2 \ --with-config-file-scan-dir=/etc/php.d \ --with-config-file-path=/etc \ --with-mcrypt
四、为php提供配置文件
cp php.ini-production /etc/php.ini
五、编辑apache的配置文件httpd.conf
#vim /application/apache/conf/httpd.conf irectoryIndex index.php index.html \\找到此行加入index.php LoadModule php5_module modules/libphp5.so \\启用此行 AddType application/x-httpd-php .php \\添加下面两行 AddType application/x-httpd-php-source .phps #/application/apache/bin/apachectl -t #/application/apache/bin/apachectl graceful
六、查看是否有php模块
find /application/apache/modules/ -name '*php*'
七、测试php是否正常工做
# vim /application/apache2.2.31/html/www/test1.php <?php phpinfo(); ?>
八、测试是否能够链接数据库
#vim /application/apache2.2.31/html/www/test2.php <?php $link=mysql_connect('localhost','root','463951510'); if(!$link) echo "failed!"; else echo "ok!"; mysql_close(); ?>