一、安装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