CENTOS5.1上搭建LAMP环境

1.下载所需的软件
http://httpd.apache.org/download.cgi
www.php.net
http://www.mysql.com/
2.安装MySQL5
2.1安装ncurses-devel 包
2.2安装gcc-c++ 包
2.3解压
[root@localhost upload]#tar zxvf mysql-5.0.51.tar.gz
2.4创建用户
[root@localhost upload]# useradd mysql
[root@localhost upload]# passwd mysql

2.5编译安装
[root@localhost upload]# ./configure --prefix=/opt/mysql5
[root@localhost upload]# make
[root@localhost upload]# make install

2.6拷贝文件,改权限
[root@localhost mysql-5.0.51]# cp support-files/my-medium.cnf /etc/my.cnf
[root@localhost mysql-5.0.51]# cd /opt/mysql5/
[root@localhost mysql5]# chown -R mysql:mysql .
[root@localhost mysql5]# bin/mysql_install_db --user=mysql
[root@localhost mysql5]# chown -R root .
[root@localhost mysql5]# chown -R mysql var

2.7启动查看
[root@localhost mysql5]# bin/mysqld_safe --user=mysql &
[root@localhost mysql5]# ps -ef | grep mysql
[root@localhost bin]# ./mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.51-log Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.01 sec)
mysql> quit
Bye

2.8关闭
[root@localhost bin]# ./mysqladmin shutdown
[root@localhost mysql5]# ps -ef | grep mysql
3.安装apache和php
3.1解压
[root@localhost upload]# tar zxvf httpd-2.2.6.tar.gz
[root@localhost upload]# tar zxvf php-5.2.5.tar.gz
3.2安装apache
[root@localhost upload]# httpd-2.2.6/configure --enable-so --prefix=/opt/www
[root@localhost upload]# make
[root@localhost upload]# make install
3.3安装php
[root@localhost upload]# rpm -ivh libxml2-2.6.26-2.1.2.i386.rpm
[root@localhost upload]# rpm -ivh zlib-devel-1.2.3-3.i386.rpm
[root@localhost upload]# rpm -ivh libxml2-devel-2.6.26-2.1.2.i386.rpm
[root@localhost upload]# php-5.2.5/configure --with-apxs2=/opt/www/bin/apxs --with-mysql=/opt/mysql5
[root@localhost upload]# make
[root@localhost upload]# make install

3.4查看是否安装成功
进入/opt/www/modules是否有libphp5.so
3.5拷文件
[root@localhost upload]# cp php-5.2.5/php.ini-dist /usr/local/lib/php.ini
3.6修改httpd.conf文件
添加AddType application/x-httpd-php .php .phtml
3.7启动
/opt/www/bin/apachectl start
如果碰到这样的错误,关掉selinux就可以了
httpd: Syntax error on line 53 of /opt/www/conf/httpd.conf: Cannot load /opt/www/modules/libphp5.so into server: /opt/www/modules/libphp5.so: cannot restore segment prot after reloc: Permission denied
3.8测试

在/opt/www/htdocs目录下新建一个test.php
vi test.php
输入以下内容
<?php

phpinfo();
?>
浏览器
http://192.168.1.218/test.php

你可能感兴趣的:(centos)