Apache+mysql+php简易环境搭建
版本
CentOS 6.4 //最小安装;要解决很多依赖包建议yum进行安装
httpd-2.4.6.tar.gz
php-5.5.4.tar.gz
Mysql-5.5.14
步骤:
1)安装所需要的一些依赖库
//可以直接进入第二步,安装时出现所需依赖包未安装返回第一步
2)安装apache
3)安装mysql
4)安装php
5)修改配置文件
6)测试
一:安装依赖库
安装时可能出现一些依赖库未安装 比如:APR APR-util PCRE C++ 或其他软件包
这里列出一些,如有提示看关键字yum安装即可或使用百度,谷歌。
安装方法如下:
①yum 安装//yum install -y包名
yum install -y gcc gcc-c++ncurses-develbisonlibxml2libxml2-dev*
②tar 安装 如下
tar zxvfapr-1.4.8.tar.gz
cd apr-1.4.8
./configure--prefix=/usr/local/apr//注意路径 安装httpd时免得找不到
make
make install
tar zxvf apr-util-1.5.2.tar.gz
cd apr-util-1.5.2
./configure--prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make
make install
tar zxvf pcre-8.33.tar.gz
cd pcre-8.33
./configure --prefix=/usr/local/pcre
make
make install
二:安装apache
tar zxvf httpd-2.4.6.tar.gz
cd httpd-2.4.6
./configure--prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util--enable-module=so --with-pcre=/usr/local/pcre
make
make install
三:安装mysql
安装cmake(mysql-5.5后需要cmake来编译)
tar zxvf cmake-2.8.5.tar.gz
cd cmake-2.8.5
./configure --prefix=/usr/local/cmake
make && make install
配置环境变量
vi /root/./bash_profile
##修改为(一个是cmakey;一个是mysql)
PATH=$PATH:$HOME/bin:/usr/local/cmake/bin:/usr/local/mysql/bin:/usr/local/mysql/lib
export PATH
保存退出
执行:source /root/.bash_profile
安装mysql
groupadd mysql
useradd -g mysql mysql -s /usr/sbin/nologin
mkdir /usr/local/mysql
mkdir /usr/local/mysql/data
tar zxvf mysql-5.5.14.tar.gz
cd mysql-5.5.14
cmake-DCMAKE_INSTALL_PREFIX=/usr/local/mysql-DINSTALL_DATADIR=/usr/local/mysql/data
make && make install
cd /usr/local/mysql
scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql//初始化mysql数据库
cp support-files/my-medium.cnf /usr/local/mysql/my.cnf//建立mysql配置文件
chown -R mysql:mysql /usr/local/mysql
四:安装PHP
tar zxvfphp-5.5.4.tar.gz
cdphp-5.5.4
./configure--with-apxs2=/usr/local/apache/bin/apxs--prefix=/usr/local/php5
--with-config-file-path=/usr/local/php5--with-mysql=/usr/local/mysql
make
make install
五:修改配置文件
Apache
配置文件在/usr/local/apache/conf/httpd.conf
网页文件在/usr/local/apache/htdocs/
php
配置文件在 /etc/php.ini
Mysql
配置文件在 /usr/local/mysql/my.cnf
数据文件在 /usr/local/mysql/date/
建立php配置文件
cp/php-5.5.4/php.ini-development/php.ini-development/etc/php/ini
vi/usr/local/apache/conf/httpd.conf
添加 //自动添加了libphp5.so模块
AddType application/x-httpd-php .php .phtml .php3 .inc
在/usr/local/apache/htdocs/下建php文件
cd/usr/local/apache/htdocs/
vi index.php
phpinfo();
?>
Mysql
vi /usr/local/mysql/my.cnf //加上以下内容
[mysqld]
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
log-error = /usr/local/mysql/mysql_error.log
pid-file = /usr/local/mysql/mysql.pid
user = mysql
tmpdir = /tmp
六:测试
关闭防火墙
service iptables stop
关闭selinux
setenforce 0
Apache服务启动
service httpd start
Mysql服务启动
cd /usr/local/mysql/support-files/
cp ./mysql.server /etc/init.d/mysqld
/etc/init.d/mysqld start
查看:
测试及访问:
修改httpd.conf
vi/usr/local/apache/conf/httpd.conf
重启服务:
service httpd restart
再次访问:
最小安装可能出现以下情况:
vservice httpd restart 出现httpd:unrecognized service错误
解决:
cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd
chmod 700 /etc/rc.d/init.d/httpd
vmake //no found make//编译时出现
解决:
yum install make