![]() | 點擊翻譯: | English • 中文 |
|
Parent page: Programming ApplicationsThis is to help people setup and install a LAMP(Linux-Apache-MySQL-PHP) server in Ubuntu, including Apache 2, PHP 4 or5, and MySQL 4.1 or 5.0. When installing from the Ubuntu 6.06 (DapperDrake) "Server cd", you have the option of choosing to install a LAMPsetup at the inital Ubuntu installation screen. That will installapache2, php5 and mysql 5.0.
這是幫助大家在Ubuntu里安裝并設置一個LAMP(Linux-Apache-MySQL-PHP)服務。其中包括Apache2, PHP 4/5 和 MySQL 4.1/ 5.0。當你從Ubuntu 6.06 (Dapper Drake)“ServerCD”里安裝系統(tǒng), 在Ubuntu安裝程序的開始時有一個讓你選擇安裝LAMP的選項。選擇後將安裝apache2, php5 and mysql5.0.
Some applications require php4 while others will work with php5. Besure to install the version of php and the corresponding apache2 modulefor it. You cannot have both php4 and php5 modules running on the sameinstance of apache2 at the same time. Installing one may remove theother. If you have both php4 and php5 installed, be aware of whichversion of the apache2 php module you have. If libapache2-mod-php5 isalready installed, the php4 package will install libapache-mod-php4 andnot libapache2-mod-php4 package. If libapache2-mod-php5 is notinstalled, installing php4 will install the apache2 php module(libapache2-mod-php4). See this example. Most web applications will useApache2, php5 and mysql5.0. If no specific versions are mentioned inyour web application‘s documentation, use those.
有些應用程序用PHP5工作,有些則需要PHP4。確定應用程序安裝的PHP版本和對應的apache2模塊。你不能把PHP4和php5同時安裝在同一個apache2實例中。安裝了其中的一個會刪除另一個。如果你都安了php4和php5,了解哪個版本適的apache2php模塊是你要用的。如果libapache2-mod-php5已經(jīng)安裝了,php4的軟件包應該安裝libapache-mod-php4而不是libapache2-mod-php4。如果libapache2-mod-php5 軟件包沒有被安裝,則php4就要安apache2php模塊(libapache2-mod-php4)??催@個例子,大部分的web程序都用Apache2,php5和mysql5.0.如果你的web程序的文檔里沒有提到要特定的版本,就安裝它們。
如果你沒有用服務器版CD里的LAMP安裝程序安裝它,但又不想重裝系統(tǒng)來安裝同樣的軟件包的話。用任何方式(any method)來安裝下列軟件包
apache2 php5-mysql libapache2-mod-php5 mysql-server
(比如 sudo apt-get install apache2 php5-mysql libapache2-mod-php5 mysql-server)
這些包全都可以Ubuntu 6.06 LTS (Dapper Drake)的 main軟件庫里找到。一旦LAMP安裝完畢后,你需要為mysql設置一個root密碼,然后根據(jù)你的web程序創(chuàng)建一個數(shù)據(jù)庫,用戶和密碼。就這些!
在Feisty里,ubuntu基本系統(tǒng)包含了 Tasksel。你可以用tasksel或者像上面描述的那樣來安裝LAMP。
sudo tasksel install lamp-server
See Tasksel
To also remove the debconf data, use the purge option when removing.To get rid of any configurations you may have made to apache, manuallyremove the /etc/apache2 directory once the packages have been removed.
刪除以下軟件包來刪除LAMP集:
apache2 apache2-mpm-prefork apache2-utils apache2.2-common libapache2-mod-php5 libapr1 libaprutil1 libdbd-mysql-perl libdbi-perl libmysqlclient15off libnet-daemon-perl libplrpc-perl libpq5 mysql-client-5.0 mysql-common mysql-server mysql-server-5.0 php5-common php5-mysql
可以用 purge參數(shù)來同時刪除配置日志。當你要完全刪除apache的配置,在你刪除以上軟件包後,你要手動刪除
/etc/apache2 這個文件夾。
用任何方式安裝Apache2網(wǎng)頁服務器:
apache2(例如 sudo apt-get install apache2)
If you get this error: apache2: Could not determine the server‘sfully qualified domain name, using 127.0.0.1 for ServerName then use atext editor such as "sudo nano" at the command line or "gksudo gedit"on the desktop to edit
如果你出現(xiàn)這個錯誤信息:apache2:不能找到完全有效的域名,現(xiàn)用127.0.0.1作為服務器域名,然後在命令行用文本編輯器比如“sudo nano”或者在桌面用“gksudo gedit”來編輯。
/etc/apache2/httpd.conf
然後在文件尾行加入
ServerName localhost
Apache2 has the concept of sites, which are separate configurationfiles that Apache2 will read. These are available in/etc/apache2/sites-available. By default, there is one site availablecalled default this is what you will see when you browse to http://localhost or http://127.0.0.1.You can have many different site configurations available, and activateonly those that you need. As an example, we want the default site to be/home/user/public_html/. To do this, we must create a new site and thenenable it in Apache2. To create a new site:
Now, we must deactivate the old site, and activate our new one.Ubuntu provides two small utilities that take care of this: a2ensite(apache2enable site) and a2dissite (apache2disable site).
sudo a2dissite default && sudo a2ensite mysite
Finally, we restart Apache2:
sudo /etc/init.d/apache2 restart
If you have not created /home/user/public_html/, you willreceive an warning message To test the new site, create a file in/home/user/public_html/:
echo ‘<b>Hello! It is working!</b>‘ > /home/user/public_html/index.html
Finally, browse to http://localhost/
apache2 有一站點的概念,這些站點分配配置文件供Apache2讀取。這些站點可以在 /etc/apache2/sites-available 找到。默認情況下,當你瀏覽[1] 或者 [2]時,只有一個命名為‘default’的有效站點可以顯示出來。你可以擁有許多不同的可用的站點配置,并且可以激活并啟用你需要的那個。舉個例子,我們想要把/home/user/public_html/ 作為默認站點,我們就必須創(chuàng)建一個新的站點并且在apache2里開啟它。新建一個站點:
現(xiàn)在,我們要使舊的站點無效,并且激活新的站點。Ubuntu提供了兩個小工具:a2ensite (apache2enable site) and a2dissite (apache2disable site).
sudo a2dissite default && sudo a2ensite mysite
最後,重啟 Apache2:
sudo /etc/init.d/apache2 restart
如果你沒有創(chuàng)建 /home/user/public_html/,在測試新站點的時候你會收到一個錯誤信息。
在 /home/user/public_html/ 里創(chuàng)建一個文件:
echo ‘<b>Hello! It is working!</b>‘ > /home/user/public_html/index.html
最後瀏覽到 [3]
用(任何方式)單獨安裝PHP5
php5(例如: sudo apt-get install php5)
如果你的系統(tǒng)里也安裝了PHP4,還需要安裝:
libapache2-mod-php5
Does your browser ask if you want to download the php file insteadof displaying it? If Apache is not actually parsing the php after yourestarted it, install libapache2-mod-php5. It is installed when youinstall the php5 package, but may have been removed inadvertently bypackages which need to run a different version of php. You may alsoneed to actually enable it, by doing sudo a2enmod php5 followed by sudo/etc/init.d/apache2 restart. Be sure to clear your browser‘s cachebefore testing your site again.
你的瀏覽器有沒有問你是否想要下載php而不運行它?如果Apache重啟後確實沒有解析php,安裝libapache2-mod-php5。這個包已經(jīng)在你安裝PHP5的時候就安裝了的,但會在你安裝了其他版本的PHP後被無意中刪除了。在執(zhí)行完
sudo /etc/init.d/apache2 restart後,你也許還要執(zhí)行“sudo a2enmod php5”來激活它。
在你測試你的站點之前請確認已經(jīng)清除掉瀏覽器的緩存。
用任何方式安裝PHP4:
php4
If PHP5 is present on your system, installing php4 will install thephp module for apache (version 1.3) and not apache2. To use php4 withapache2, install
如果你的系統(tǒng)已經(jīng)安裝了PHP5,在安裝php4時還要安裝apache(version1.3)的php模塊而不是apache2.若要在 apache2里使用php4,請安裝:
libapache2-mod-php4
你的瀏覽器有沒有問你是否想要下載php而不運行它?如果Apache重啟後確實沒有解析php,安裝libapache2-mod-php4。這個包已經(jīng)在你安裝PHP5的時候就安裝了的,但會在你安裝了其他版本的PHP後被無意中刪除了。在執(zhí)行完
sudo /etc/init.d/apache2 restart後,你也許還要執(zhí)行“sudo a2enmod php4”來激活它。
在你測試你的站點之前請確認已經(jīng)清除掉瀏覽器的緩存。
使用任何方式安裝:
mysql-server libapache2-mod-auth-mysql php5-mysq
First enable the universe repository since the packages are not in main
因為軟件包不在main源里,所以先激活 universe 源
我正在使用Ubuntu服務器版(命令行)
我正在用桌面版
使用任何方式安裝:
mysql-server libapache2-mod-auth-mysql php4-mysql
You may need to increase the memory limit that PHP imposes on ascript. Edit the /etc/php5/apache2/php.ini file and increase thememory_limit value.
你也許需要提升存儲限制來讓PHP利用script(小程序)。編輯/etc/php5/apache2/php.ini文件并且提升存儲限制的值。
Before you can access the database from other computers in yournetwork, you have to change its bind address. Note that this can be asecurity problem, because your database can be accessed by otherscomputers than your own. Skip this step if the applications whichrequire mysql are running on the same machine. type:
設置mysql協(xié)議地址
在你可以從其他電腦通過網(wǎng)絡訪問到數(shù)據(jù)庫之前,你必須更改它的協(xié)議地址。注意,這會是個安全問題,因為除了你之外的其他電腦也可以訪問到數(shù)據(jù)庫。如果需要用到的程序在同一個機器上運行,跳過這個步驟。輸入:
nano /etc/mysql/my.cnf
and change the line:
然後更改行
bind-address = localhost
to your own internal ip address e.g. 192.168.1.20
成你自己的內(nèi)部 ip 地址 比如: 192.168.1.20
bind-address = 192.168.1.20
If your ip address is dynamic you can also comment out thebind-address line and it will default to your current ip. If you try toconnect without changing the bind-address you will recieve a "Can notconnect to mysql error 10061".
如果你的是動態(tài)IP地址,你也可以把 blind-adress 這一行給注釋掉。它會默認為你當前的IP。如果你沒有更改bind-address的地址而嘗試鏈接,你會收到這樣一個錯誤信息:‘Can not connect to mysql error10061’。
在用控制臺訪問數(shù)據(jù)庫之前,你需要輸入:
mysql -u root
在mysql控制臺輸入:
mysql> SET PASSWORD FOR ‘root‘@‘localhost‘ = PASSWORD(‘yourpassword‘);
正確輸入mysql命令後會顯示:Query OK, 0 rows affected (0.00 sec) Mysql commands can span several lines
別忘了在你結束沒意思起來命令的時候在結尾加上分號。注意:如果你已經(jīng)設置了root密碼,你將需要用到:
mysql -u root -p
(你忘記了 mysql-root 密碼嗎?查看 MysqlPasswordReset。)
mysql> CREATE DATABASE database1;
創(chuàng)建一個擁有所有權限的新用戶(只用于檢測故障),在mysql prompt(字符控制臺)里輸入:
mysql> GRANT ALL PRIVILEGES ON *.* TO ‘yourusername‘@‘localhost‘ IDENTIFIED BY ‘yourpassword‘ WITH GRANT OPTION;
創(chuàng)建一個擁有少許權限的新用戶(用于在大部分web程序上工作),這個用戶只可以使用命名為“database1”的數(shù)據(jù)庫。在mysql prompt里輸入:
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON database1.* TO ‘yourusername‘@‘localhost‘ IDENTIFIED BY ‘yourpassword‘;
yourusername 和 yourpassword 可以是你喜歡的任何東西。database1是用戶可以訪問的一個數(shù)據(jù)庫名稱。localhost是你訪問數(shù)據(jù)庫的域名,為了可以讓所有的域名鏈接(或者特定的域名)到你的數(shù)據(jù)庫,你可以把它改成“%”(或者改成主機名和ip地址)。注意,這會是一個安全問題而且只能用于測試目的!推出mysql prompt,輸入:
mysql> \q
因為你已經(jīng)設置了root密碼,如果你要重新使用mysql(以mysql root身份),你需要使用:
mysql -u root -p
然後在prompt里輸入密碼。
Please, let‘s say something in which directories MySql stores the database information and how to configure a backup
請讓我們來說一下那些目錄可以用來儲存 數(shù)據(jù)庫信息和如何備份
有不止一種方式來設置mysql root密碼和創(chuàng)建數(shù)據(jù)庫。例如 mysqladmin可以這樣使用:
mysqladmin -u root -p password yourpassword
和
mysqladmin -u root -p create database1
mysqladmin 是LAMP默認安裝方式里提供的一個命令行工具。
通過Phpmyadmin 和mysql-admin這兩個圖形界面工具可以完成 所有的mysql任務,包括設置root密碼和創(chuàng)建可用的數(shù)據(jù)庫。在安裝其中一個或者兩個都安裝之前,先激活 universe 源
我正在使用Ubuntu服務器版(命令行)
我正在使用桌面版
用任何方式安裝:
phpmyadmin
‘If you get blowfish_secret error: Choose and set a phrase forcryptography in the file /etc/phpmyadmin/blowfish_secret.inc.php andcopy the line (not the php tags) into the file/etc/phpmyadmin/config.inc.php or you will receive an error.
如果你收到了短信密碼(或者密碼字,網(wǎng)上有兩個名字)錯誤信息,
在/etc/phpmyadmin/blowfish_secret.inc.php里用密碼學選擇并設置一個短語 ,并且把該行(沒有PHP後綴)復制到文檔/etc/phpmyadmin/config.inc.php里,不然你就會收到錯誤信息。
查看phpMyAdmin說明頁面: 如何源碼安裝 phpmyadm
在桌面版系統(tǒng)限制運行Mysql-admin。用any method 安裝
你真的應該閱讀 2.9.3. Securing the Initial MySQL Accountsfrom the MySQL Reference Manual.
如果你想使當前用戶成為PHP頁面的管理員。你需要編輯apache的配置文檔:
$ gksudo "gedit /etc/apache2/apache2.conf"
Search both the strings starting by "User" and "Group", and changethe names by the current username and groupname you are using. Thenyou‘ll need to restart Apache. (look at the next chapter concerningapache commands) Configuration options relating specifically to userwebsites (accessed through localhost/~username) are in/etc/apache2/mods-enabled/userdir.conf.
搜索所有以“User”和“Group”開頭的行,然後把名字更改成你當前的用戶名和你正在使用的組名。接著你需要重啟apache。(請看下一章,關于apache命令行)具體于用戶站點(通過localhost/~username訪問)相關的配置選項在:/etc/apache2/mods-enabled/userdir.conf。
In Dapper Drake, "extension=mysql.so" and "extension=mysqli.so" areenabled in the php.ini file out-of-the-box. However, sometimes php isnot looking for those files in the right directory. You have then tomove your files or modify the php.ini configuration.:
在Dapper Drake里,"extension=mysql.so" 和 "extension=mysqli.so"在php.ini文件里預設啟動的。但是,php有時候沒用通過正確目錄查查看這些文件。所以你必須移動你的文件或者修改php.ini配置:
locate the directory where the extension files are placed: locatemysql.so (change mysql.so in mysqli.so if you want to install themysqli functions) -then modify the php.ini file to indicate the rightplace for the extension directory:
找出擴展文件放置的所在目錄:找出 mysql.so(如果你想安裝mysqli functions,把 mysql.so改成 mysqli.so),然後修改php.ini文件以指示出擴展目錄正確的放置位置:
$ gksudo "gedit /etc/php4/apache2/php.ini"
或者你用的是php5:
$ gksudo "gedit /etc/php5/apache2/php.ini"
查看 “extension_dir”的屬性,然後把它設置成mysql(i).so(你找到的)的所在目錄:
extension_dir= "/usr/lib/php5/20051025/"
重啟apache,接著測試你的mysql(i)functions是否工作。
locate the directory where the extension files are placed: locatemysql.so (change mysql.so in mysqli.so if you want to install themysqli functions) Let‘s say that you found the file in‘/usr/lib/php5/20051025/‘ -then check in the php.ini file for theextension directory
找出擴展文件放置的所在目錄:找出 mysql.so(如果你想安裝mysqli functions,把 mysql.so改成mysqli.so),假設你找到的文件在 : ‘/usr/lib/php5/20051025/‘,作為擴展目錄把它登記到php.ini文件里。
$ gksudo "gedit /etc/php4/apache2/php.ini"
或者你用的是php5
$ gksudo "gedit /etc/php5/apache2/php.ini"
Look for the ‘extension_dir‘ property. It should be by default‘/usr/lib/php5/ext‘. If it‘s not, change it for this value. -Now createthe default directory for extensions:
查看(locate)‘extension_dir‘的屬性。它應該默認為 ‘/usr/lib/php5/ext’。如果不是,把它改成這個值。--現(xiàn)在為擴展文件創(chuàng)建一個默認的目錄:
$ sudo mkdir /usr/lib/php5/ext
Copy the extension file to the new directory:
--復制擴展文件到新建的目錄:
$ sudo cp /usr/lib/php5/20051025/mysql.so /usr/lib/php5/ext/mysql.so
Change the first path to the one you found with the locate function,and change mysql.so into mysqli.so if you want to use mysqli functions.-Restart apache (see below), and test if your mysql(i) functions areworking.
把第一個路徑改成你用 locate功能 找到的那個,如果你想要使用 mysqli功能,把mysql.so 改成 mysqli.so。--重啟apache(看下面),然後測試看你的 mysql(i)功能 是否在工作。
使用下列命令來運行 Apache:
$ sudo /usr/sbin/apache2ctl start
停止:
$ sudo /usr/sbin/apache2ctl stop
To test configuration changes, use :
測試配置的更改:
$ sudo /usr/sbin/apache2ctl configtest
最后,重啟使用:
$ sudo /usr/sbin/apache2ctl restart
You can access apache by typing 127.0.0.1 or http://localhost(by default it will be listening on port 80) in your browser addressbar. By default the directory for apache server pages is /var/www . Itneeds root access in order to put files in. A way to do it is juststarting the file browser as root in a terminal:
你可以通過在瀏覽器的地址欄里鍵入127.0.0.1 或者 http://localhost (默認監(jiān)視端口為80) 來訪問apache。apache服務器頁面的默認目錄是 /var/www 。為了把文件放進去,要用root用戶訪問。用root用戶登錄的一個方法:只要以root身份在終端里啟動文件瀏覽程序:
$ sudo nautilus
or if you want to make /var/www your own. (Use only fornon-production web servers - this is not the most secure way to dothings.)
或者如果你想要使 /var/www 成為你自己的(更改權限)。(只用于未出示的web服務器-這不是最安全的做法)
$ sudo chown -R $USER:$USER /var/www
檢查你的PHP裝置的狀態(tài):
$ gksudo "gedit /var/www/testphp.php"
然後插入這行:
<?php phpinfo(); ?>
用web瀏覽器在 http://yourserveripaddress/testphp.php 或者 http://localhost/testphp.php 訪問這個頁面。
If you just want to run your Apache install as a development serverand want to prevent it from listening for incoming connection attempts,this is easy to do.
如果你只是想讓apache以開發(fā)服務器運行并且阻止被企圖連接進來的連接所監(jiān)聽。這是容易實現(xiàn)的。
$ gksudo "gedit /etc/apache2/ports.conf"$ password:
修改 ports.conf是之包含:
Listen 127.0.0.1:80
保存文件,然后重啟Apache(看上文)。現(xiàn)在Apache想只服務于你的本地域名,http://127.0.0.1 或者 http://localhost。
有兩個方法來密碼保護一個特殊的目錄。推薦的方法有:
編輯 /etc/apache2/apache2.conf。(你需要用root用戶訪問來完成這個工作)。
另一個方法是:編輯目錄里的 a .htaccess 文件來實現(xiàn)保護。(你需要用root用戶訪問來完成這個工作)。
閱讀 EnablingUseOfApacheHtaccessFiles 提示:在很少的一些Ubuntu版本里,.htaccess文件是默認不工作的。.
閱讀EnablingUseOfApacheHtaccessFiles 來幫助啟用它們。
thumbnails
If you direct your web browser to a directory (rather than aspecific file), and there is no "index.html" file in that directory,Apache will generate an index file on-the-fly listing all the files andfolders in that directory. Each folder has a little icon of a foldernext to it. To put a thumbnail of that specific image (rather than thegeneric "image icon") next to each image file (.jpg, .png, etc.): ...todo: add instructions on how to do thumbnails here, perhaps usingApache::AutoIndex 0.08 or Apache::Album 0.95 ...
如果你讓你的瀏覽器訪問一個沒有“index.html”文件的目錄。Apache將會產(chǎn)生一個index文件,這個文件會即時把該目錄中所有的文件和文件夾列出來。每個文件夾都有一個相應小圖標在其旁邊。發(fā)送一個略圖當做特殊圖像(不是通常的“圖標”)放在每個圖像文件(.jpg,.png,等等)的旁邊:...要做的有:在這里,也許能附加使用 Apache::AutoIndex 0.08 或者 Apache::Album 0.95 指令來實現(xiàn) 略圖。
[4]Skype uses port 80 for incoming calls, and thus, may block Apache.
Skype 的來訪呼叫使用端口80,因此會于Apache沖突。解決的方法是改變其中一個程序的端口。通常端口81是空閑并且工作良好的。在Skype里打開 ‘目錄>選項’,然后點擊 ‘高級’ ,然后在來訪呼叫(incoming calls)的方框里寫入你選的端口。