最近学习linux,安装lamp遇到一些问题,记录下来分享一下;

------------------------------------------------------------------------------------------------------------------

Linux + Apache + MySQL + PHP/Perl together commonly known as LAMP Server.

参考blog:http://www.howtoforge.com/quick-n-easy-lamp-server-centos-rhel

一 安装apache:

yum install httpd httpd-devel

/etc/init.d/httpd start

二 安装mysql:(如遇问题,参考:http://blog.csdn.net/indexman/article/details/16946141)

yum install mysql mysql-server mysql-devel

/etc/init.d/mysqld start
mysql

mysql> USE mysql;
mysql> UPDATE user SET Password=PASSWORD('newpassword') WHERE user='root';
mysql> FLUSH PRIVILEGES;

mysql -u root -p
Enter Password: <your new password>

1、创建用户:



mysql> GRANT ALL PRIVILEGES ON *.* TO dylan@localhost IDENTIFIED BY 'dylan123';

mysql> FLUSH PRIVILEGES;

2、创建测试数据库:

mysql> create database testdb;

Query OK; 1 row affected (0.03 sec)

mysql> show databases;
+-----------------+
| Database |
+-----------------+
| mysql |
| test |
| test_db |
+-----------------+
6 rows in set (0.00 sec)

mysql> use testdb
Database changed

mysql> CREATE TABLE comment_table(
-> id INT NOT NULL auto_increment,
-> comment TEXT,
-> PRIMARY KEY(id));
Query OK, 0 rows affected (0.10 sec)
mysql> show tables;
+-------------------------+
| Tables_in_test_database |
+-------------------------+
| comment_table |
+-------------------------+
1 row in set (0.00 sec)
mysql> INSERT INTO comment_table VALUES ('0','comment');
Query OK, 1 row affected (0.06 sec)
mysql> SELECT * FROM comment_table;
+----+---------+
| id | comment |
+----+---------+
| 1 | comment |
+----+---------+
1 row in set (0.01 sec)

三、安装PHP5:

yum install php php-mysql php-common php-gd php-mbstring php-mcrypt php-devel php-xml

/etc/init.d/httpd restart

vi /var/www/html/test.php

#test.php 内容如下:



<?php

   php_info();

?>

测试地址:Then point your browser to http://localhost/test.php

四、测试PHP操作mysql:

1、测试PHP能否正常连接mysql:

vi  /var/www/html/test_conn.php

<?php
$link=mysql_connect('127.0.0.1','root','root123');
if(!$link) echo "false!";
else echo " true!";
mysql_close($link);
?>

2、测试PHP提交数据到表comment_table:

2.1   vi /var/www/html/write_comment_table.html

<html>
<form action=write.php method="get">
<input type="text" name="comment" size="80"> <br>
<input type="submit">
</form>
</html>

2.2  
vi /var/www/html/write.php

<html>
<body>
<?php
$comment=$_GET['comment'];
if ($comment){
$conn=mysql_connect("localhost","root","root123" )
or die("Could not connect to MySQL as root");
mysql_select_db("testdb", $conn)
or die("could not select the test_database");
$string="INSERT INTO comment_table VALUES ('0','$comment')";
mysql_query($string)
or die(mysql_error( ));} print ($comment);
print ("thanks for submit!!!");
?>
</body>
</html>

3、测试PHP查询表comment_table数据:

vi /var/www/html/view_comment_table.php

<html>
<?php
$conn=mysql_connect("localhost","root","root123" )
or die("Could not connect to MySQL as root");
mysql_select_db("testdb", $conn)
or die("could not select the test_database");
$string="SELECT * FROM comment_table";
$result= mysql_query($string)
or die(mysql_error( ));
$numbers_cols= mysql_num_fields($result);
print "<b>query: $string</b>";
print "<table border =1>\n";
print "<tr>";
print "<td> ID</td>";
print "<td> Comment </td>";
print "</tr>";
while (list($id,$comment) = mysql_fetch_array($result)){
print "<tr>";
print "<td>$id</td>";
print "<td>$comment</td>";
print "</tr>";}
print "</table>";
mysql_close($conn);
?>
</html>

------------------

dylan presents.

linux 快速安装LAMP教程的更多相关文章

  1. linux快速安装lamp环境

    我折腾过不少的lamp安装方式,lnmp也折腾过.不过因为windows下面apache用的比较多,各种配置也比较熟悉,因此最终还是选择了lamp这个架构. 由于是自己装虚拟机玩,所以各种安全措施都没 ...

  2. linux快速安装mysql教程

    #安装mysql服务器:yum install mysql-server #设置开机启动chkconfig mysqld on#现在启动服务service mysqld start #设置root初始 ...

  3. Ubuntu下快速安装LAMP server

    Ubuntu下可快速安装LAMP server(Apache+MySQL+PHP5). 首先,打开Ubuntu虚拟机,Terminal打开root权限:“sudo -s”. 一.安装LAMP serv ...

  4. linux上安装LAMP笔记

    B哥最近在参加比赛,需要把一个php项目部署到服务器上,故此在linux上安装LAMP环境,用于部署项目,第一次安装,做点儿笔记记录一下. 安装条件: Redhat或者CentOS linux环境已装 ...

  5. 【Git】2、Linux快速安装Git环境 & oh-my-zsh

    Linux快速安装Git环境 文章目录 Linux快速安装Git环境 1.Linux安装Git 2.安装zsh 3.安装oh-my-zsh 3.1.安装oh-my-zsh 3.2. 测试验证 4.小结 ...

  6. JetBrains IntelliJ IDEA(IJ)v2019.3.3/3.1/3.2/3.4/3.5 for mac/windows/linux 详细安装破解教程

    手欠升级了IntelliJ IDEA到2019.3.3,原来的破解不可用,IntelliJ IDEA 2019.3.3破解办法如下,为方便自己使用记录下.======================= ...

  7. Twitter开源的Heron快速安装部署教程

    什么是Heron? Twitter使用Storm实时分析海量数据已经有好几年了,并在2011年将其开源.该项目稍后开始在Apache基金会孵化,并在2015年秋天成为顶级项目.Storm以季度为发布周 ...

  8. FinalShell Mac OS版,Linux版安装及教程

    该版本功能和windows版基本一样,但是主机检测和远程桌面功能由于兼容性问题暂时无法使用,以后会支持. 该版本功能和windows版基本一样,但是主机检测和远程桌面功能由于兼容性问题暂时无法使用,以 ...

  9. FinalShell Mac OS版,Linux版安装及教程(Mac下的xshell)

    用户QQ群 342045988 Mac版安装路径/Applications/finalshelldata Linux版安装路径/usr/lib/finalshelldata 注意:1.FinalShe ...

  10. Linux下安装mysql教程

    Linux下安装mysql  MySQL官网:https://dev.mysql.com/downloads/mysql/ 到mysql官网下载mysql编译好的二进制安装包,在下载页面Select ...

随机推荐

  1. Android——共享参数SharedPreferences

    4数据存储 共享参数SharedPreferences.数据库SQLite.SD卡文件.App的全局内存 4.1共享参数SharedPreferences SharedPreferences是一个轻量 ...

  2. Go-数据类型-布尔类型-bool

    布尔类型--bool 只有两个值 true false 不能转换成其他类型,也不能参加数值运算 布尔应用场景 if swicht for 三大分支语句中的条件部分 比较运算和逻辑运算的返回值 作为通道 ...

  3. MySQL高可用搭建方案之(MMM)

    有的时候博客内容会有变动,首发博客是最新的,其他博客地址可能会未同步,认准https://blog.zysicyj.top 注意:这篇转载文章,非原创 首发博客地址 原文地址 前言 MySQL的高可用 ...

  4. [转帖]TLS/SSL (Schannel SSP) 中的密码套件

    https://learn.microsoft.com/zh-cn/windows/win32/secauthn/cipher-suites-in-schannel 密码套件是一组加密算法. TLS/ ...

  5. [转帖]关于F5负载均衡你认识多少?

    https://www.cnblogs.com/xiexun/p/10718348.html 网络负载均衡(load balance),就是将负载(工作任务)进行平衡.分摊到多个操作单元上进行执行,例 ...

  6. Redis 菜鸟进阶

    Redis 菜鸟进阶 背景 最近产品一直要优化性能,加强高可用. 有一个课题是Redis高可用与性能调优. 我这边其实获取到的内容很有限. 最近济南疫情严重,自己锁骨骨折. 然后通勤时间基本上都用来查 ...

  7. React类组件中事件绑定this指向的三种方式

    有状态组件和无状态组件 函数组件又叫做无状态组件,类组件又叫做有状态组件. 状态又叫做数据 函数组件没有自己的状态,只负责静态页面的展示. 我们可以理解为纯ui展示.() 类组件有自己的状态,扶着更新 ...

  8. 乌班图安装docker

    目录 一.前言 二.安装 2.1 设置仓库 2.3 安装 Docker Engine 2.4 安装特定版本的 Docker Engine: 2.5 测试 三.配置非 root 用户运行 Docker ...

  9. CMake出错的处理

    在windows上使用cmake来c++的程序,遇到一个问题 问题排查 试过在电脑上单独使用gcc是可以编译成功的,那么就可能是IDE集成的问题了 IDE的编译工具链从mingw换成vs,编译通过 让 ...

  10. vim 从嫌弃到依赖(7)——可视模式

    vim 的可视模式下可以选择一个区域,然后针对区域进行操作.可视模式有点类似于在其他编辑器上使用鼠标选中一块区域然后针对区域进行操作. vim中有3种可视模式,分别用来处理不同范围的文本: 处理字符的 ...