ubuntu 12.04下的apache+mysql+php配置

来源:互联网 发布:如何零基础学算法 编辑:程序博客网 时间:2024/05/16 23:32

        之前每次安装这些东西,都需要我去翻一遍收藏夹再加上各种google,于是打算在这次安装过程中,自己动手记录下来,以便整理和理解。毕竟四处找到的教程良莠不齐,很多还没法正确的运行。

          相关软件环境的安装:

cmake ,autoconf,libxml2,libncurses5-dev


mysql源码安装


1.创建mysql用户组和mysql用户

>>groupadd mysql

>>useradd -r -g mysql mysql


2.下载的mysql-5.5.27的源码,解压缩到目录,然后进入mysql源码所在文件夹之中:

# tar zxvf mysql-5.5.27.tar.gz

# cd mysql-5.5.27

# cmake . \

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ 
*****都是可选项,我安装的时候都没有选,只用了第一个选项******
-DSYSCONFDIR=/etc \
-DMYSQL_DATADIR=/data/mysql \
-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock \
-DWITH_DEBUG=0 \
-DMYSQL_TCP_PORT=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 

# make

# make install

3.配置并初始化数据库

创建my.cnf配置文件

# cp support-files/my-medium.cnf /etc/my.cnf

# cd /usr/local/mysql

# scripts/mysql_install_db --user=mysql

4.改变目录权限

cd /usr/local/mysql/data

sudo chown -R mysql .

sudo chgrp -R mysql .

  >>cp surpport-files/mysql.server /rtc/init.d/mysql 
  >>chmod 755 /etc/init.d/mysql

  

5启动mysql服务 
  >>  /etc/init.d/mysql start 
  
6.创建root用户以及密码 
  >>bin/mysqladmin -u root password '*******' // 密码可以为空,""

7.创建成功后,开始使用一下把 
  >>bin/mysql -uroot -p 

输入密码



Mysql 安装遇到问题:

1.开机如何自动启动:

chkconfig: 

   12.04中chkconfig有bug,修改后提示/sbin/insserv不存在。解决方法是在/sbin下建立软链接。先找到insserv所在位置:whereis insserv,然后连接过去就行了。之后用chkconfig启动mysql服务。

   或者可以:

sudo update-rc.d mysql.server defaults ;mysql.server需要存在于/etc/init.d/下面
2、安装Apache


>tar -zxvf httpd-2.2.4.tar.gz
>cd httpd-2.2.4
>./configure --prefix=/usr/local/apache --with-mysql=/usr/local/mysql --enable-module=so --enable-shared=max
>make
>make install



3、安装PHP

>tar -zxvf php-5.2.2.tar.gz
>cd php-5.2.2
>./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-apxs2=/usr/local/apache/bin/apxs
>make
>make install
>cp php.ini-dist /usr/local/php/lib/php.ini
>vi /usr/local/php/lib/php.ini

修改 register_globals=On


4、配置httpd.conf


>vi /usr/local/apache/conf/httpd.conf

找到"AddType application/x-gzip .tgz"(第294行),在它的下面添加
"AddType application/x-httpd-php .php"和"AddType application/x-httpd-php-source .phps"

找到"DirectoryIndex index.html
" 在index.html 前添加 index.php 


>vi /usr/local/apache/htdocs/index.php

内容为:
<?php
phpinfo();
?>
>/usr/local/apache/bin/apachectl -k start


至此,LAMP全部配置完毕,输入 http://localhost/index.php 即可看到安装成功的页面了 :)


APACHE遇到的问题:APR NOT FOUND

bigCat Posted in Linux - for Comments = 3

原文 http://52lamp.net/documents/apache/128956574863.html

#./configure --prefix……检查编辑环境时出现:

checking for APR... no
configure: error: APR not found .  Please read the documentation.

可以用./configure –help | grep apr 查看帮助。
--with-included-apr     Use bundled copies of APR/APR-Util
--with-apr=PATH         prefix for installed APR or the full path to apr-config
--with-apr-util=PATH    prefix for installed APU or the full path to
安装APR(Apache Portable Runtime )
下载:http://apr.apache.org/download.cgi

#cd /tmp/52lamp/ //源码存放位置
#tar -zxvf apr-1.4.2.tar.gz //unzip -o apr-1.4.2.zip
#cd apr-1.4.2
#./configure
#make
#make install

再次检查编译环境出现

checking for APR-util... no
configure: error: APR-util not found .  Please read the documentation.

#./configure –help | grep apr-util
--with-apr-util=PATH    prefix for installed APU or the full path to

下载:http://download.chinaunix.net/download/0001000/472.shtml
#tar -zxvf apr-util-1.3.9.tar.gz
#cd apr-util-1.3.9
#./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
#make
#make install

./configure仍提示APR-util not found,增加--with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util后出现
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

#./configure –help | grep pcre
--with-pcre=PATH        Use external PCRE library

下载:http://sourceforge.net/projects/pcre
#unzip -o pcre-8.10.zip
#cd pcre-8.10
#./configure --prefix=/usr/local/pcre
#make
#make install

继续安装Apache/httpd,./configure 时加上参数 --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre,这个问题就解决了

注意:Apache在安装时不会检查参数是否正确,错误的参数会直接被丢弃,不会报告给用户。但可以使用echo $?命令检查是否有错误,当输出结果为0时表示没有错误。

#echo $?
0

#make
#make install

复制Apache启动文件
#cp /usr/local/httpd/bin/apachectl /sbin/

启动Apache
#apachectl start

设置Apache开机自启动
#vi /etc/rc.d/rc.local
增加一行 /sbin/apachectl start

或者将httpd服务添加到ntsysv服务管理工具
#apachectl stop //关闭Apache以免不必要的麻烦
#cp /usr/local/httpd/bin/apachectl /etc/rc.d/init.d/httpd
#vi /etc/rc.d/init.d/httpd
修改为
#!/bin/sh
#
#chkconfig: 345 85 15 //#不能省略,注意空格
#description: httpd for 52lamp 20101016 21:54 //任意字符串
#
......

第二行中345的含义:
#       0 - operation completed successfully
#       1 -
#       2 - usage error
#       3 - httpd could not be started
#       4 - httpd could not be stopped
#       5 - httpd could not be started during a restart

修改有关权限
#cd /etc/rc.d/init.d/
#chmod a+x httpd
#chkconfig --add httpd

#ntsysv
httpd已经在列表中,按F1可以看到刚才编写的服务描述httpd for 52lamp 20101016 21:54。

#apachectl start
#ps -e |grep httpd
23247 ?        00:00:00 httpd
23248 ?        00:00:00 httpd
23249 ?        00:00:00 httpd
23251 ?        00:00:00 httpd
23252 ?        00:00:00 httpd

在浏览器中输入127.0.0.1,看起来一切正常;但是局域网内其他电脑不能访问!

#service iptables stop

如果不想关闭防火墙,放开80端口即可。

#vi /etc/sysconfig/iptables
增加一行-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
#service iptables restart //重启防火墙

现在一切OK




原创粉丝点击