Biasanya di vps sudah tersedia apache2.
Virtual Host
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 000-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/000-default.conf /etc/apache2/sites-available/mysite.confÂ
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.conf
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/>
        Options All
        AllowOverride All Â
        Require all granted
       </Directory>
You can also set separate logs for each site. To do this, change the ErrorLog and CustomLog 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 000-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/
To only install PHP5. use any method to install the package
libapache2-mod-php5
Enable this module by doing
$ sudo a2enmod php5
which creates a symbolic link /etc/apache2/mods-enabled/php5 pointing to /etc/apache2/mods-availble/php5 .
Except if you use deprecated PHP code beginning only by "<?" instead of "<?php" (which is highly inadvisable), open, as root, the file /etc/php5/apache2/php.ini , look for the line "short_open_tag = On", change it to "short_open_tag = Off" (not including the quotation marks) and add a line of comment (beginning by a semi-colon) giving the reason, the author and the date of this change. This way, if you later want some XML or XHTML file to be served as PHP, the "<?xml" tag will be ignored by PHP instead of being seen as a PHP code mistake.
Relaunch Apache 2 again:
$ sudo service apache2 restart
Don't forget to install php5-fpm
apt-get install php5-fpm
apt-get install php5-mysql php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl
Installing MYSQL with PHP 5
Use any method to install
mysql-server libapache2-mod-auth-mysql php5-mysql
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 other computers than your own. Skip this step if the applications which require mysql are running on the same machine.
type:
$ sudo 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".
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.)
$ mysql> CREATE DATABASE database1;
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.
Please, let's say something in which directories mysql stores the database information and how to configure a backup
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.
All mysql tasks including setting the root password and creating databases can be done via a graphical interface using phpmyadmin or mysql-workbench.
To install one or both of them, first enable the universe repository
Use any method to install
phpmyadmin
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.
If you get a 404 error upon visiting http://localhost/phpmyadmin: You will need to configure apache2.conf to work with Phpmyadmin.
$ gksudo gedit /etc/apache2/apache2.conf
Include the following line at the bottom of the file, save and quit.
$ Include /etc/phpmyadmin/apache.conf
See the phpMyAdmin page for instructions on how to install phpmyadmin from source:
Mysql-workbench runs locally, on the desktop. Use any method to install
mysql-workbench
2.9.3. Securing the Initial MySQL Accounts from the MySQL Reference Manual is worth reading.
You may want your current user to be the PHP pages administrator. To do so, edit the Apache configuration file :
$ gksudo "gedit /etc/apache2/envvars"
Search both the strings starting by "APACHE_RUN_USER" and "APACHE_RUN_GROUP", and change the names to 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.
suPHP is a tool for executing PHP scripts with the permissions of their owners. It consists of an Apache module (mod_suphp) and a setuid root binary (suphp) that is called by the Apache module to change the uid of the process executing the PHP interpreter.
Note: suPHP enforces, security and helps avoid file permission problems under development environments with several users editing the site files, but it also demands more memory and CPU usage, which can degrade your server performance under certain circumstances.
To only install suPHP. use any method to install the package
libapache2-mod-suphp
Enable this module by doing
sudo a2enmod suphp
then use a text editor such as "sudo nano" at the command line or "gksudo gedit" on the desktop to edit this file
sudo nano /etc/apache2/mods-available/php5.conf
or
gksu "gedit /etc/apache2/mods-available/php5.conf"
make a new empty line at the top of the content, then add
<Directory /usr/share>
make a new empty line at the bottom of the content, then add
</Directory>
save changes
For security reasons we need to specify to suPHP what are the document paths allowed to execute scripts, use a text editor such as "sudo nano" at the command line or "gksudo gedit" on the desktop to edit this file
sudo nano /etc/suphp/suphp.conf
or
gksu "gedit /etc/suphp/suphp.conf
find the value "docroot" and specify the document path of your site files, for example:
docroot=/var/www/
that value restrict script execution only to files inside "/var/www/"
docroot=/var/www/:${HOME}/public_html
that value restrict script execution only to files inside a custom home folder for each configured user inside "/var/www/:${HOME}/public_html"
for this tutorial we are going to use this value
docroot=/home/user/public_html/
which is the same Apache directory directive set before in this document
save changes
to restart Apache, type in your terminal
sudo /etc/init.d/apache2 restart
Now lets create a test script to see if suPHP is working correctly, in your terminal type
echo "<?php echo 'whoim = '.exec('/usr/bin/whoami');?>" | tee /home/user/public_html/whomi.php
that command creates a quick php test file to display the current user executing the script
open your browser and navigate to "localhost/whomi.php", most likely the browser will show you a "500" server error, this is because suPHP does not allow too permissive file and folder permissions and also does not allow mixed file and folder ownership, to correct this type in your terminal
sudo find /home/user/public_html/ -type f -exec chmod 644 {} \; sudo find /home/user/public_html/ -type d -exec chmod 755 {} \; sudo chown user:group -R /home/user/public_html/
those commands enforce a secure and correct file and folder permission and also set a correct user and group ownership for all of them
Now open your browser and navigate to "localhost/whomi.php", if everything went fine you should see the name of the file owner executing the script and not "www-data" unless you specified so
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
Alternatively, you can use a graphical interface by installing Rapache or the simpler localhost-indicator.
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:
$ gksudo 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
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
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.
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).
See EnablingUseOfApacheHtaccessFiles
Warning: On at least some versions of Ubuntu, .htaccess files will not work by default. See EnablingUseOfApacheHtaccessFiles for help on enabling them.
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 ...
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.