前言

因为在windows下搞pear没有成功,老出现无缘无故的问题,所以今天用ubuntu搭建了一个php。众所周知开源代码和linux总是有无懈的缘分,而我作为一个开源的忠实粉丝,却还抱着windows系统不放,总有些惭愧,下一个wamp毫无技术可言就搞定了。少说废话,下面就开始。



ubuntu搭建php

① apache2

  • sudo apt-get install apache2

…大概几秒钟时间

打开浏览器输入http://localhost/

it works总是令人那么激动,只是你还有很多东西要做

② PHP5

  • sudo apt-get install php5

  • sudo apt-get install libapache2-mod-php5

  • sudo /etc/init.d/apache2 restart

然后php应该被安装到了/etc/php5/

试试 php -v

查询到PHP 5.4.6

③ MySql

  • sudo apt-get install mysql-server

MySql初始只允许本机(127.0.0.1)连接,如果想多台机子使用或者向Internet开放的话,编辑/etc/mysql/my.cnf

  • sudo gedit /etc/mysql/my.cnf

找到bind-address = 127.0.0.1 在前面加一个’#’注释掉

④ MySql Administrator

  • sudo apt-get install mysql-admin

不知道为啥这个命令没有成功,如果你也不行,可以试下下面的命令

  • sudo apt-get install libapache2-mod-auth-mysql
  • sudo apt-get install php5-mysql
  • sudo apt-get install phpmyadmin

要让PHP与MySql一起工作,编辑

  • sudo gedit /etc/php5/apache2/php.ini

取消对;extension=mysql.so的注释

重启apache

  • sudo /etc/init.d/apache2 restart

打开浏览器输入http://localhost/phpmyadmin,我在这里输的时候,出现了一个问题

Not Found The requested URL /phpmyadmin/ was not found on this server. Apache/2.2.14 (Ubuntu) Server at localhost Port 80

然后各种纠结,百度了以后才知道得让phpAdministrator和php建立一个软连接

打开var/www

  • sudo ln -s /usr/share/phpmyadmin

⑤ pear

下载pear在php中是一个很简单的事情,只要输入一行代码

  • curl -o go-pear.php http://pear.php.net/go-pear

如果你没有按curl,请输入一行命令

  • sudo apt-get install curl libcurl3 libcurl3-dev php5-curl

重启下服务器

  • sudo /etc/init.d/apache2 restart

⑥ 运行go-pear.php

找到go-pear.php

  • php go-pear.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
1. Installation base ($prefix)                   : /usr/local/php5
2. Temporary directory for processing            : /tmp/pear/install
3. Temporary directory for downloads             : /tmp/pear/install
4. Binaries directory                            : /usr/local/php5/bin
5. PHP code directory ($php_dir)                 : /usr/local/php5/lib/php
6. Documentation directory                       : /usr/local/php5/docs
7. Data directory                                : /usr/local/php5/data
8. User-modifiable configuration files directory : /usr/local/php5/cfg
9. Public Web Files directory                    : /usr/local/php5/www
10. Tests directory                               : /usr/local/php5/tests
11. Name of configuration file                    : /usr/local/php5/etc/pear.conf
1-11, ‘all’ or Enter to continue:
Beginning install…
Configuration written to /usr/local/php5/etc/pear.conf…
Initialized registry…
Preparing to install…
installing phar://go-pear.phar/PEAR/go-pear-tarballs/Archive_Tar-1.3.7.tar…
installing phar://go-pear.phar/PEAR/go-pear-tarballs/Console_Getopt-1.3.0.tar…
installing phar://go-pear.phar/PEAR/go-pear-tarballs/PEAR-1.9.4.tar…
installing phar://go-pear.phar/PEAR/go-pear-tarballs/Structures_Graph-1.0.4.tar…
installing phar://go-pear.phar/PEAR/go-pear-tarballs/XML_Util-1.2.1.tar…
install ok: channel://pear.php.net/Archive_Tar-1.3.7
install ok: channel://pear.php.net/Console_Getopt-1.3.0
install ok: channel://pear.php.net/Structures_Graph-1.0.4
install ok: channel://pear.php.net/XML_Util-1.2.1
install ok: channel://pear.php.net/PEAR-1.9.4
PEAR: Optional feature webinstaller available (PEAR’s web-based installer)
PEAR: Optional feature gtkinstaller available (PEAR’s PHP-GTK-based installer)
PEAR: Optional feature gtk2installer available (PEAR’s PHP-GTK2-based installer)
PEAR: To install optional features use “pear install pear/PEAR#featurename”
** WARNING! Old version found at /usr/local/php5/bin, please remove it or be sure to use the new /usr/local/php5/bin/pear command
The ‘pear’ command is now at your service at /usr/local/php5/bin/pear
** The ‘pear’ command is not currently in your PATH, so you need to
** use ‘/usr/local/php5/bin/pear’ until you have added
** ‘/usr/local/php5/bin’ to your PATH environment variable.
Run it without parameters to see the available actions, try ‘pear list’
to see what packages are installed, or ‘pear help’ for help.
For more information about PEAR, see:
http://pear.php.net/faq.php
http://pear.php.net/manual/

linux, php






发表评论