debian 下实现LAMP 搭建服务器

一、安装Apache
 
在安装HTTP Server之前需安装APR  ,APR-util ,  pcre (http://apr.apache.org/)
(1)apr安装
$ tar zxvf apr-1.4.6.tar.gz
$ cd apr-1.4.6/
$ ./configure
$ make
$ sudo make install

(2)安装APR-util(http://apr.apache.org/)
$ tar zxvf apr-util-1.4.1.tar.gz
$ cd apr-util-1.4.1
$ ./configure --with-apr=/usr/local/apr (whereis apr)
$ make
$ sudo make install

(3)安装pcre( http://www.pcre.org/)
切换到pcre-8.33文件夹下,依次执行命令:
    $./configure   --with-apr=/usr/local/apr
 (该命令的意思是配置安装文件,指定安装路径为绝对路径;且需要依赖apr,否则将会出错)
    $ make (编译)  
    $ sudo make install(安装)
出现问题: error: You need a C++ compiler for C++ support
解决方式:apt-get install -y gcc gcc-c++
     或者apt-get install build-essential

(4)安装httpd-2.4.2.tar.bz2(http://httpd.apache.org/)
默认安装位置/usr/local/apache2
网页放在/usr/local/apache2/htdocs
配置文件/usr/local/apache2/conf/httpd.conf
$ tar jxvf httpd-2.4.2.tar.bz2
$ cd httpd-2.4.2/
$ ./configure
$ make
$ sudo make install

(5)修改apache的配置文件
 #vim /usr/local/apache2/conf/httpd.conf

ServerAdmin you@example.com 改为你的 email
#ServerName www.example.com:80 改为你的域名,并且去掉“#”号,”:80”可以去掉
查看域名: sudo ifconfig
DocumentRoot “/usr/local/apache2/htdocs” 改为:DocumentRoot “/var/www”
<Directory “/usr/local/apache2/htdocs”> 改为:<Directory “/var/www”>

复制默认首页到网站根目录

# cp /usr/local/apache2/htdocs/index.html /var/www/

修改网站目录所属用户和所属组

# chown -R www-data:www-data /var/www

修改网站目录权限

# chmod -R 755 /var/www

做apache2文件在/etc/init.d/目录下的软连接

# ln -s /usr/local/apache2/bin/apachectl /etc/init.d/apache2

启动apache服务器

# /usr/local/apache2/bin/apachectl start

 出现问题:
1.error while loading shared libraries :libbpcre.so.1:cannot open shared object file;no such file or directory
2.(98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
(98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
第一个问题的解决办法:
   在/etc/ld.so.conf.d/目录下新建任何以.conf为后缀的文件,在该文件中加入库文件所在的目录。
   运行ldconfig,以更新/etc/ld.so.cache文件。
 第二个问题的解决方法:http://www.th7.cn/system/lin/201501/82593.shtml

(#/etc/init.d/apache2 start)


至此,我们的apache服务器搭建完毕,可通过:http://127.0.0.1进行浏览

(6)查看http是否正常运行$ netstat -a | grep httptcp 0 0 *:http *:* LISTEN

(7)在浏览器输入127.0.0.1如果正常应该显示“It works!”
END

[备注]
  在安装时httpd-2.4.2时,上面的前两步是没有做的(即安装apr,apr-util).应该是因为
安装httpd-2.4.2时,一起把上面两个安装了,而不需要单独安装。



二、安装MySQL

安装:apt-get install mysql-server-5.5 

出现问题:软件包 mysql-server-5.5 尚未配置
解决方式:这里主要是把原来的mysql全部删除掉,重新进行安装.
sudo rm /var/lib/mysql/ -R
sudo rm /etc/mysql/ -R

sudo apt-get autoremove mysql* --purge
sudo apt-get remove apparmor

sudo apt-get install mysql-server mysql-common 

启动MySQL Server:
/etc/init.d/mysql start|stop|restart|reload

登录mysql:/etc/init.d/mysql -u root -p
 error:不提示输入密码  更改密码就行了 

$/etc/init.d/mysql stop $mysqld_safe --user=mysql --skip-grant-tables --skip-networking & $mysql -u root mysql mysql>UPDATE user SET Password=PASSWORD('newpassword')where User='root'; mysql>FLUSH PRIVILEGES; mysql>quit $/etc/init.d/mysql restart

 $mysql -u root -p
 
三、安装PHP

(1)安装下载php-5.4.4.tar.gz(http://php.net/)
$ tar zxvf php-5.4.4.tar.gz
$ cd php-5.4.4
$ ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql --with-mysqli --enable-mbstring --with-mcrypt(可能需要安装libmcrypt-dev )
$ sudo make install
$ sudo cp php.ini-development /usr/local/lib/php.ini

出现问题:
error: xml2-config not found. Please check your libxml2 installation.
解决方式:
sudo apt-get install  libxml2
sudo apt-get install libxml2-dev
error: mcrypt.h not found. Please reinstall libmcrypt.
解决方式:apt-get install libmcrypt-dev

(2)配置HTTP Server使之支持PHPapache配置文件/usr/local/apache2/conf/httpd.conf修改或添加如下配置
<;IfModule dir_module>
    DirectoryIndex index.php
<;/IfModule>
 
<;FilesMatch \.php$>
    SetHandler application/x-httpd-php
<;/FilesMatch>

以下为出现的新的错误:

a、执行configure无错误,在make的时候报错:
     make[2]:***[do_abi_check] 错误一
     make: *** [all-recursive]错误一
 
解决方法:
    在configure完成之后,用编辑器打开Makefile,删除do_abi_check后面的东西直至done(done也删除)  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值