CentOS LAMP环境搭建和测试php与mysql的链接

CentOS LAMP做为服务器,不安装不须要的组件,因此在选择组件的时候,不要选web服务器,由于咱们后面要手动编译安装。CentOS LAMP系统约定RPM包和源码包存放位置:php

  
  
  
  
  1. RPM包和源码包存放位置 /usr/local/src  
  2. 源码包编译安装位置(prefix) /usr/local/XXX  
  3. MySQL 数据库位置 /usr/local/mysql/var  
  4. 网站根目录 /usr/local/apache/htdocs 

CentOS LAMP环境搭建html

搭建的工做包括APACHE、MYSQL、PHP。能够按照这个顺序来搭建环境。mysql

一、获取软件包linux

  
  
  
  
  1. Httpd:  http://www.apache.org/dist/httpd/httpd-2.2.11.tar.gz  
  2. mysql: http://mirror.provenscaling.com/mysql/enterprise/source/5.0/mysql-5.0.70.tar.gz  
  3. php: http://museum.php.net/php5/php-5.2.2.tar.gz 

把它们所有放到 /usr/local/src 下面.>cd /usr/local/src    (定位到安装包目录)web

二、安装 mysql sql

  
  
  
  
  1. >tar -zxvf mysql-5.0.70.tar.gz  
  2. >cd mysql-5.0.70  
  3. >./configure --prefix=/usr/local/mysql  
  4. >make  
  5. >make install   
  6. >useradd mysql //添加 mysql 用户  
  7. >cd /usr/local/mysql  
  8. >bin/mysql_install_db --user=mysql 
  9. >chown -R mysql .  //设置权限,注意后面有一个点 "."  
  10. >chgrp -R mysql .  
  11. >chown -R mysql var  
  12. >cp share/mysql/my-medium.cnf /etc/my.cnf  
  13. >cp share/mysql/mysql.server /etc/rc.d/init.d/mysqld //开机启动  
  14. >chmod 755 /etc/rc.d/init.d/mysqld  
  15. >chkconfig --add mysqld 

运行了上面第8步后:数据库

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/local/mysql/bin/mysqladmin -u root password 'new-password'
/usr/local/mysql/bin/mysqladmin -u root -h centos5 password 'new-password'

Alternatively you can run:
/usr/local/mysql/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/local/mysql/bin/mysqlbug script!

The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.comapache

运行如下命令便可启动 MySQL 服务器:>/etc/rc.d/init.d/mysqld start //启动 MySQL(mysql安装完毕)centos

三、安装Apache浏览器

  
  
  
  
  1. >tar -zxvf httpd-2.2.11.tar.gz  
  2. >cd httpd-2.2.11  
  3. >./configure --prefix=/usr/local/apache --enable-module=so --enable-module=rewrite --enable-shared=max 
  4. >make  
  5. >make install 

运行上面第3步时,出现下面的问题:

[root@centos5 httpd-2.3.8]# ./configure --prefix=/usr/local/apache --enable-module=so --enable-module=rewrite --enable-shared=max
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu

Configuring Apache Portable Runtime library ...

checking for APR... no
configure: error: APR not found.  Please read the documentation.

到http://apr.apache.org/download.cgi下载 apr-1.4.2.tar.gz

解压后进入解压目录,进行以下操做:

./configure --prefix=/desired/path/of/apr
   make
   make test
   make install
 

启动apache服务 >/usr/local/apache/bin/apachectl -k start用浏览器打开 http://127.0.0.1/  若是能够访问则说明apache安装成功。

四、安装PHP

>tar -zxvf php-5.2.2.tar.gz
>cd php-5.2.2
>./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-apxs2=/usr/local/apache/bin/apxs
>make
>make install
>cp php.ini-dist /usr/local/php/lib/php.ini
>vi /usr/local/php/lib/php.ini

五、CentOS LAMP配置httpd

.conf >vi /usr/local/apache/conf/httpd.conf找到"AddType application/x-gzip .tgz"在它的下面添加AddType application/x-httpd-php .phpAddType application/x-httpd-php-source .phps找到"DirectoryIndex index.html在index.html 前添加 index.php

启动apache服务>/usr/local/apache/bin/apachectl -k start将apache设置成开机自启动:在/etc/rc.d/rc.local文件中加入一行并保存: /usr/local/apache /bin/apachectl start (apache+php配置完毕)

六、查看确认 L.A.M.P 环境信息:>vi /usr/local/apache/htdocs/phpinfo.php新增长下面一行,并保存。 <?php phpinfo(); ?>>chmod 755 /usr/local/apache/htdocs/phpinfo.php用浏览器打开 http://127.0.0.1/phpinfo.php检查 phpinfo中的各项信息是否正确。若是能够访问则环境搭建成功

测试php与mysql的链接

  
  
  
  
  1. >vi /usr/local/apache/htdocs/testdb.php增长下面几行,并保存。  
  2. <?php 
  3. $link=mysql_connect('localhost','root','yourpassword');  
  4. if(!$link) echo "fail";  
  5. else echo "success";  
  6. mysql_close();  
  7. ?> 
  8. >chmod 755 /usr/local/apache/htdocs/testdb.php  
  9. >service mysqld start 

用浏览器打开 http://127.0.0.1/testdb.php若是输出success代表php与mysql链接成功CentOS LAMP环境搭建完毕

相关文章
相关标签/搜索