LAMP環境搭建

1. 安裝mysql

###############################

注意,剛開始安裝出錯,原因是二進制包下載錯了,本機centos是32位的,卻下載了個64位的二進制包

###############################

[root@chen src]# cd /usr/local/src/

[root@chen src]# wget http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.73-linux-x86_64-glibc23.tar.gz   

#二進制包免編譯,若是64位系統,則下載這個包,32位則下載下面排錯時的包

[root@chen src]# tar zxvf mysql-5.1.73-linux-x86_64-glibc23.tar.gz

[root@chen src]# mv mysql-5.1.73-linux-x86_64-glibc23 /usr/local/mysql

[root@chen ~]# useradd -s /sbin/nologin mysql

 [root@chen ~]# cd /usr/local/mysql

[root@chen mysql]# mkdir -p /data/mysql

[root@chen mysql]# chown -R mysql:mysql /data/mysql

[root@chen mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql

./scripts/mysql_install_db: line 249: ./bin/my_print_defaults: cannot execute binary file

Neither host 'chen' nor 'localhost' could be looked up with

./bin/resolveip

Please configure the 'hostname' command to return a correct

hostname.

If you want to solve this at a later stage, restart this script

with the --force option

########################

此時出現錯誤,經過蒐集資料,發現是因爲本機系統爲32位,卻下載了一個64位的二進制包

使用命令如下命令查看本機系統是32位,還是64位

[root@chen mysql]# getconf LONG_BIT

32


########################

#重新下下載一個對應包,再進行之前的操作,錯誤解決

[root@chen mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql

Installing MySQL system tables...

OK

Filling help tables...

OK


To start mysqld at boot time you have to copy

support-files/mysql.server to the right place for your system

#出現兩個OK則正確安裝上了

[root@chen mysql]# cp support-files/my-large.cnf /etc/my.cnf

cp:是否覆蓋"/etc/my.cnf"? y       #由於系統自帶此文件,需要將它覆蓋掉

[root@chen mysql]# cp support-files/mysql.server /etc/init.d/mysqld

[root@chen mysql]# chmod 755 /etc/init.d/mysqld

[root@chen mysql]# vim /etc/init.d/mysqld   #修改basedir和basedir,如下:


# overwritten by settings in the MySQL configuration files.


basedir=/usr/local/mysql

datadir=/data/mysql



[root@chen mysql]# chkconfig --add mysqld

[root@chen mysql]# chkconfig mysqld on

[root@chen mysql]# service mysqld start

Starting MySQL............. SUCCESS!

#成功安裝並啓動mysql

2. 安裝apache

[root@chen src]# wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.2.31.tar.gz

[root@chen src]# tar zxvf httpd-2.2.31.tar.gz

[root@chen src]# cd httpd-2.2.31

[root@chen httpd-2.2.31]# ./configure --prefix=/usr/local/apache2 --with-included-apr  --with-pcre --enable-mods-shared=most

[root@chen httpd-2.2.31]# echo $?   #檢查上一步是否出錯,若爲0則未出錯,非0則有錯

0

[root@chen httpd-2.2.31]# make && make install

[root@chen httpd-2.2.31]# echo $?

0

【如何指定使用worker/prefork】http://www.lishiming.net/thread-944-1-1.html
【apache兩種工作模式】http://www.lishiming.net/thread-838-1-2.html

3.  安裝php

[root@chen src]# wget http://cn2.php.net/distributions/php-5.3.28.tar.gz

[root@chen src]# tar zxf php-5.3.28.tar.gz

[root@chen src]# cd php-5.3.28

[root@chen php-5.3.28]# ./configure   --prefix=/usr/local/php   --with-apxs2=/usr/local/apache2/bin/apxs   --with-config-file-path=/usr/local/php/etc   --with-mysql=/usr/local/mysql   --with-libxml-dir   --with-gd   --with-jpeg-dir   --with-png-dir   --with-freetype-dir   --with-iconv-dir   --with-zlib-dir   --with-bz2   --with-openssl   --with-mcrypt   --enable-soap   --enable-gd-native-ttf   --enable-mbstring   --enable-sockets   --enable-exif   --disable-ipv6

######################

執行上面命令的過程中會遇到一些依賴缺少的提示,下面列出我遇到的依賴問題:
錯誤:
configure: error: xml2-config not found. Please check your libxml2 installation.

解決:
yum  install -y  libxml2-devel

錯誤:
configure: error: jpeglib.h not found.

解決:
yum  install -y  libjpeg-devel

錯誤:
configure: error: mcrypt.h not found. Please reinstall libmcrypt.

解決:
yum  install  -y  libmcrypt-devel
由於版權原因,可能無法直接安裝上面的包,在百度經驗裏找到了一個解決辦法:
http://jingyan.baidu.com/article/54b6b9c0e94f1e2d583b4782.html

錯誤:
checking for recode support... yes
configure: error: Can not find recode.h anywhere under /usr /usr/local /usr /opt.

解決:
yum  install -y  librecode-devel


######################

重新編譯執行如上操作,出現以下提示,則表明安裝成功:

+--------------------------------------------------------------------+

| License:                                                           |

| This software is subject to the PHP License, available in this     |

| distribution in the file LICENSE.  By continuing this installation |

| process, you are bound by the terms of this license agreement.     |

| If you do not agree with the terms of this license, you must abort |

| the installation process at this point.                            |

+--------------------------------------------------------------------+


Thank you for using PHP.


[root@chen php-5.3.28]# echo $?

0

[root@chen php-5.3.28]# make && make install

[root@chen php-5.3.28]# echo $?

0

[root@chen php-5.3.28]#  cp php.ini-production /usr/local/php/etc/php.ini     #拷貝配置文件


4. 配置apache結合php

vim /usr/local/apache2/conf/httpd.conf找到:

    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all

改爲:

    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Allow from all




找到:
AddType application/x-gzip .gz .tgz
在該行下面添加:

AddType application/x-httpd-php .php
找到:

    DirectoryIndex index.html

將該行改爲:

    DirectoryIndex index.html index.htm index.php

找到:
#ServerName www.example.com:80
修改爲:
ServerName localhost:80


查看配置文件是否有問題:

/usr/local/apache2/bin/apachectl -t

如果顯示Syntax OK,則沒有問題了。然後啓動服務:

/usr/local/apache2/bin/apachectl start

檢查Apache是否正常啓動:

[root@chen php-5.3.28]# ps aux |grep httpd

root      6733  0.0  1.0  28912  9952 ?        Ss   03:58   0:00 /usr/local/apache2/bin/httpd -k start

daemon    6734  0.0  0.9  28912  8716 ?        S    03:58   0:00 /usr/local/apache2/bin/httpd -k start

daemon    6735  0.0  0.9  28912  8716 ?        S    03:58   0:00 /usr/local/apache2/bin/httpd -k start

daemon    6736  0.0  0.9  28912  8716 ?        S    03:58   0:00 /usr/local/apache2/bin/httpd -k start

daemon    6737  0.0  0.9  28912  8716 ?        S    03:58   0:00 /usr/local/apache2/bin/httpd -k start

daemon    6738  0.0  0.9  28912  8716 ?        S    03:58   0:00 /usr/local/apache2/bin/httpd -k start

root      6753  0.0  0.0   6052   788 pts/0    S+   04:01   0:00 grep httpd

5. 測試解析php
vim /usr/local/apache2/htdocs/1.php
寫入:

<?php
    echo "php解析正常";
?>
保存後,繼續測試:

curl localhost/1.php




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章