LAMP的搭建说简单也简单,说难也不容易,若是采用一键安装也是比较容易的,但想配置本身须要的版本等等也是比较麻烦。前段时间我分别在本身的电脑和阿里云上部署了Lamp环境,如下是步骤和常出现的问题的解决方法,都是编译安装,但愿对初学者有用。php
安装目录,我把他们指定在 /usr/local/ 下面 ,包括apache2,php,mysql文件html
须要的文件http://yunpan.cn/c3KzgIjkumcwy (提取码:a1b8)node
先安装apachemysql
安装步骤:linux
1 tar -zxvf httpd-2.4.12.tar.gz 2 cd httpd-2.4.12
3 ./configure --prefix=/usr/local/apache2 --enable-so --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre 4 make 5 make install
若是顺利,能够成功把apache安装在--prefix=指定的目录,可是可能出现编译错误,能够对照下面的方法解决sql
常出错误apache
1、在进行第三步的时候回出现缺乏环境的错误,能够按照一下步骤解决浏览器
若是出现:app
1 checking for APR... no
2 configure: error: APR not found . Please read the documentation
解决办法:dom
1:下载须要的安装包(上面的云盘中已经提供,能够下载):
1 wget http://archive.apache.org/dist/apr/apr-1.4.5.tar.gz
2 wget http://archive.apache.org/dist/apr/apr-util-1.3.12.tar.gz
3 wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.10/pcre-8.10.zip
2.编译安装(先移除旧的文件):
1 yum remove apr-util-devel apr apr-util-mysql apr-docs apr-devel apr-util apr-util-docs
具体步骤以下:
解决apr not found问题
1 # tar -zxf apr-1.4.5.tar.gz 2 # cd apr-1.4.5
3 # ./configure --prefix=/usr/local/apr 4 # make && make install
解决APR-util not found
1 # tar -zxf apr-util-1.3.12.tar.gz 2 # cd apr-util-1.3.12
3 # ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr 4 # make && make install
解决pcre
1 #unzip -o pcre-8.10.zip 2 #cd pcre-8.10
3 #./configure --prefix=/usr/local/pcre 4 #make && make install
4.最后编译Apache时加上:
1 --with-apr=/usr/local/apr \ 2 --with-apr-util=/usr/local/apr-util/ \ 3 --with-pcre=/usr/local/pcre
2、若是在编译的时候出现:configure: error: mod_so can not be built as a shared DSO
解决办法:删除编译选项:--enable-modules=so
3、启动apache报错:
linux启动apache命令报错(98)Address already in use: make_sock: could not bind to address [::]:80
解决办法:
1 查看到对应哪一个应用占用了80端口: 2 netstat -tulnp | grep ':80 ' 3 找到对应的PID杀掉。 4 kill 'PID'
4、出现:httpd: Could not reliably determine the server's fully qualified domain name
解决方案:进入apache的安装目录:
Windows : D:\Program Files\Apache Software Foundation\Apache2.2\conf
linux : /usr/local/apache/conf
用记事本打开httpd.conf
将里面的#ServerName localhost:80注释去掉便可。
再执行httpd
而后能够经过浏览器访问http://localhost:80,若是页面显示“It works!”,即表示apache已安装并启动成功。
经常使用修改:
Apache自动启动
一、将apachectl文件拷贝到/etc/rc.d/init.d 中,而后在/etc/rc.d/rc5.d/下加入连接便可。
1 cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd 2 ln -s /etc/rc.d/init.d/httpd /etc/rc.d/rc5.d/S85httpd
此时Apache就能够自动启动。
二、 运行chkconfig --list,发现没有linux服务列表中httpd,经过chkconfig --add httpd来添加,可是提示:httpd服务不支持 chkconfig。
须要编辑/etc/rc.d/init.d/httpd,在第一行添加如下注释信息:
1 chkconfig: 345 85 15 2 description: Activates/Deactivates Apache Web Server
第一行3个数字参数意义分别为:哪些Linux级别须要启动httpd(3,4,5);启动序号(85);关闭序号(15)。
保存后执行:chkconfig --add httpd,成功添加。
在rc3.d、rc4.d、rc5.d路径中会出现S85httpd的连接文件,其余运行级别路径中会出现K61httpd的连接文件。
三、运行chkconfig --list httpd 就会出现
能够经过:service httpd start 启动
编译期间可能出现其余的缺乏环境问题,能够一步一步查查,都有对应的解决办法。
安装mysql(建议先安装mysql在安装php,php要指定mysql的安装路径)
1:检查是否已安装
1 rpm -qa|grep -i mysql
载时使用了--nodeps选项,忽略了依赖关系
1 rpm -e mysql-5.4.61-4.el6.x86_64 --nodeps
2:添加mysql组和mysql用户,用于设置mysql安装目录文件全部者和所属组。
1 groupadd mysql 2 useradd -r -g mysql mysql
将二进制文件解压到指定的安装目录,咱们这里指定为/usr/local
1 cd/usr/local/ 2 tar zxvf /your_path/mysql-5.5.29-linux2.6-x86_64.tar.gz
3:进入mysql文件夹,也就是mysql所在的目录,并更改所属的组和用户。
1 cd mysql 2 3 chown -R mysql . 4 5 chgrp -R mysql .
4:执行mysql_install_db脚本,对mysql中的data目录进行初始化并建立一些系统表格。注意 mysql服务进程mysqld运行时会访问data目录,因此必须由启动mysqld进程的用户(就是咱们以前设置的mysql用户)执行这个脚本,或 者用root执行,可是加上参数--user=mysql。
1 scripts/mysql_install_db --user=mysql
5:将mysql/目录下除了data/目录的全部文件,改回root用户全部,mysql用户只需做为mysql/data/目录下全部文件的全部者。
1 chown -R root . 2 3 chown -R mysql data
6: 复制配置文件
1 cp support-files/my-medium.cnf /etc/my.cnf 2 首先须要将scripts/mysql.server服务脚本复制到/etc/init.d/,并重命名为mysqld。 3 cp support-files/mysql.server /etc/init.d/mysqld
7:经过chkconfig命令将mysqld服务加入到自启动服务项中。
1 chkconfig --add mysqld 2 chkconfig --list mysqld
检查是否启动:netstat -anp|grep mysqld
启动:service mysqld start
安装php
tar -zxvf php-5.0.2.tar.gz cd php-5.0.2 ./configure --prefix=/usr/local/php5 --with-config-file-path=/usr/local/php5/etc --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql --disable-tokenizer --with-curl --with-mcrypt --enable-mbstring --with-iconv --with-gd --with-gettext --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --disable-tokenizer make make install
编译时已经制定了经常使用的扩展,若是还须要其余扩展,能够按照下面的方式来添加
进入源码安装包:ext文件
可用扩展都在那
执行步骤:
1 //添加扩展 2 /usr/local/php/bin/phpize 3 ./configure --with-php-config=/usr/local/php/bin/php-config --with-curl=DIR(默认路径时无需指定) 4 make&&make install 5 会在/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525生成curl.so文件
与apache整合:
1 php与apache整合 2 emacs /usr/local/apache2/conf/httpd.conf 找到DirectoryIndex改成以下: 3 DirectoryIndex index.html index.php index.htm index.html.var 4 找到 5 AddType application/x-compress .Z 6 AddType application/x-gzip .gz .tgz 7 在它后面添加 8 AddType application/x-httpd-php .php 9 /usr/local/apache2/bin/apachectl restart