当前位置: > Linux发行版 > Debian >

debian7.8安装LAMP+Redis

时间:2015-10-08 14:27来源:linux.it.net.cn 作者:IT
  • 1、安装apache2+mysql5.5+php5
  • 2、安装mysql管理工具phpmyadmin, mysql-workbench
  • 3、安装redis-server
  • 4、pear安装mysql封装:MDB2
  • 5、安装php5-curl

1、安装apache2+mysql5.5+php5

sudo apt-get install mysql-server-5.5
sudo apt-get install apache2
sudo apt-get install php5 php5-mysql
sudo apt-get install libapache2-mod-php5

vi /var/www/index.html

<!DOCTYPE html>
<html>
<body>

<?php
echo "My first PHP script!";
?>  

</body>
</html>

浏览器打开 http://localhost/index.php 看到内容:My first PHP script!,说明apahe2和php已安装成功。

测试php脚本中是否能连接mysql

shen@debian:/var/www/shm_fast$ cat connect-mysql.php 
<?php
$servername = "localhost";
$username = "root";
$password = "123456";

// 创建连接
$conn = mysqli_connect($servername, $username, $password);

// 检测连接
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
?>
shen@debian:/var/www/shm_fast$ php -f connect-mysql.php 
Connected successfully

浏览器中输入: http://localhost/shm_fast/connect-mysql.php
看到网页输出: Connected successfully 表示mysql安装正确。

2、安装mysql管理工具phpmyadmin, mysql-workbench

sudo apt-get install phpmyadmin

安装中选择apache2作为web server。

在Debain桌面,打开菜单: 应用程序 > 编程 > phpMyAdmin, 或者浏览器中输入http://localhost/phpmyadmin/
能打开phpmyadmin登录页面,以root帐号登录,如果成功说明phpmyadmin已安装成功。

输入图片说明

输入图片说明

phpMyAdmin版本信息: 3.4.11.1deb2+deb7u1

apt-get install mysql-workbench

安装完成后,在Debain桌面,打开菜单: 应用程序 > 编程 > MySQL Workbench, 即可打开桌面应用MySQL Workbench

输入图片说明

安装后的版本号是5.2.40

3、安装redis-server

sudo apt-get install redis-server

版本2.4.14

shen@debian:~$ redis-server --version
Redis server version 2.4.14 (00000000:0)
shen@debian:~$ sudo /etc/init.d/redis-server status
redis-server is running

安装PHP包管理器——pear

sudo apt-get install php-pear
sudo apt-get install php5-dev

打开网站 http://pecl.php.net/ 搜索 redis,进入 http://pecl.php.net/package/redis

sudo pear install http://pecl.php.net/get/redis-2.2.7.tgz
...
Build process completed successfully
Installing '/usr/lib/php5/20100525/redis.so'
install ok: channel://pecl.php.net/redis-2.2.7
configuration option "php_ini" is not set to php.ini location
You should add "extension=redis.so" to php.ini
sudo vi /etc/php5/mods-available/redis.ini
shen@debian:~$ cat /etc/php5/mods-available/redis.ini
; configuration for php redis module
; priority=20
extension=redis.so
shen@debian:/etc/php5/conf.d$ sudo ln -snf ../mods-available/redis.ini 20-redis.ini
shen@debian:/etc/php5/conf.d$ ls -l
总用量 0
lrwxrwxrwx 1 root root 25  8月 31 13:36 10-pdo.ini -> ../mods-available/pdo.ini
lrwxrwxrwx 1 root root 24  9月  5 10:02 20-gd.ini -> ../mods-available/gd.ini
lrwxrwxrwx 1 root root 28  9月  5 10:02 20-mcrypt.ini -> ../mods-available/mcrypt.ini
lrwxrwxrwx 1 root root 28  8月 31 13:36 20-mysqli.ini -> ../mods-available/mysqli.ini
lrwxrwxrwx 1 root root 27  8月 31 13:36 20-mysql.ini -> ../mods-available/mysql.ini
lrwxrwxrwx 1 root root 31  8月 31 13:36 20-pdo_mysql.ini -> ../mods-available/pdo_mysql.ini
lrwxrwxrwx 1 root root 27  9月  9 09:41 20-redis.ini -> ../mods-available/redis.ini

重启apache

shen@debian:~$ sudo /etc/init.d/apache2 restart
[ ok ] Restarting web server: apache2 ... waiting .

4、pear安装mysql封装:MDB2

sudo pear install MDB2
sudo pear install MDB2#mysql
sudo pear install PHP_Debug

5、安装php5-curl

测试curl代码:

shen@debian:~$ cat curl_version.php 
<?php
// 获取cURL版本数组
$version = curl_version();

// 在cURL编译版本中使用位域来检查某些特性
$bitfields = Array(
            'CURL_VERSION_IPV6', 
            'CURL_VERSION_KERBEROS4', 
            'CURL_VERSION_SSL', 
            'CURL_VERSION_LIBZ'
            );


foreach($bitfields as $feature)
{
    echo $feature . ($version['features'] & constant($feature) ? ' matches' : ' does not match');
    echo PHP_EOL;
}
?>

安装之前运行错误:

shen@debian:~$ php -f curl_version.php 
PHP Fatal error:  Call to undefined function curl_version() in /home/shen/curl_version.php on line 3

安装并测试:

shen@debian:~$ sudo apt-get install php5-curl
shen@debian:~$ php -f curl_version.php 
CURL_VERSION_IPV6 matches
CURL_VERSION_KERBEROS4 does not match
CURL_VERSION_SSL matches
CURL_VERSION_LIBZ matches



(责任编辑:IT)
------分隔线----------------------------