特殊:Badtitle/NS100:ApacheMySQLPHP:修订间差异
小无编辑摘要 |
小无编辑摘要 |
||
第2行: | 第2行: | ||
{{Languages|UbuntuHelp:ApacheMySQLPHP}} | {{Languages|UbuntuHelp:ApacheMySQLPHP}} | ||
Parent page: [[UbuntuHelp:Programming| Programming Applications]] | Parent page: [[UbuntuHelp:Programming| Programming Applications]] | ||
This is to help people setup and install a [http://en.wikipedia.org/wiki/LAMP_%28software_bundle%29 LAMP] ('''L'''inux-'''A'''pache-'''M'''ySQL-'''P'''HP) server in Ubuntu, including Apache 2, PHP 4 or 5, and MySQL 4.1 or 5.0. | This is to help people setup and install a [http://en.wikipedia.org/wiki/LAMP_%28software_bundle%29 LAMP] ('''L'''inux-'''A'''pache-'''M'''ySQL-'''P'''HP) server in Ubuntu, including Apache 2, PHP 4 or 5, and MySQL 4.1 or 5.0. | ||
When installing from the Ubuntu 6.06 (Dapper Drake) "Server cd", you have the option of choosing to install a LAMP setup at the inital Ubuntu installation screen. That will install apache2, php5 and mysql 5.0. | When installing from the Ubuntu 6.06 (Dapper Drake) "Server cd", you have the option of choosing to install a LAMP setup at the inital Ubuntu installation screen. That will install apache2, php5 and mysql 5.0. | ||
=== Check Requirements === | === Check Requirements === | ||
Some applications require php4 while others will work with php5. Be sure to install the version of php and the corresponding apache2 module for it. You cannot have both php4 and php5 modules running on the same instance of apache2 at the same time. Installing one may remove the other. | Some applications require php4 while others will work with php5. Be sure to install the version of php and the corresponding apache2 module for it. You cannot have both php4 and php5 modules running on the same instance of apache2 at the same time. Installing one may remove the other. | ||
''If you have both php4 and php5 installed, be aware of which version of the apache2 php module you have. If libapache2-mod-php5 is already installed, the php4 package will install libapache-mod-php4 and not libapache'''2'''-mod-php4 package.'' | ''If you have both php4 and php5 installed, be aware of which version of the apache2 php module you have. If libapache2-mod-php5 is already installed, the php4 package will install libapache-mod-php4 and not libapache'''2'''-mod-php4 package.'' | ||
''If libapache2-mod-php5 is not installed, installing php4 will install the apache2 php module (libapache2-mod-php4). See this [[UbuntuHelp:ApacheMySQLPHP/AptPhp4Output| example]].'' | ''If libapache2-mod-php5 is not installed, installing php4 will install the apache2 php module (libapache2-mod-php4). See this [[UbuntuHelp:ApacheMySQLPHP/AptPhp4Output| example]].'' | ||
Most web applications will use Apache2, php5 and mysql5.0. If no specific versions are mentioned in your web application's documentation, use those. | Most web applications will use Apache2, php5 and mysql5.0. If no specific versions are mentioned in your web application's documentation, use those. | ||
=== To install the default LAMP stack in Ubuntu 6.06 LTS (Dapper Drake) === | === To install the default LAMP stack in Ubuntu 6.06 LTS (Dapper Drake) === | ||
If you did not use the LAMP installer option from the server cd but want to install those same packages without having to reinstall your operating system, use [[UbuntuHelp:InstallingSoftware| any method]] to install the following packages | If you did not use the LAMP installer option from the server cd but want to install those same packages without having to reinstall your operating system, use [[UbuntuHelp:InstallingSoftware| any method]] to install the following packages | ||
<pre><nowiki> | <pre><nowiki> | ||
apache2 php5-mysql libapache2-mod-php5 mysql-server | apache2 php5-mysql libapache2-mod-php5 mysql-server | ||
</nowiki></pre> | </nowiki></pre> | ||
All of those packages are in the Ubuntu 6.06 LTS (Dapper Drake) '''main''' repository. Once LAMP is installed, you need to set a mysql root password and then, depending on your web application, create a database, user and password. That's it! | All of those packages are in the Ubuntu 6.06 LTS (Dapper Drake) '''main''' repository. Once LAMP is installed, you need to set a mysql root password and then, depending on your web application, create a database, user and password. That's it! | ||
=== To install the default LAMP stack in Ubuntu 7.04 (Feisty Fawn) === | === To install the default LAMP stack in Ubuntu 7.04 (Feisty Fawn) === | ||
In Feisty, the Ubuntu base system includes Tasksel. You can either install LAMP using tasksel or install the LAMP packages as detailed above. | In Feisty, the Ubuntu base system includes Tasksel. You can either install LAMP using tasksel or install the LAMP packages as detailed above. | ||
<pre><nowiki> | <pre><nowiki> | ||
sudo tasksel install lamp-server | sudo tasksel install lamp-server | ||
</nowiki></pre> | </nowiki></pre> | ||
See [[UbuntuHelp:Tasksel| Tasksel]] | See [[UbuntuHelp:Tasksel| Tasksel]] | ||
=== Starting over, How to remove the LAMP stack === | === Starting over, How to remove the LAMP stack === | ||
To remove the LAMP stack remove the following packages: | To remove the LAMP stack remove the following packages: | ||
<pre><nowiki> | <pre><nowiki> | ||
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 | 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 | ||
</nowiki></pre> | </nowiki></pre> | ||
To also remove the debconf data, use the purge option when removing. To get rid of any configurations you may have made to apache, manually remove the /etc/apache2 directory once the packages have been removed. | To also remove the debconf data, use the purge option when removing. To get rid of any configurations you may have made to apache, manually remove the /etc/apache2 directory once the packages have been removed. | ||
=== Installing Apache 2 === | === Installing Apache 2 === | ||
To only install the apache2 webserver, use [[UbuntuHelp:InstallingSoftware| any method]] to install | To only install the apache2 webserver, use [[UbuntuHelp:InstallingSoftware| any method]] to install | ||
<pre><nowiki> | <pre><nowiki> | ||
apache2 | apache2 | ||
</nowiki></pre> | </nowiki></pre> | ||
==== Troubleshooting ==== | ==== Troubleshooting ==== | ||
If you get this error: | If you get this error: | ||
''apache2: Could not determine the server's fully qualified domain name, using 127.0.0.1 for ServerName'' | ''apache2: Could not determine the server's fully qualified domain name, using 127.0.0.1 for ServerName'' | ||
then use a text editor such as "sudo nano" at the command line or "gksudo gedit" on the desktop to edit | then use a text editor such as "sudo nano" at the command line or "gksudo gedit" on the desktop to edit | ||
<pre><nowiki> | <pre><nowiki> | ||
/etc/apache2/httpd.conf | /etc/apache2/httpd.conf | ||
</nowiki></pre> | </nowiki></pre> | ||
and add | and add | ||
<pre><nowiki> | <pre><nowiki> | ||
ServerName localhost | ServerName localhost | ||
</nowiki></pre> | </nowiki></pre> | ||
at the end of the file. | at the end of the file. | ||
==== Virtual Hosts ==== | ==== Virtual Hosts ==== | ||
Apache2 has the concept of sites, which are separate configuration files that Apache2 will read. These are available in <code><nowiki>/etc/apache2/sites-available</nowiki></code>. By default, there is one site available called ''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 activate only those that you need. | Apache2 has the concept of sites, which are separate configuration files that Apache2 will read. These are available in <code><nowiki>/etc/apache2/sites-available</nowiki></code>. By default, there is one site available called ''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 activate only those that you need. | ||
As an example, we want the default site to be <code><nowiki>/home/user/public_html/</nowiki></code>. To do this, we must create a new site and then enable it in Apache2. | As an example, we want the default site to be <code><nowiki>/home/user/public_html/</nowiki></code>. To do this, we must create a new site and then enable it in Apache2. | ||
To create a new site: | To create a new site: | ||
* Copy the default website as a starting point. <code><nowiki>sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/mysite </nowiki></code> | * Copy the default website as a starting point. <code><nowiki>sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/mysite </nowiki></code> | ||
* Edit the new configuration file in a text editor "sudo nano" on the command line or "gksudo gedit", for example: <code><nowiki>gksudo gedit /etc/apache2/sites-available/mysite</nowiki></code> | * Edit the new configuration file in a text editor "sudo nano" on the command line or "gksudo gedit", for example: <code><nowiki>gksudo gedit /etc/apache2/sites-available/mysite</nowiki></code> | ||
第89行: | 第54行: | ||
* ''You can also set separate logs for each site. To do this, change the <code><nowiki>ErrorLog</nowiki></code> and <code><nowiki>CustomLog</nowiki></code> directives. This is optional, but handy if you have many sites'' | * ''You can also set separate logs for each site. To do this, change the <code><nowiki>ErrorLog</nowiki></code> and <code><nowiki>CustomLog</nowiki></code> directives. This is optional, but handy if you have many sites'' | ||
* Save the file | * Save the file | ||
Now, we must deactivate the old site, and activate our new one. Ubuntu provides two small utilities that take care of this: a2ensite ('''a'''pache'''2en'''able '''site''') and a2dissite ('''a'''pache'''2dis'''able '''site'''). | Now, we must deactivate the old site, and activate our new one. Ubuntu provides two small utilities that take care of this: a2ensite ('''a'''pache'''2en'''able '''site''') and a2dissite ('''a'''pache'''2dis'''able '''site'''). | ||
<pre><nowiki> | <pre><nowiki> | ||
sudo a2dissite default && sudo a2ensite mysite | sudo a2dissite default && sudo a2ensite mysite | ||
</nowiki></pre> | </nowiki></pre> | ||
Finally, we restart Apache2: | Finally, we restart Apache2: | ||
<pre><nowiki> | <pre><nowiki> | ||
sudo /etc/init.d/apache2 restart | sudo /etc/init.d/apache2 restart | ||
</nowiki></pre> | </nowiki></pre> | ||
''If you have not created <code><nowiki>/home/user/public_html/</nowiki></code>, you will receive an warning message'' | ''If you have not created <code><nowiki>/home/user/public_html/</nowiki></code>, you will receive an warning message'' | ||
To test the new site, create a file in <code><nowiki>/home/user/public_html/</nowiki></code>: | To test the new site, create a file in <code><nowiki>/home/user/public_html/</nowiki></code>: | ||
<pre><nowiki> | <pre><nowiki> | ||
echo '<b>Hello! It is working!</b>' > /home/user/public_html/index.html | echo '<b>Hello! It is working!</b>' > /home/user/public_html/index.html | ||
</nowiki></pre> | </nowiki></pre> | ||
Finally, browse to http://localhost/ | Finally, browse to http://localhost/ | ||
=== Installing PHP 5 === | === Installing PHP 5 === | ||
To only install PHP5. use [[UbuntuHelp:InstallingSoftware| any method]] to install | To only install PHP5. use [[UbuntuHelp:InstallingSoftware| any method]] to install | ||
<pre><nowiki> | <pre><nowiki> | ||
php5 | php5 | ||
</nowiki></pre> | </nowiki></pre> | ||
If PHP4 is present on your system, also install | If PHP4 is present on your system, also install | ||
<pre><nowiki> | <pre><nowiki> | ||
libapache2-mod-php5 | libapache2-mod-php5 | ||
</nowiki></pre> | </nowiki></pre> | ||
==== Troubleshooting ==== | ==== Troubleshooting ==== | ||
Does your browser ask if you want to '''download the php''' file instead of displaying it? If Apache is not actually parsing the php after you restarted it, install <code><nowiki>libapache2-mod-php5</nowiki></code>. It is installed when you install the <code><nowiki>php5</nowiki></code> package, but may have been removed inadvertently by packages which need to run a different version of php. You may also need to actually enable it, by doing <code><nowiki>sudo a2enmod php5</nowiki></code> followed by <code><nowiki>sudo /etc/init.d/apache2 restart</nowiki></code>. Be sure to clear your browser's cache before testing your site again. | Does your browser ask if you want to '''download the php''' file instead of displaying it? If Apache is not actually parsing the php after you restarted it, install <code><nowiki>libapache2-mod-php5</nowiki></code>. It is installed when you install the <code><nowiki>php5</nowiki></code> package, but may have been removed inadvertently by packages which need to run a different version of php. You may also need to actually enable it, by doing <code><nowiki>sudo a2enmod php5</nowiki></code> followed by <code><nowiki>sudo /etc/init.d/apache2 restart</nowiki></code>. Be sure to clear your browser's cache before testing your site again. | ||
=== Installing PHP 4 === | === Installing PHP 4 === | ||
To install PHP4, Use [[UbuntuHelp:InstallingSoftware| any method]] to install | To install PHP4, Use [[UbuntuHelp:InstallingSoftware| any method]] to install | ||
<pre><nowiki> | <pre><nowiki> | ||
php4 | php4 | ||
</nowiki></pre> | </nowiki></pre> | ||
If PHP5 is present on your system, installing php4 will install the php module for apache (version 1.3) and not apache2. To use php4 with apache2, install | If PHP5 is present on your system, installing php4 will install the php module for apache (version 1.3) and not apache2. To use php4 with apache2, install | ||
<pre><nowiki> | <pre><nowiki> | ||
libapache2-mod-php4 | libapache2-mod-php4 | ||
</nowiki></pre> | </nowiki></pre> | ||
==== Troubleshooting ==== | ==== Troubleshooting ==== | ||
Does your browser ask if you want to '''download the php''' file instead of displaying it? If Apache is not actually parsing the php after you restarted it, install <code><nowiki>libapache2-mod-php4</nowiki></code>. It is installed when you install the <code><nowiki>php4</nowiki></code> package, but may have been removed inadvertently by packages which need to run a different version of php. You may also need to actually enable it, by doing <code><nowiki>sudo a2enmod php4</nowiki></code> followed by <code><nowiki>sudo /etc/init.d/apache2 restart</nowiki></code>. Be sure to clear your browser's cache before testing your site again. | Does your browser ask if you want to '''download the php''' file instead of displaying it? If Apache is not actually parsing the php after you restarted it, install <code><nowiki>libapache2-mod-php4</nowiki></code>. It is installed when you install the <code><nowiki>php4</nowiki></code> package, but may have been removed inadvertently by packages which need to run a different version of php. You may also need to actually enable it, by doing <code><nowiki>sudo a2enmod php4</nowiki></code> followed by <code><nowiki>sudo /etc/init.d/apache2 restart</nowiki></code>. Be sure to clear your browser's cache before testing your site again. | ||
=== Installing MYSQL with PHP 5 === | === Installing MYSQL with PHP 5 === | ||
Use [[UbuntuHelp:InstallingSoftware| any method]] to install | Use [[UbuntuHelp:InstallingSoftware| any method]] to install | ||
<pre><nowiki> | <pre><nowiki> | ||
mysql-server libapache2-mod-auth-mysql php5-mysql | mysql-server libapache2-mod-auth-mysql php5-mysql | ||
</nowiki></pre> | </nowiki></pre> | ||
=== Installing MYSQL with PHP 4 === | === Installing MYSQL with PHP 4 === | ||
First enable the universe repository since the packages are not in ''main'' | First enable the universe repository since the packages are not in ''main'' | ||
* [[UbuntuHelp:Repositories/CommandLine| I am using Ubuntu server (command line)]] | * [[UbuntuHelp:Repositories/CommandLine| I am using Ubuntu server (command line)]] | ||
* [[UbuntuHelp:AddingRepositoriesHowto| I am using a desktop]] | * [[UbuntuHelp:AddingRepositoriesHowto| I am using a desktop]] | ||
Use [[UbuntuHelp:InstallingSoftware| any method]] to install | Use [[UbuntuHelp:InstallingSoftware| any method]] to install | ||
<pre><nowiki> | <pre><nowiki> | ||
mysql-server libapache2-mod-auth-mysql php4-mysql | mysql-server libapache2-mod-auth-mysql php4-mysql | ||
</nowiki></pre> | </nowiki></pre> | ||
=== After installing PHP === | === After installing PHP === | ||
You may need to increase the memory limit that PHP imposes on a script. Edit the /etc/php5/apache2/php.ini file and increase the ''memory_limit'' value. | You may need to increase the memory limit that PHP imposes on a script. Edit the /etc/php5/apache2/php.ini file and increase the ''memory_limit'' value. | ||
=== After installing MySQL === | === After installing MySQL === | ||
==== Set mysql bind address ==== | ==== Set mysql bind address ==== | ||
Before you can access the database '''from other''' computers in your network, you have to change its bind address. | Before you can access the database '''from other''' computers in your network, you have to change its bind address. | ||
'''Note that this can be a security problem, because your database can be accessed by others computers than your own. | '''Note that this can be a security problem, because your database can be accessed by others computers than your own. | ||
Skip this step if the applications which require mysql are running on the same machine.''' | Skip this step if the applications which require mysql are running on the same machine.''' | ||
type: | type: | ||
<pre><nowiki> | <pre><nowiki> | ||
nano /etc/mysql/my.cnf | nano /etc/mysql/my.cnf | ||
</nowiki></pre> | </nowiki></pre> | ||
and change the line: | and change the line: | ||
<pre><nowiki> | <pre><nowiki> | ||
第198行: | 第122行: | ||
bind-address = 192.168.1.20 | bind-address = 192.168.1.20 | ||
</nowiki></pre> | </nowiki></pre> | ||
If your ip address is dynamic you can also comment out the bind-address line and it will default to your current ip. | If your ip address is dynamic you can also comment out the bind-address line and it will default to your current ip. | ||
If you try to connect without changing the bind-address you will recieve a "Can not connect to mysql error 10061". | If you try to connect without changing the bind-address you will recieve a "Can not connect to mysql error 10061". | ||
==== Set mysql root password ==== | ==== Set mysql root password ==== | ||
Before accessing the database by console you need to type: | Before accessing the database by console you need to type: | ||
<pre><nowiki> | <pre><nowiki> | ||
mysql -u root | mysql -u root | ||
</nowiki></pre> | </nowiki></pre> | ||
At the mysql console type: | At the mysql console type: | ||
<pre><nowiki> | <pre><nowiki> | ||
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('yourpassword'); | mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('yourpassword'); | ||
</nowiki></pre> | </nowiki></pre> | ||
A successful mysql command will show: | A successful mysql command will show: | ||
''Query OK, 0 rows affected (0.00 sec) '' | ''Query OK, 0 rows affected (0.00 sec) '' | ||
Mysql commands can span several lines. Do not forget to end your mysql command with a semicolon. | Mysql commands can span several lines. Do not forget to end your mysql command with a semicolon. | ||
'''Note:''' If you have already set a password for the mysql root, you will need to use: | '''Note:''' If you have already set a password for the mysql root, you will need to use: | ||
<pre><nowiki> | <pre><nowiki> | ||
第226行: | 第141行: | ||
</nowiki></pre> | </nowiki></pre> | ||
(Did you forget the mysql-root password? See MysqlPasswordReset.) | (Did you forget the mysql-root password? See MysqlPasswordReset.) | ||
==== Create a mysql database ==== | ==== Create a mysql database ==== | ||
<pre><nowiki> | <pre><nowiki> | ||
mysql> CREATE DATABASE database1; | mysql> CREATE DATABASE database1; | ||
</nowiki></pre> | </nowiki></pre> | ||
==== Create a mysql user ==== | ==== Create a mysql user ==== | ||
For creating a new user with all privileges (use only for troubleshooting), at mysql prompt type: | For creating a new user with all privileges (use only for troubleshooting), at mysql prompt type: | ||
<pre><nowiki>mysql> GRANT ALL PRIVILEGES ON *.* TO 'yourusername'@'localhost' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION; | <pre><nowiki>mysql> GRANT ALL PRIVILEGES ON *.* TO 'yourusername'@'localhost' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION; | ||
</nowiki></pre> | </nowiki></pre> | ||
For creating a new user with fewer privileges (should work for most web applications) which can only use the database named "database1", at mysql prompt type: | For creating a new user with fewer privileges (should work for most web applications) which can only use the database named "database1", at mysql prompt type: | ||
<pre><nowiki> | <pre><nowiki> | ||
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON database1.* TO 'yourusername'@'localhost' IDENTIFIED BY 'yourpassword'; | mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON database1.* TO 'yourusername'@'localhost' IDENTIFIED BY 'yourpassword'; | ||
</nowiki></pre> | </nowiki></pre> | ||
''yourusername'' and ''yourpassword'' can be anything you like. ''database1'' is the name of the database the user gets access to. ''localhost'' is the location which gets access to your database. You can change it to '%' (or to hostnames or ip addresses) to allow connections from every location (or only from specific locations) to the database. '''Note, that this can be a security problem and should only be used for testing purposes!''' | ''yourusername'' and ''yourpassword'' can be anything you like. ''database1'' is the name of the database the user gets access to. ''localhost'' is the location which gets access to your database. You can change it to '%' (or to hostnames or ip addresses) to allow connections from every location (or only from specific locations) to the database. '''Note, that this can be a security problem and should only be used for testing purposes!''' | ||
To exit the mysql prompt type: | To exit the mysql prompt type: | ||
<pre><nowiki> | <pre><nowiki> | ||
mysql> \q | mysql> \q | ||
</nowiki></pre> | </nowiki></pre> | ||
Since the mysql root password is now set, if you need to use mysql again (as the mysql root), you will need to use: | Since the mysql root password is now set, if you need to use mysql again (as the mysql root), you will need to use: | ||
<pre><nowiki> | <pre><nowiki> | ||
mysql -u root -p | mysql -u root -p | ||
</nowiki></pre> | </nowiki></pre> | ||
and then enter the password at the prompt. | and then enter the password at the prompt. | ||
==== Backup-Settings ==== | ==== Backup-Settings ==== | ||
Please, let's say something in which directories MySql stores the database information and how to configure a backup | Please, let's say something in which directories MySql stores the database information and how to configure a backup | ||
==== Alternatively ==== | ==== Alternatively ==== | ||
There is more than just one way to set the mysql root password and create a database. For example '''mysqladmin''' can be used: | There is more than just one way to set the mysql root password and create a database. For example '''mysqladmin''' can be used: | ||
<pre><nowiki> | <pre><nowiki> | ||
mysqladmin -u root -p password yourpassword | mysqladmin -u root -p password yourpassword | ||
</nowiki></pre> | </nowiki></pre> | ||
and | and | ||
<pre><nowiki> | <pre><nowiki> | ||
mysqladmin -u root -p create database1 | mysqladmin -u root -p create database1 | ||
</nowiki></pre> | </nowiki></pre> | ||
''mysqladmin'' is a command-line tool provided by the default LAMP install. | ''mysqladmin'' is a command-line tool provided by the default LAMP install. | ||
=== Phpmyadmin and mysql-admin === | === Phpmyadmin and mysql-admin === | ||
All mysql tasks including setting the root password and creating databases can be done via a graphical interface using '''phpmyadmin''' or '''mysql-admin'''. | All mysql tasks including setting the root password and creating databases can be done via a graphical interface using '''phpmyadmin''' or '''mysql-admin'''. | ||
To install one or both of them, first enable the universe repository | To install one or both of them, first enable the universe repository | ||
* [[UbuntuHelp:Repositories/CommandLine| I am using Ubuntu server (command line)]] | * [[UbuntuHelp:Repositories/CommandLine| I am using Ubuntu server (command line)]] | ||
* [[UbuntuHelp:AddingRepositoriesHowto| I am using a desktop]] | * [[UbuntuHelp:AddingRepositoriesHowto| I am using a desktop]] | ||
Use [[UbuntuHelp:InstallingSoftware| any method]] to install | Use [[UbuntuHelp:InstallingSoftware| any method]] to install | ||
<pre><nowiki> | <pre><nowiki> | ||
phpmyadmin | phpmyadmin | ||
</nowiki></pre> | </nowiki></pre> | ||
==== Troubleshooting ==== | ==== Troubleshooting ==== | ||
'''If you get blowfish_secret error:''' | '''If you get blowfish_secret error:''' | ||
Choose and set a phrase for cryptography in the file /etc/phpmyadmin/blowfish_secret.inc.php and copy the line (not the php tags) into the file /etc/phpmyadmin/config.inc.php or you will receive an error. | Choose and set a phrase for cryptography in the file /etc/phpmyadmin/blowfish_secret.inc.php and copy the line (not the php tags) into the file /etc/phpmyadmin/config.inc.php or you will receive an error. | ||
==== Alternative: install phpMyAdmin from source ==== | ==== Alternative: install phpMyAdmin from source ==== | ||
See the [https://help.ubuntu.com/community/phpMyAdmin phpMyAdmin] page for instructions on how to install phpmyadmin from source: | See the [https://help.ubuntu.com/community/phpMyAdmin phpMyAdmin] page for instructions on how to install phpmyadmin from source: | ||
==== Mysql-admin ==== | ==== Mysql-admin ==== | ||
Mysql-admin runs locally, on the desktop. Use [[UbuntuHelp:InstallingSoftware| any method]] to install | Mysql-admin runs locally, on the desktop. Use [[UbuntuHelp:InstallingSoftware| any method]] to install | ||
<pre><nowiki> | <pre><nowiki> | ||
mysql-admin | mysql-admin | ||
</nowiki></pre> | </nowiki></pre> | ||
==== For more information ==== | ==== For more information ==== | ||
You really ought to read [http://dev.mysql.com/doc/mysql/en/default-privileges.html 2.9.3. Securing the Initial MySQL Accounts] from the [http://dev.mysql.com/doc/mysql/en/index.html MySQL Reference Manual]. | You really ought to read [http://dev.mysql.com/doc/mysql/en/default-privileges.html 2.9.3. Securing the Initial MySQL Accounts] from the [http://dev.mysql.com/doc/mysql/en/index.html MySQL Reference Manual]. | ||
=== Edit Apache Configuration === | === Edit Apache Configuration === | ||
You may want your current user to be the PHP pages administrator. To do so, edit the Apache configuration file : | You may want your current user to be the PHP pages administrator. To do so, edit the Apache configuration file : | ||
第319行: | 第203行: | ||
Search both the strings starting by "User" and "Group", and change the names by the current username and groupname you are using. | Search both the strings starting by "User" and "Group", and change the names by the current username and groupname you are using. | ||
Then you'll need to restart Apache. (look at the next chapter concerning apache commands) | Then you'll need to restart Apache. (look at the next chapter concerning apache commands) | ||
Configuration options relating specifically to user websites (accessed through localhost/~username) are in /etc/apache2/mods-enabled/userdir.conf. | Configuration options relating specifically to user websites (accessed through localhost/~username) are in /etc/apache2/mods-enabled/userdir.conf. | ||
=== Edit PHP Configuration to Work With MYSQL (Ubuntu Dapper) === | === Edit PHP Configuration to Work With MYSQL (Ubuntu Dapper) === | ||
In Dapper Drake, "extension=mysql.so" and "extension=mysqli.so" are enabled in the php.ini file out-of-the-box. However, sometimes php is not looking for those files in the right directory. You have then to move your files or modify the php.ini configuration.: | In Dapper Drake, "extension=mysql.so" and "extension=mysqli.so" are enabled in the php.ini file out-of-the-box. However, sometimes php is not looking for those files in the right directory. You have then to move your files or modify the php.ini configuration.: | ||
==== First solution ==== | ==== First solution ==== | ||
locate the directory where the extension files are placed: | locate the directory where the extension files are placed: | ||
<code><nowiki> locate mysql.so </nowiki></code> | <code><nowiki> locate mysql.so </nowiki></code> | ||
(change mysql.so in mysqli.so if you want to install the mysqli functions) | (change mysql.so in mysqli.so if you want to install the mysqli functions) | ||
-then modify the php.ini file to indicate the right place for the extension directory: | -then modify the php.ini file to indicate the right place for the extension directory: | ||
<pre><nowiki> | <pre><nowiki> | ||
$ gksudo "gedit /etc/php4/apache2/php.ini" | $ gksudo "gedit /etc/php4/apache2/php.ini" | ||
</nowiki></pre> | </nowiki></pre> | ||
or if you are using php5 | or if you are using php5 | ||
<pre><nowiki> | <pre><nowiki> | ||
$ gksudo "gedit /etc/php5/apache2/php.ini" | $ gksudo "gedit /etc/php5/apache2/php.ini" | ||
</nowiki></pre> | </nowiki></pre> | ||
Look for the 'extension_dir' property, and set it to the directory where you found the mysql(i).so file: | Look for the 'extension_dir' property, and set it to the directory where you found the mysql(i).so file: | ||
extension_dir= "/usr/lib/php5/20051025/" | extension_dir= "/usr/lib/php5/20051025/" | ||
Restart apache, and test if your mysql(i) functions are working. | Restart apache, and test if your mysql(i) functions are working. | ||
==== Second solution ==== | ==== Second solution ==== | ||
-locate the directory where the extension files are placed: | -locate the directory where the extension files are placed: | ||
<code><nowiki> locate mysql.so </nowiki></code> | <code><nowiki> locate mysql.so </nowiki></code> | ||
(change mysql.so in mysqli.so if you want to install the mysqli functions) | (change mysql.so in mysqli.so if you want to install the mysqli functions) | ||
Let's say that you found the file in '/usr/lib/php5/20051025/' | Let's say that you found the file in '/usr/lib/php5/20051025/' | ||
-then check in the php.ini file for the extension directory | -then check in the php.ini file for the extension directory | ||
<pre><nowiki> | <pre><nowiki> | ||
$ gksudo "gedit /etc/php4/apache2/php.ini" | $ gksudo "gedit /etc/php4/apache2/php.ini" | ||
</nowiki></pre> | </nowiki></pre> | ||
or if you are using php5 | or if you are using php5 | ||
<pre><nowiki> | <pre><nowiki> | ||
$ gksudo "gedit /etc/php5/apache2/php.ini" | $ gksudo "gedit /etc/php5/apache2/php.ini" | ||
</nowiki></pre> | </nowiki></pre> | ||
Look for the 'extension_dir' property. It should be by default '/usr/lib/php5/ext'. If it's not, change it for this value. | 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 create the default directory for extensions: | -Now create the default directory for extensions: | ||
<pre><nowiki> | <pre><nowiki> | ||
$ sudo mkdir /usr/lib/php5/ext | $ sudo mkdir /usr/lib/php5/ext | ||
</nowiki></pre> | </nowiki></pre> | ||
-Copy the extension file to the new directory: | -Copy the extension file to the new directory: | ||
<pre><nowiki> | <pre><nowiki> | ||
$ sudo cp /usr/lib/php5/20051025/mysql.so /usr/lib/php5/ext/mysql.so | $ sudo cp /usr/lib/php5/20051025/mysql.so /usr/lib/php5/ext/mysql.so | ||
</nowiki></pre> | </nowiki></pre> | ||
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. | 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 are working. | -Restart apache (see below), and test if your mysql(i) functions are working. | ||
=== Run, Stop, Test, And Restart Apache === | === Run, Stop, Test, And Restart Apache === | ||
Use the following command to run Apache : | Use the following command to run Apache : | ||
第419行: | 第269行: | ||
$ sudo nautilus | $ sudo nautilus | ||
</nowiki></pre> | </nowiki></pre> | ||
or | or | ||
if you want to make /var/www your own. (Use only for non-production web servers - this is not the most secure way to do things.) | if you want to make /var/www your own. (Use only for non-production web servers - this is not the most secure way to do things.) | ||
<pre><nowiki> | <pre><nowiki> | ||
$ sudo chown -R $USER:$USER /var/www | $ sudo chown -R $USER:$USER /var/www | ||
</nowiki></pre> | </nowiki></pre> | ||
=== Status === | === Status === | ||
To check the status of your PHP installation: | To check the status of your PHP installation: | ||
第436行: | 第283行: | ||
<?php phpinfo(); ?> | <?php phpinfo(); ?> | ||
</nowiki></pre> | </nowiki></pre> | ||
View this page on a web browser at http://yourserveripaddress/testphp.php or http://localhost/testphp.php | View this page on a web browser at http://yourserveripaddress/testphp.php or http://localhost/testphp.php | ||
=== Securing Apache === | === Securing Apache === | ||
If you just want to run your Apache install as a development server and want to prevent it from listening for incoming connection attempts, this is easy to do. | If you just want to run your Apache install as a development server and want to prevent it from listening for incoming connection attempts, this is easy to do. | ||
第445行: | 第290行: | ||
$ password: | $ password: | ||
</nowiki></pre> | </nowiki></pre> | ||
Change ports.conf so that it contains: | Change ports.conf so that it contains: | ||
<pre><nowiki> | <pre><nowiki> | ||
Listen 127.0.0.1:80 | Listen 127.0.0.1:80 | ||
</nowiki></pre> | </nowiki></pre> | ||
Save this file, and restart Apache (see above). Now Apache will serve only to your home domain, http://127.0.0.1 or http://localhost. | Save this file, and restart Apache (see above). Now Apache will serve only to your home domain, http://127.0.0.1 or http://localhost. | ||
=== Password-Protect a Directory === | === Password-Protect a Directory === | ||
There are 2 ways to password-protect a specific directory. | There are 2 ways to password-protect a specific directory. | ||
The recommended way involves editing | The recommended way involves editing | ||
第461行: | 第302行: | ||
The other way involves editing a <code><nowiki>.htaccess</nowiki></code> file in the directory to be protected. | The other way involves editing a <code><nowiki>.htaccess</nowiki></code> file in the directory to be protected. | ||
(To do this, you need access to that directory). | (To do this, you need access to that directory). | ||
==== Password-Protect a Directory With .htaccess ==== | ==== Password-Protect a Directory With .htaccess ==== | ||
See EnablingUseOfApacheHtaccessFiles | See EnablingUseOfApacheHtaccessFiles | ||
'''Warning: On at least some versions of Ubuntu, <code><nowiki>.htaccess</nowiki></code> files will not work by default. See EnablingUseOfApacheHtaccessFiles for help on enabling them.''' | '''Warning: On at least some versions of Ubuntu, <code><nowiki>.htaccess</nowiki></code> files will not work by default. See EnablingUseOfApacheHtaccessFiles for help on enabling them.''' | ||
=== thumbnails === | === thumbnails === | ||
If you direct your web browser to a directory (rather than a specific file), | If you direct your web browser to a directory (rather than a specific file), | ||
and there is no "index.html" file in that directory, | and there is no "index.html" file in that directory, | ||
Apache will generate an index file on-the-fly listing all the files and folders in that directory. | Apache will generate an index file on-the-fly listing all the files and folders in that directory. | ||
Each folder has a little icon of a folder next to it. | Each folder has a little icon of a folder next to it. | ||
To put a thumbnail of that specific image (rather than the generic "image icon") | To put a thumbnail of that specific image (rather than the generic "image icon") | ||
next to each image file (.jpg, .png, etc.): | next to each image file (.jpg, .png, etc.): | ||
''... todo: add instructions on how to do thumbnails here, perhaps using [http://aspn.activestate.com/ASPN/CodeDoc/Apache-AutoIndex/AutoIndex.html Apache::AutoIndex 0.08] or [http://aspn.activestate.com/ASPN/CodeDoc/Apache-Album/Album.html Apache::Album 0.95] ... '' | ''... todo: add instructions on how to do thumbnails here, perhaps using [http://aspn.activestate.com/ASPN/CodeDoc/Apache-AutoIndex/AutoIndex.html Apache::AutoIndex 0.08] or [http://aspn.activestate.com/ASPN/CodeDoc/Apache-Album/Album.html Apache::Album 0.95] ... '' | ||
=== Known problems === | === Known problems === | ||
==== Skype incompatibility ==== | ==== Skype incompatibility ==== | ||
[[UbuntuHelp:Skype]] uses port 80 for incoming calls, and thus, may block Apache. The solution is to change the port in one of the applications. Usually, port 81 is free and works fine. To change the port number in [[UbuntuHelp:Skype]] go to menu Tools > Options, then click on the Advanced tab, then in the box of the port for incoming calls write your preference. | [[UbuntuHelp:Skype]] uses port 80 for incoming calls, and thus, may block Apache. The solution is to change the port in one of the applications. Usually, port 81 is free and works fine. To change the port number in [[UbuntuHelp:Skype]] go to menu Tools > Options, then click on the Advanced tab, then in the box of the port for incoming calls write your preference. | ||
=== Other Apache Options === | === Other Apache Options === | ||
* ServerSideIncludes - enable SSI in Apache2 | * ServerSideIncludes - enable SSI in Apache2 | ||
* LocalhostSubdomain - access your local files as if you had different subdomains | * LocalhostSubdomain - access your local files as if you had different subdomains | ||
=== Further Information === | === Further Information === | ||
* StrongPasswords is recommended reading! | * StrongPasswords is recommended reading! |
2007年11月30日 (五) 15:21的版本
文章出处: |
{{#if: | {{{2}}} | https://help.ubuntu.com/community/ApacheMySQLPHP }} |
点击翻译: |
English {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/af | • {{#if: UbuntuHelp:ApacheMySQLPHP|Afrikaans| [[::ApacheMySQLPHP/af|Afrikaans]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/ar | • {{#if: UbuntuHelp:ApacheMySQLPHP|العربية| [[::ApacheMySQLPHP/ar|العربية]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/az | • {{#if: UbuntuHelp:ApacheMySQLPHP|azərbaycanca| [[::ApacheMySQLPHP/az|azərbaycanca]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/bcc | • {{#if: UbuntuHelp:ApacheMySQLPHP|جهلسری بلوچی| [[::ApacheMySQLPHP/bcc|جهلسری بلوچی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/bg | • {{#if: UbuntuHelp:ApacheMySQLPHP|български| [[::ApacheMySQLPHP/bg|български]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/br | • {{#if: UbuntuHelp:ApacheMySQLPHP|brezhoneg| [[::ApacheMySQLPHP/br|brezhoneg]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/ca | • {{#if: UbuntuHelp:ApacheMySQLPHP|català| [[::ApacheMySQLPHP/ca|català]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/cs | • {{#if: UbuntuHelp:ApacheMySQLPHP|čeština| [[::ApacheMySQLPHP/cs|čeština]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/de | • {{#if: UbuntuHelp:ApacheMySQLPHP|Deutsch| [[::ApacheMySQLPHP/de|Deutsch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/el | • {{#if: UbuntuHelp:ApacheMySQLPHP|Ελληνικά| [[::ApacheMySQLPHP/el|Ελληνικά]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/es | • {{#if: UbuntuHelp:ApacheMySQLPHP|español| [[::ApacheMySQLPHP/es|español]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/fa | • {{#if: UbuntuHelp:ApacheMySQLPHP|فارسی| [[::ApacheMySQLPHP/fa|فارسی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/fi | • {{#if: UbuntuHelp:ApacheMySQLPHP|suomi| [[::ApacheMySQLPHP/fi|suomi]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/fr | • {{#if: UbuntuHelp:ApacheMySQLPHP|français| [[::ApacheMySQLPHP/fr|français]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/gu | • {{#if: UbuntuHelp:ApacheMySQLPHP|ગુજરાતી| [[::ApacheMySQLPHP/gu|ગુજરાતી]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/he | • {{#if: UbuntuHelp:ApacheMySQLPHP|עברית| [[::ApacheMySQLPHP/he|עברית]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/hu | • {{#if: UbuntuHelp:ApacheMySQLPHP|magyar| [[::ApacheMySQLPHP/hu|magyar]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/id | • {{#if: UbuntuHelp:ApacheMySQLPHP|Bahasa Indonesia| [[::ApacheMySQLPHP/id|Bahasa Indonesia]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/it | • {{#if: UbuntuHelp:ApacheMySQLPHP|italiano| [[::ApacheMySQLPHP/it|italiano]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/ja | • {{#if: UbuntuHelp:ApacheMySQLPHP|日本語| [[::ApacheMySQLPHP/ja|日本語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/ko | • {{#if: UbuntuHelp:ApacheMySQLPHP|한국어| [[::ApacheMySQLPHP/ko|한국어]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/ksh | • {{#if: UbuntuHelp:ApacheMySQLPHP|Ripoarisch| [[::ApacheMySQLPHP/ksh|Ripoarisch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/mr | • {{#if: UbuntuHelp:ApacheMySQLPHP|मराठी| [[::ApacheMySQLPHP/mr|मराठी]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/ms | • {{#if: UbuntuHelp:ApacheMySQLPHP|Bahasa Melayu| [[::ApacheMySQLPHP/ms|Bahasa Melayu]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/nl | • {{#if: UbuntuHelp:ApacheMySQLPHP|Nederlands| [[::ApacheMySQLPHP/nl|Nederlands]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/no | • {{#if: UbuntuHelp:ApacheMySQLPHP|norsk| [[::ApacheMySQLPHP/no|norsk]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/oc | • {{#if: UbuntuHelp:ApacheMySQLPHP|occitan| [[::ApacheMySQLPHP/oc|occitan]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/pl | • {{#if: UbuntuHelp:ApacheMySQLPHP|polski| [[::ApacheMySQLPHP/pl|polski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/pt | • {{#if: UbuntuHelp:ApacheMySQLPHP|português| [[::ApacheMySQLPHP/pt|português]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/ro | • {{#if: UbuntuHelp:ApacheMySQLPHP|română| [[::ApacheMySQLPHP/ro|română]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/ru | • {{#if: UbuntuHelp:ApacheMySQLPHP|русский| [[::ApacheMySQLPHP/ru|русский]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/si | • {{#if: UbuntuHelp:ApacheMySQLPHP|සිංහල| [[::ApacheMySQLPHP/si|සිංහල]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/sq | • {{#if: UbuntuHelp:ApacheMySQLPHP|shqip| [[::ApacheMySQLPHP/sq|shqip]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/sr | • {{#if: UbuntuHelp:ApacheMySQLPHP|српски / srpski| [[::ApacheMySQLPHP/sr|српски / srpski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/sv | • {{#if: UbuntuHelp:ApacheMySQLPHP|svenska| [[::ApacheMySQLPHP/sv|svenska]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/th | • {{#if: UbuntuHelp:ApacheMySQLPHP|ไทย| [[::ApacheMySQLPHP/th|ไทย]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/tr | • {{#if: UbuntuHelp:ApacheMySQLPHP|Türkçe| [[::ApacheMySQLPHP/tr|Türkçe]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/vi | • {{#if: UbuntuHelp:ApacheMySQLPHP|Tiếng Việt| [[::ApacheMySQLPHP/vi|Tiếng Việt]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/yue | • {{#if: UbuntuHelp:ApacheMySQLPHP|粵語| [[::ApacheMySQLPHP/yue|粵語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/zh | • {{#if: UbuntuHelp:ApacheMySQLPHP|中文| [[::ApacheMySQLPHP/zh|中文]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/zh-hans | • {{#if: UbuntuHelp:ApacheMySQLPHP|中文(简体)| [[::ApacheMySQLPHP/zh-hans|中文(简体)]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ApacheMySQLPHP | UbuntuHelp:ApacheMySQLPHP | {{#if: | :}}ApacheMySQLPHP}}/zh-hant | • {{#if: UbuntuHelp:ApacheMySQLPHP|中文(繁體)| [[::ApacheMySQLPHP/zh-hant|中文(繁體)]]}}|}} |
{{#ifeq:UbuntuHelp:ApacheMySQLPHP|:ApacheMySQLPHP|请不要直接编辑翻译本页,本页将定期与来源同步。}} |
{{#ifexist: :ApacheMySQLPHP/zh | | {{#ifexist: ApacheMySQLPHP/zh | | {{#ifeq: {{#titleparts:ApacheMySQLPHP|1|-1|}} | zh | | }} }} }} {{#ifeq: {{#titleparts:ApacheMySQLPHP|1|-1|}} | zh | | }}
Parent page: Programming Applications This is to help people setup and install a LAMP (Linux-Apache-MySQL-PHP) server in Ubuntu, including Apache 2, PHP 4 or 5, and MySQL 4.1 or 5.0. When installing from the Ubuntu 6.06 (Dapper Drake) "Server cd", you have the option of choosing to install a LAMP setup at the inital Ubuntu installation screen. That will install apache2, php5 and mysql 5.0.
Check Requirements
Some applications require php4 while others will work with php5. Be sure to install the version of php and the corresponding apache2 module for it. You cannot have both php4 and php5 modules running on the same instance of apache2 at the same time. Installing one may remove the other. If you have both php4 and php5 installed, be aware of which version of the apache2 php module you have. If libapache2-mod-php5 is already installed, the php4 package will install libapache-mod-php4 and not libapache2-mod-php4 package. If libapache2-mod-php5 is not installed, installing php4 will install the apache2 php module (libapache2-mod-php4). See this example. Most web applications will use Apache2, php5 and mysql5.0. If no specific versions are mentioned in your web application's documentation, use those.
To install the default LAMP stack in Ubuntu 6.06 LTS (Dapper Drake)
If you did not use the LAMP installer option from the server cd but want to install those same packages without having to reinstall your operating system, use any method to install the following packages
apache2 php5-mysql libapache2-mod-php5 mysql-server
All of those packages are in the Ubuntu 6.06 LTS (Dapper Drake) main repository. Once LAMP is installed, you need to set a mysql root password and then, depending on your web application, create a database, user and password. That's it!
To install the default LAMP stack in Ubuntu 7.04 (Feisty Fawn)
In Feisty, the Ubuntu base system includes Tasksel. You can either install LAMP using tasksel or install the LAMP packages as detailed above.
sudo tasksel install lamp-server
See Tasksel
Starting over, How to remove the LAMP stack
To remove the LAMP stack remove the following packages:
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
To also remove the debconf data, use the purge option when removing. To get rid of any configurations you may have made to apache, manually remove the /etc/apache2 directory once the packages have been removed.
Installing Apache 2
To only install the apache2 webserver, use any method to install
apache2
Troubleshooting
If you get this error: apache2: Could not determine the server's fully qualified domain name, using 127.0.0.1 for ServerName then use a text editor such as "sudo nano" at the command line or "gksudo gedit" on the desktop to edit
/etc/apache2/httpd.conf
and add
ServerName localhost
at the end of the file.
Virtual Hosts
Apache2 has the concept of sites, which are separate configuration files that Apache2 will read. These are available in /etc/apache2/sites-available
. By default, there is one site available called 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 activate only 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 then enable it in Apache2.
To create a new site:
- Copy the default website as a starting point.
sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/mysite
- Edit the new configuration file in a text editor "sudo nano" on the command line or "gksudo gedit", for example:
gksudo gedit /etc/apache2/sites-available/mysite
- Change the
DocumentRoot
to point to the new location. For example,/home/user/public_html/
- Change the
Directory
directive, replace<Directory /var/www/>
to<Directory /home/user/public_html/
- You can also set separate logs for each site. To do this, change the
ErrorLog
andCustomLog
directives. This is optional, but handy if you have many sites - Save the file
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 will receive 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/
Installing PHP 5
To only install PHP5. use any method to install
php5
If PHP4 is present on your system, also install
libapache2-mod-php5
Troubleshooting
Does your browser ask if you want to download the php file instead of displaying it? If Apache is not actually parsing the php after you restarted it, install libapache2-mod-php5
. It is installed when you install the php5
package, but may have been removed inadvertently by packages which need to run a different version of php. You may also need to actually enable it, by doing sudo a2enmod php5
followed by sudo /etc/init.d/apache2 restart
. Be sure to clear your browser's cache before testing your site again.
Installing PHP 4
To install PHP4, Use any method to install
php4
If PHP5 is present on your system, installing php4 will install the php module for apache (version 1.3) and not apache2. To use php4 with apache2, install
libapache2-mod-php4
Troubleshooting
Does your browser ask if you want to download the php file instead of displaying it? If Apache is not actually parsing the php after you restarted it, install libapache2-mod-php4
. It is installed when you install the php4
package, but may have been removed inadvertently by packages which need to run a different version of php. You may also need to actually enable it, by doing sudo a2enmod php4
followed by sudo /etc/init.d/apache2 restart
. Be sure to clear your browser's cache before testing your site again.
Installing MYSQL with PHP 5
Use any method to install
mysql-server libapache2-mod-auth-mysql php5-mysql
Installing MYSQL with PHP 4
First enable the universe repository since the packages are not in main
Use any method to install
mysql-server libapache2-mod-auth-mysql php4-mysql
After installing PHP
You may need to increase the memory limit that PHP imposes on a script. Edit the /etc/php5/apache2/php.ini file and increase the memory_limit value.
After installing MySQL
Set mysql bind address
Before you can access the database from other computers in your network, you have to change its bind address. Note that this can be a security problem, because your database can be accessed by others computers than your own. Skip this step if the applications which require mysql are running on the same machine. type:
nano /etc/mysql/my.cnf
and change the line:
bind-address = localhost
to your own internal ip address e.g. 192.168.1.20
bind-address = 192.168.1.20
If your ip address is dynamic you can also comment out the bind-address line and it will default to your current ip. If you try to connect without changing the bind-address you will recieve a "Can not connect to mysql error 10061".
Set mysql root password
Before accessing the database by console you need to type:
mysql -u root
At the mysql console type:
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('yourpassword');
A successful mysql command will show: Query OK, 0 rows affected (0.00 sec) Mysql commands can span several lines. Do not forget to end your mysql command with a semicolon. Note: If you have already set a password for the mysql root, you will need to use:
mysql -u root -p
(Did you forget the mysql-root password? See MysqlPasswordReset.)
Create a mysql database
mysql> CREATE DATABASE database1;
Create a mysql user
For creating a new user with all privileges (use only for troubleshooting), at mysql prompt type:
mysql> GRANT ALL PRIVILEGES ON *.* TO 'yourusername'@'localhost' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION;
For creating a new user with fewer privileges (should work for most web applications) which can only use the database named "database1", at mysql prompt type:
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON database1.* TO 'yourusername'@'localhost' IDENTIFIED BY 'yourpassword';
yourusername and yourpassword can be anything you like. database1 is the name of the database the user gets access to. localhost is the location which gets access to your database. You can change it to '%' (or to hostnames or ip addresses) to allow connections from every location (or only from specific locations) to the database. Note, that this can be a security problem and should only be used for testing purposes! To exit the mysql prompt type:
mysql> \q
Since the mysql root password is now set, if you need to use mysql again (as the mysql root), you will need to use:
mysql -u root -p
and then enter the password at the prompt.
Backup-Settings
Please, let's say something in which directories MySql stores the database information and how to configure a backup
Alternatively
There is more than just one way to set the mysql root password and create a database. For example mysqladmin can be used:
mysqladmin -u root -p password yourpassword
and
mysqladmin -u root -p create database1
mysqladmin is a command-line tool provided by the default LAMP install.
Phpmyadmin and mysql-admin
All mysql tasks including setting the root password and creating databases can be done via a graphical interface using phpmyadmin or mysql-admin. To install one or both of them, first enable the universe repository
Use any method to install
phpmyadmin
Troubleshooting
If you get blowfish_secret error: Choose and set a phrase for cryptography in the file /etc/phpmyadmin/blowfish_secret.inc.php and copy the line (not the php tags) into the file /etc/phpmyadmin/config.inc.php or you will receive an error.
Alternative: install phpMyAdmin from source
See the phpMyAdmin page for instructions on how to install phpmyadmin from source:
Mysql-admin
Mysql-admin runs locally, on the desktop. Use any method to install
mysql-admin
For more information
You really ought to read 2.9.3. Securing the Initial MySQL Accounts from the MySQL Reference Manual.
Edit Apache Configuration
You may want your current user to be the PHP pages administrator. To do so, edit the Apache configuration file :
$ gksudo "gedit /etc/apache2/apache2.conf"
Search both the strings starting by "User" and "Group", and change the names by the current username and groupname you are using. Then you'll need to restart Apache. (look at the next chapter concerning apache commands) Configuration options relating specifically to user websites (accessed through localhost/~username) are in /etc/apache2/mods-enabled/userdir.conf.
Edit PHP Configuration to Work With MYSQL (Ubuntu Dapper)
In Dapper Drake, "extension=mysql.so" and "extension=mysqli.so" are enabled in the php.ini file out-of-the-box. However, sometimes php is not looking for those files in the right directory. You have then to move your files or modify the php.ini configuration.:
First solution
locate the directory where the extension files are placed:
locate mysql.so
(change mysql.so in mysqli.so if you want to install the mysqli functions)
-then modify the php.ini file to indicate the right place for the extension directory:
$ gksudo "gedit /etc/php4/apache2/php.ini"
or if you are using php5
$ gksudo "gedit /etc/php5/apache2/php.ini"
Look for the 'extension_dir' property, and set it to the directory where you found the mysql(i).so file: extension_dir= "/usr/lib/php5/20051025/" Restart apache, and test if your mysql(i) functions are working.
Second solution
-locate the directory where the extension files are placed:
locate mysql.so
(change mysql.so in mysqli.so if you want to install the mysqli functions)
Let's say that you found the file in '/usr/lib/php5/20051025/'
-then check in the php.ini file for the extension directory
$ gksudo "gedit /etc/php4/apache2/php.ini"
or if you are using 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 create the default directory for extensions:
$ 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 are working.
Run, Stop, Test, And Restart Apache
Use the following command to run Apache :
$ sudo /usr/sbin/apache2ctl start
To stop it, use :
$ sudo /usr/sbin/apache2ctl stop
To test configuration changes, use :
$ sudo /usr/sbin/apache2ctl configtest
Finally, to restart it, run :
$ sudo /usr/sbin/apache2ctl restart
Using Apache
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 address bar. By default the directory for apache server pages is /var/www . It needs root access in order to put files in. A way to do it is just starting the file browser as root in a terminal:
$ sudo nautilus
or if you want to make /var/www your own. (Use only for non-production web servers - this is not the most secure way to do things.)
$ sudo chown -R $USER:$USER /var/www
Status
To check the status of your PHP installation:
$ gksudo "gedit /var/www/testphp.php"
and insert the following line
<?php phpinfo(); ?>
View this page on a web browser at http://yourserveripaddress/testphp.php or http://localhost/testphp.php
Securing Apache
If you just want to run your Apache install as a development server and want to prevent it from listening for incoming connection attempts, this is easy to do.
$ gksudo "gedit /etc/apache2/ports.conf" $ password:
Change ports.conf so that it contains:
Listen 127.0.0.1:80
Save this file, and restart Apache (see above). Now Apache will serve only to your home domain, http://127.0.0.1 or http://localhost.
Password-Protect a Directory
There are 2 ways to password-protect a specific directory.
The recommended way involves editing
/etc/apache2/apache2.conf
.
(To do this, you need root access).
The other way involves editing a .htaccess
file in the directory to be protected.
(To do this, you need access to that directory).
Password-Protect a Directory With .htaccess
See EnablingUseOfApacheHtaccessFiles
Warning: On at least some versions of Ubuntu, .htaccess
files will not work by default. See EnablingUseOfApacheHtaccessFiles for help on enabling them.
thumbnails
If you direct your web browser to a directory (rather than a specific file), and there is no "index.html" file in that directory, Apache will generate an index file on-the-fly listing all the files and folders in that directory. Each folder has a little icon of a folder next to it. To put a thumbnail of that specific image (rather than the generic "image icon") next to each image file (.jpg, .png, etc.): ... todo: add instructions on how to do thumbnails here, perhaps using Apache::AutoIndex 0.08 or Apache::Album 0.95 ...
Known problems
Skype incompatibility
UbuntuHelp:Skype uses port 80 for incoming calls, and thus, may block Apache. The solution is to change the port in one of the applications. Usually, port 81 is free and works fine. To change the port number in UbuntuHelp:Skype go to menu Tools > Options, then click on the Advanced tab, then in the box of the port for incoming calls write your preference.
Other Apache Options
- ServerSideIncludes - enable SSI in Apache2
- LocalhostSubdomain - access your local files as if you had different subdomains
Further Information
- StrongPasswords is recommended reading!
- BastilleLinux is also recommended if you're going to be running a live webserver.
- You can compile Self:PHP5FromSource, as well as Self:MYSQL5FromSource.
- Self:PHPOracle will enable you to connect to Oracle databases.
- PhpPear : PHP Extension and Application Repository