Linux学习笔记(LAMP-环境搭建)


 

1.安装mysql
cd /usr/local/src/
wget http://syslab.comsenz.com/downloads/linux/mysql-5.1.40-linux-i686-icc-glibc23.tar.gz

\
注意:上面的地址是32位机器用的,如果你的机器是64位,下载这个包(http://syslab.comsenz.com/downloads/linux/mysql-5.1.40-linux-x86_64-icc-glibc23.tar.gz)安装方法是一样的。
tar zxvf /usr/local/src/mysql-5.1.40-linux-i686-icc-glibc23.tar.gz
mv mysql-5.1.40-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://syslab.comsenz.com/downloads/linux/httpd-2.2.16.tar.gz
tar zvxf httpd-2.2.16.tar.gz
cd httpd-2.2.16
./configure --prefix=/usr/local/apache2 --enable-mods-shared=most --enable-so
make && make install

使用:cat /usr/local/apache2/build/config.nice:可以查看编译参数

./bin/apachectl graceful:可以不把进程杀死

 

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

(apxs是php的自动配置的)
make && make install

查看安装了哪些模块:

/usr/local/php/bin/php -m

\

/usr/local/php/bin/php -i:可以看php的参数

\

 

 

4. 配置apache结合php
vim /usr/local/apache2/conf/httpd.conf
找到:
AddType application/x-gzip .gz .tgz
在该行下面添加:
AddType application/x-httpd-php .php

检测:/usr/local/apache2/bin/apachectl -t

\
找到:

DirectoryIndex index.html


将该行改为:

DirectoryIndex index.html index.htm index.php


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

 

 

5. 测试解析php
vim /usr/local/apache2/htdocs/1.php
写入:

phpinfo();
?>
保存后,继续测试:

curl localhost/1.php

 

 

如果解析不了php文件:

看看apache加载了php没有:

ls /usr/local/apache2/modules/libphp5.so

ldd可以看加载成功了没有

看看加载了php成功没有:

grep -i ‘addtype’ /usr/local/apche2/conf/httpd.conf

然后重启apache,然后再试试看看

 

测试mysql的连通性:

写一个文件并访问,文件内容如下

$conn= mysql_connect("localhost", "root", "密码");

if($conn){

echo"连接mysql成功!";

}

else{

echo"连接mysql失败!";

}

?>

如果输出"连接mysql成功!"则连接成功!

 

相关内容