1. 安装mysql
cd /usr/local/src/
wget http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.73-linux-i686-glibc23.tar.gz
注意:上面的地址是32位机器用的,如果你的机器是64位, 安装方法是一样的。
tar zxvf /usr/local/src/mysql-5.1.73-linux-i686-icc-glibc23.tar.gz
mv mysql-5.1.73-linux-i686-icc-glibc23 /usr/local/mysql
useradd -s /sbin/nologin mysql
cd /usr/local/mysql
mkdir -p /data/mysql
chown -R mysql:mysql /data/mysql
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
cp support-files/my-large.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
vim /etc/init.d/mysqld #修改datadir
chkconfig --add mysqld
chkconfig mysqld on
service mysqld start
2. 安装apache
wget http://archive.apache.org/dist/httpd/httpd-2.2.27.tar.bz2
tar jvxf httpd-2.2.27.tar.bz2
cd httpd-2.2.27
./configure --prefix=/usr/local/apache2 --enable-mods-shared=most --enable-so
时间花的会久点,之后 echo $?
make && make install
3. 安装php
wget http://cn2.php.net/distributions/php-5.3.28.tar.gz
tar zxf php-5.3.28.tar.gz
cd 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
以下几种错误的解决办法:
yum install -y libxml2-devel
yum install -y openssl openssl-devel
yum install -y bzip2 bzip2-devel
yum install -y libpng libpng-devel
yum install -y freetype freetype-devel
yum install -y libjpeg-devel
遇到该错误时:configure: error: mcrypt.h not found. Please reinstall libmcrypt.
yum install -y epel-release
yum install -y libmcrypt-devel
make && make install
4. 配置apache结合php
vim /usr/local/apache2/conf/httpd.conf
找到:
AddType application/x-gzip .gz .tgz
在该行下面添加:
AddType application/x-httpd-php .php
找到:
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
将该行改为:
<IfModule dir_module>
DirectoryIndex index.html index.htm index.php
</IfModule>
找到:
#ServerName www.example.com:80
修改为:
ServerName localhost:80
5. 测试解析php
先 /usr/local/apache2/bin/apachectl -t 检测是否有错误,如果显示Syntax ok 则没有问题
/usr/local/apache2/bin/apachectl start
用netstat -lnp |grep httpd 查看是否开启成功
vim /usr/local/apache2/htdocs/1.php
写入:
<?php echo "abcd"; ?>
保存后,继续测试:
curl localhost/1.php
6.LAMP环境是搭建成功