- Check Requirements
- Untuk menginstall LAMP stack default di Ubuntu 6.06 LTS (Dapper Drake)
- Menginstall Apache 2
- Menginstall PHP 5
- Installing PHP 4
- Installing MYSQL with PHP 5
- Installing MYSQL with PHP 4
- After installing PHP
- After installing MySQL
- Phpmyadmin or mysql-admin
- Edit Apache Configuration
- Edit PHP Configuration to Work With MYSQL (Ubuntu Breezy)
- Edit PHP Configuration to Work With MYSQL (Ubuntu Dapper)
- Run, Stop, And Restart Apache
- Using Apache
- Status
- Securing Apache
- Password-Protect a Directory With .htaccess
- Known problems
- Other Apache Options
- Further Information
Saat menginstal dari Ubuntu 6.06 (Dapper Drake) "Server cd", anda punya plihan untuk memilih untuk meng-install LAMP setup di layar inital Ubuntu installation. Yang akan menginstall apache2, php5 and mysql 5.0.
Pada Ubuntu 5.10 (Breezy Badger), PHP5 available di main repositories tapi MYSQL 5.0 hanya bisa diinstall dengan compiling.
Check Requirements
Beberapa aplikasi membutuhkan php4 sedangkan yang lainnya dapat bekerja dengan php5. Pastikan untuk menginstal versi PHP yang berhubungan dengan module apache2. Anda tidak bisa memiliki kedua modul PHP4 dan PHP5 yang berjalan di apache2 secara bersamaan. Menginstall yang satu akan meremove yang lain.
Jika anda menginstall baik php4 dan php5, perhatikan versi modul apache2 yang mana yang telah anda miliki. Jika libapache2-mod-php5 telah diinstall, maka package php4 akan menginstall libapache-mod-php4 and not libapache2-mod-php4 package.
Jika libapache2-mod-php5 belum diinstall, menginstall php4 akan menginstall modul apache2 php (libapache2-mod-php4). Lihat berikut example.
Kebanyakan aplikasi-aplikasi web menggunakan Apache2, php5 dan mysql5.0. Jika aplikasi web anda tidak mencantumkan versi yang spesifik, use those
Untuk menginstall LAMP stack default di Ubuntu 6.06 LTS (Dapper Drake)
Jika anda tidak menggunakan pilihan installer LAMP dari cd server tapi ingin menginstall packages LAMP yang sama tanpa perlu menginstall ulang sistem operasi anda, maka gunakanlah any method untuk menginstall packages berikut
apache2 php5-mysql libapache2-mod-php5 mysql-server
Semua paket tersebut berada di Ubuntu 6.06 LTS (Dapper Drake) main repository. Setelah LAMP diinstall, anda perlu mengeset mysql root password dan kemudian, tergantung pada aplikasi web anda, buat database, user, dan password. Selesai !!!
Menginstall Apache 2
Untuk menginstall apache2 webserver saja, gunakan any method untuk install
apache2
Menginstall PHP 5
Untuk menginstall PHP5, gunakan any method untuk install
php5
Jika PHP4 juga ada di sistem anda, install juga
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
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
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
Type this for creating standard configuration in Ubuntu 5.10 (Breezy Badger):
cd /usr sudo ./bin/mysql_install_db --user=mysql
that command is not needed for Ubuntu 6.06 (Dapper Drake). Is it even needed for Breezy?
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 that step, if your applications who need 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
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.
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.
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 dababase1
mysqladmin is a command-line tool provided by the default LAMP install.
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
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.
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 Breezy)
This is not needed for Ubuntu 6.06 LTS (Dapper Drake). In the latest version, "extension=mysql.so" and "extension=mysqli.so" are present without the ";" and so are enabled out-of-the-box.
You may need to edit the PHP configuration file to get PHP and MYSQL talking :
$ gksudo "gedit /etc/php4/apache2/php.ini"
or if you are using php5
$ gksudo "gedit /etc/php5/apache2/php.ini"
Remove the ";" for the line ";extension=mysql.so", and restart Apache as is stated below.
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, And Restart Apache
Use the following command to run Apache :
$ sudo /usr/sbin/apache2ctl start
To stop it, use :
$ sudo /usr/sbin/apache2ctl stop
Finally, to restart it, run :
$ sudo /usr/sbin/apache2ctl restart
Using Apache
You can acces 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
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 With .htaccess
Create a file called .htaccess in the directory you want to password-protect with the follwing content:
AuthUserFile /your/path/.htpasswd AuthName "Authorization Required" AuthType Basic require valid-user
instead of valid-user, you can also add the users you want directly
If you want to password protect just a single file in a folder add the following lines to the .htaccess file:
<Files "mypage.html"> Require valid-user </Files>
Then create the file /your/path/.htpasswd which contains the users that are allowed to login and their passwords. We do that with the htpasswd command:
htpasswd -c /path/to/your/.htpasswd user1
The -c flag is used only when you are creating a new file. After the first time, you will omit the -c flag, when you are adding new users to an already-existing password file. Otherwise you will overwrite the file!!
Nevertheless, you should store the file in as secure a location as possible, with whatever minimum permissions on the file so that the web server itself can read the file.
Finally we need to add the following lines to /etc/apache2/apache2.conf:
<Directory /your/path> AllowOverride All </Directory>
You have to adjust /your/path/.htpasswd
Restart your webserver:
sudo /etc/init.d/apache2 restart
Troubleshooting
If you can't access your stuff and the dialog keeps popping up, check that you entered the username and password correctly. If it still doesn't work, check the path to your .htpasswd and make sure the path specified in the AuthUserFile directive is correct. Also make sure that both the .htpasswd and .htaccess files are readable by the web server user chmod 644 should do the trick!
Example
Here is an example on how to prevent users from access the directory, password-protect a specific file and allow userse to view a specific file:
AuthUserFile /your/path/.htpasswd AuthName "Authorization Required" AuthType Basic Order Allow,Deny <Files myfile1.html> Order Allow,Deny require valid-user </Files> <Files myfile2.html> Order Deny,Allow </Files>
Known problems
Skype incompatibility
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 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 PHP5FromSource, as well as MYSQL5FromSource.
PHPOracle will enable you to connect to Oracle databases.
terakhir disunting 2007-08-10 16:25:26 oleh adhan
