點(diǎn)擊翻譯: | 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里安裝并設(shè)置一個(gè)LAMP(Linux-Apache-MySQL-PHP)服務(wù)。其中包括Apache2, PHP 4/5 和 MySQL 4.1/ 5.0。當(dāng)你從Ubuntu 6.06 (Dapper Drake)“ServerCD”里安裝系統(tǒng), 在Ubuntu安裝程序的開始時(shí)有一個(gè)讓你選擇安裝LAMP的選項(xiàng)。選擇後將安裝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.
有些應(yīng)用程序用PHP5工作,有些則需要PHP4。確定應(yīng)用程序安裝的PHP版本和對(duì)應(yīng)的apache2模塊。你不能把PHP4和php5同時(shí)安裝在同一個(gè)apache2實(shí)例中。安裝了其中的一個(gè)會(huì)刪除另一個(gè)。如果你都安了php4和php5,了解哪個(gè)版本適的apache2php模塊是你要用的。如果libapache2-mod-php5已經(jīng)安裝了,php4的軟件包應(yīng)該安裝libapache-mod-php4而不是libapache2-mod-php4。如果libapache2-mod-php5 軟件包沒有被安裝,則php4就要安apache2php模塊(libapache2-mod-php4)。看這個(gè)例子,大部分的web程序都用Apache2,php5和mysql5.0.如果你的web程序的文檔里沒有提到要特定的版本,就安裝它們。
如果你沒有用服務(wù)器版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軟件庫(kù)里找到。一旦LAMP安裝完畢后,你需要為mysql設(shè)置一個(gè)root密碼,然后根據(jù)你的web程序創(chuàng)建一個(gè)數(shù)據(jù)庫(kù),用戶和密碼。就這些!
在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ù)來同時(shí)刪除配置日志。當(dāng)你要完全刪除apache的配置,在你刪除以上軟件包後,你要手動(dòng)刪除
/etc/apache2 這個(gè)文件夾。
用任何方式安裝Apache2網(wǎng)頁(yè)服務(wù)器:
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)這個(gè)錯(cuò)誤信息:apache2:不能找到完全有效的域名,現(xiàn)用127.0.0.1作為服務(wù)器域名,然後在命令行用文本編輯器比如“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 有一站點(diǎn)的概念,這些站點(diǎn)分配配置文件供Apache2讀取。這些站點(diǎn)可以在 /etc/apache2/sites-available 找到。默認(rèn)情況下,當(dāng)你瀏覽[1] 或者 [2]時(shí),只有一個(gè)命名為‘default’的有效站點(diǎn)可以顯示出來。你可以擁有許多不同的可用的站點(diǎn)配置,并且可以激活并啟用你需要的那個(gè)。舉個(gè)例子,我們想要把/home/user/public_html/ 作為默認(rèn)站點(diǎn),我們就必須創(chuàng)建一個(gè)新的站點(diǎn)并且在apache2里開啟它。新建一個(gè)站點(diǎn):
現(xiàn)在,我們要使舊的站點(diǎn)無效,并且激活新的站點(diǎn)。Ubuntu提供了兩個(gè)小工具: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/,在測(cè)試新站點(diǎn)的時(shí)候你會(huì)收到一個(gè)錯(cuò)誤信息。
在 /home/user/public_html/ 里創(chuàng)建一個(gè)文件:
echo ‘<b>Hello! It is working!</b>‘ > /home/user/public_html/index.html
最後瀏覽到 [3]
用(任何方式)單獨(dú)安裝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而不運(yùn)行它?如果Apache重啟後確實(shí)沒有解析php,安裝libapache2-mod-php5。這個(gè)包已經(jīng)在你安裝PHP5的時(shí)候就安裝了的,但會(huì)在你安裝了其他版本的PHP後被無意中刪除了。在執(zhí)行完
sudo /etc/init.d/apache2 restart後,你也許還要執(zhí)行“sudo a2enmod php5”來激活它。
在你測(cè)試你的站點(diǎn)之前請(qǐng)確認(rèn)已經(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時(shí)還要安裝apache(version1.3)的php模塊而不是apache2.若要在 apache2里使用php4,請(qǐng)安裝:
libapache2-mod-php4
你的瀏覽器有沒有問你是否想要下載php而不運(yùn)行它?如果Apache重啟後確實(shí)沒有解析php,安裝libapache2-mod-php4。這個(gè)包已經(jīng)在你安裝PHP5的時(shí)候就安裝了的,但會(huì)在你安裝了其他版本的PHP後被無意中刪除了。在執(zhí)行完
sudo /etc/init.d/apache2 restart後,你也許還要執(zhí)行“sudo a2enmod php4”來激活它。
在你測(cè)試你的站點(diǎn)之前請(qǐng)確認(rèn)已經(jīng)清除掉瀏覽器的緩存。
使用任何方式安裝:
mysql-server libapache2-mod-auth-mysql php5-mysq
First enable the universe repository since the packages are not in main
因?yàn)檐浖辉趍ain源里,所以先激活 universe 源
我正在使用Ubuntu服務(wù)器版(命令行)
我正在用桌面版
使用任何方式安裝:
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.
你也許需要提升存儲(chǔ)限制來讓PHP利用script(小程序)。編輯/etc/php5/apache2/php.ini文件并且提升存儲(chǔ)限制的值。
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:
設(shè)置mysql協(xié)議地址
在你可以從其他電腦通過網(wǎng)絡(luò)訪問到數(shù)據(jù)庫(kù)之前,你必須更改它的協(xié)議地址。注意,這會(huì)是個(gè)安全問題,因?yàn)槌四阒獾钠渌娔X也可以訪問到數(shù)據(jù)庫(kù)。如果需要用到的程序在同一個(gè)機(jī)器上運(yùn)行,跳過這個(gè)步驟。輸入:
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".
如果你的是動(dòng)態(tài)IP地址,你也可以把 blind-adress 這一行給注釋掉。它會(huì)默認(rèn)為你當(dāng)前的IP。如果你沒有更改bind-address的地址而嘗試鏈接,你會(huì)收到這樣一個(gè)錯(cuò)誤信息:‘Can not connect to mysql error10061’。
在用控制臺(tái)訪問數(shù)據(jù)庫(kù)之前,你需要輸入:
mysql -u root
在mysql控制臺(tái)輸入:
mysql> SET PASSWORD FOR ‘root‘@‘localhost‘ = PASSWORD(‘yourpassword‘);
正確輸入mysql命令後會(huì)顯示:Query OK, 0 rows affected (0.00 sec) Mysql commands can span several lines
別忘了在你結(jié)束沒意思起來命令的時(shí)候在結(jié)尾加上分號(hào)。注意:如果你已經(jīng)設(shè)置了root密碼,你將需要用到:
mysql -u root -p
(你忘記了 mysql-root 密碼嗎?查看 MysqlPasswordReset。)
mysql> CREATE DATABASE database1;
創(chuàng)建一個(gè)擁有所有權(quán)限的新用戶(只用于檢測(cè)故障),在mysql prompt(字符控制臺(tái))里輸入:
mysql> GRANT ALL PRIVILEGES ON *.* TO ‘yourusername‘@‘localhost‘ IDENTIFIED BY ‘yourpassword‘ WITH GRANT OPTION;
創(chuàng)建一個(gè)擁有少許權(quán)限的新用戶(用于在大部分web程序上工作),這個(gè)用戶只可以使用命名為“database1”的數(shù)據(jù)庫(kù)。在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是用戶可以訪問的一個(gè)數(shù)據(jù)庫(kù)名稱。localhost是你訪問數(shù)據(jù)庫(kù)的域名,為了可以讓所有的域名鏈接(或者特定的域名)到你的數(shù)據(jù)庫(kù),你可以把它改成“%”(或者改成主機(jī)名和ip地址)。注意,這會(huì)是一個(gè)安全問題而且只能用于測(cè)試目的!推出mysql prompt,輸入:
mysql> \q
因?yàn)槟阋呀?jīng)設(shè)置了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
請(qǐng)讓我們來說一下那些目錄可以用來儲(chǔ)存 數(shù)據(jù)庫(kù)信息和如何備份
有不止一種方式來設(shè)置mysql root密碼和創(chuàng)建數(shù)據(jù)庫(kù)。例如 mysqladmin可以這樣使用:
mysqladmin -u root -p password yourpassword
和
mysqladmin -u root -p create database1
mysqladmin 是LAMP默認(rèn)安裝方式里提供的一個(gè)命令行工具。
通過Phpmyadmin 和mysql-admin這兩個(gè)圖形界面工具可以完成 所有的mysql任務(wù),包括設(shè)置root密碼和創(chuàng)建可用的數(shù)據(jù)庫(kù)。在安裝其中一個(gè)或者兩個(gè)都安裝之前,先激活 universe 源
我正在使用Ubuntu服務(wù)器版(命令行)
我正在使用桌面版
用任何方式安裝:
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)上有兩個(gè)名字)錯(cuò)誤信息,
在/etc/phpmyadmin/blowfish_secret.inc.php里用密碼學(xué)選擇并設(shè)置一個(gè)短語(yǔ) ,并且把該行(沒有PHP後綴)復(fù)制到文檔/etc/phpmyadmin/config.inc.php里,不然你就會(huì)收到錯(cuò)誤信息。
查看phpMyAdmin說明頁(yè)面: 如何源碼安裝 phpmyadm
在桌面版系統(tǒng)限制運(yùn)行Mysql-admin。用any method 安裝
你真的應(yīng)該閱讀 2.9.3. Securing the Initial MySQL Accountsfrom the MySQL Reference Manual.
如果你想使當(dāng)前用戶成為PHP頁(yè)面的管理員。你需要編輯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”開頭的行,然後把名字更改成你當(dāng)前的用戶名和你正在使用的組名。接著你需要重啟apache。(請(qǐng)看下一章,關(guān)于apache命令行)具體于用戶站點(diǎn)(通過localhost/~username訪問)相關(guān)的配置選項(xiàng)在:/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文件里預(yù)設(shè)啟動(dòng)的。但是,php有時(shí)候沒用通過正確目錄查查看這些文件。所以你必須移動(dòng)你的文件或者修改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:
找出擴(kuò)展文件放置的所在目錄:找出 mysql.so(如果你想安裝mysqli functions,把 mysql.so改成 mysqli.so),然後修改php.ini文件以指示出擴(kuò)展目錄正確的放置位置:
$ gksudo "gedit /etc/php4/apache2/php.ini"
或者你用的是php5:
$ gksudo "gedit /etc/php5/apache2/php.ini"
查看 “extension_dir”的屬性,然後把它設(shè)置成mysql(i).so(你找到的)的所在目錄:
extension_dir= "/usr/lib/php5/20051025/"
重啟apache,接著測(cè)試你的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
找出擴(kuò)展文件放置的所在目錄:找出 mysql.so(如果你想安裝mysqli functions,把 mysql.so改成mysqli.so),假設(shè)你找到的文件在 : ‘/usr/lib/php5/20051025/‘,作為擴(kuò)展目錄把它登記到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‘的屬性。它應(yīng)該默認(rèn)為 ‘/usr/lib/php5/ext’。如果不是,把它改成這個(gè)值。--現(xiàn)在為擴(kuò)展文件創(chuàng)建一個(gè)默認(rèn)的目錄:
$ sudo mkdir /usr/lib/php5/ext
Copy the extension file to the new directory:
--復(fù)制擴(kuò)展文件到新建的目錄:
$ 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.
把第一個(gè)路徑改成你用 locate功能 找到的那個(gè),如果你想要使用 mysqli功能,把mysql.so 改成 mysqli.so。--重啟apache(看下面),然後測(cè)試看你的 mysql(i)功能 是否在工作。
使用下列命令來運(yùn)行 Apache:
$ sudo /usr/sbin/apache2ctl start
停止:
$ sudo /usr/sbin/apache2ctl stop
To test configuration changes, use :
測(cè)試配置的更改:
$ 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 (默認(rèn)監(jiān)視端口為80) 來訪問apache。apache服務(wù)器頁(yè)面的默認(rèn)目錄是 /var/www 。為了把文件放進(jìn)去,要用root用戶訪問。用root用戶登錄的一個(gè)方法:只要以root身份在終端里啟動(dòng)文件瀏覽程序:
$ 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 成為你自己的(更改權(quán)限)。(只用于未出示的web服務(wù)器-這不是最安全的做法)
$ 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 訪問這個(gè)頁(yè)面。
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ā)服務(wù)器運(yùn)行并且阻止被企圖連接進(jìn)來的連接所監(jiān)聽。這是容易實(shí)現(xiàn)的。
$ gksudo "gedit /etc/apache2/ports.conf"$ password:
修改 ports.conf是之包含:
Listen 127.0.0.1:80
保存文件,然后重啟Apache(看上文)?,F(xiàn)在Apache想只服務(wù)于你的本地域名,http://127.0.0.1 或者 http://localhost。
有兩個(gè)方法來密碼保護(hù)一個(gè)特殊的目錄。推薦的方法有:
編輯 /etc/apache2/apache2.conf。(你需要用root用戶訪問來完成這個(gè)工作)。
另一個(gè)方法是:編輯目錄里的 a .htaccess 文件來實(shí)現(xiàn)保護(hù)。(你需要用root用戶訪問來完成這個(gè)工作)。
閱讀 EnablingUseOfApacheHtaccessFiles 提示:在很少的一些Ubuntu版本里,.htaccess文件是默認(rèn)不工作的。.
閱讀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 ...
如果你讓你的瀏覽器訪問一個(gè)沒有“index.html”文件的目錄。Apache將會(huì)產(chǎn)生一個(gè)index文件,這個(gè)文件會(huì)即時(shí)把該目錄中所有的文件和文件夾列出來。每個(gè)文件夾都有一個(gè)相應(yīng)小圖標(biāo)在其旁邊。發(fā)送一個(gè)略圖當(dāng)做特殊圖像(不是通常的“圖標(biāo)”)放在每個(gè)圖像文件(.jpg,.png,等等)的旁邊:...要做的有:在這里,也許能附加使用 Apache::AutoIndex 0.08 或者 Apache::Album 0.95 指令來實(shí)現(xiàn) 略圖。
[4]Skype uses port 80 for incoming calls, and thus, may block Apache.
Skype 的來訪呼叫使用端口80,因此會(huì)于Apache沖突。解決的方法是改變其中一個(gè)程序的端口。通常端口81是空閑并且工作良好的。在Skype里打開 ‘目錄>選項(xiàng)’,然后點(diǎn)擊 ‘高級(jí)’ ,然后在來訪呼叫(incoming calls)的方框里寫入你選的端口。
聯(lián)系客服