Today we see how to set up our Linux box for the web production. What we need is Apache (il web server), MySQL (the database that will contain the data) and PHP (the interpreter for the dynamic language PHP). This configuration is exactly the same adopted by major server worldwide.
Some time ago there was some’ confusion about which version to use php. It was just released php5 and was still using the version 4, for some commands backward compatibility has not been met and some scripts have stopped working. Fortunately php5 circulating for quite some time, and it is even completed the development of php4. There will be problems with large packages (wordpress, joomla and company).
Installation is very simple. Just run the command
sudo apt-get install tasksel
to install the program tasksel (not included in ubuntu 11.04), and run the command with tasksel
sudo tasksel install lamp-server
This command will install the following packages:
apache2 apache2-mpm-prefork apache2-utils apache2.2-common libapache2-mod-php5 libapr1 libaprutil1 libdbi-perl libdbd-mysql-perl libmysqlclient15off libnet-daemon-perl libplrpc libpq5-perl mysql-client-5.0 mysql-common mysql-server
that (if we wanted to remove the webserver) these packets will be deleted.
Apache is a service, and as all services is bootable via the command line as follows:
sudo / etc/init.d/apache2 start
We test operation by calling the Apache webserver from the browser. We write in the URL bar of Firefox address “
http://127.0.0.1/“: always address that identifies the machine from which the request originated.
If you see the message “It works!“… as understandable Apache is properly initiated and… works. Conversely, if Firefox times out something went wrong. Check again that when the service there were problems.
Now that we know that Apache runs we will have to change the page “It works!” and put the code we are writing. If we use Ubuntu are all in the directory “
/var/www/“, for many other distributions instead is under “
/var/www/html/“. Edit the file “
index.html” and we can start working.
Now that we have tested have to test the operation of the Apache PHP. Simply delete the file “
index.html” and create the new file “
index.php“, inside which contact this very short code:
<?PHP phpinfo(); ?>
We recall the file using browser. If you will see the same code placed there something wrong. I suggest you check the PHP packages installed. As if the image was going to be this video.
Be careful not to make public the file containing the function “
phpinfo();“, from the information that it might be a help to “pierce” the site.
MySQL is the data manager within the server, the blog post, articles in a newspaper, users, their passwords, the post in a forum (virtually all data) are saved in a number of tables that reside in a database. MySQL is a DBMS (Data Base Management System), Suffice to say that we can save all this information to make them available within the pages.
As always the installation is simple. Just run the following command:
sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql
The packages are three that we install in all: “mysql-server” is the real database, “libapache2-mod-auth-mysql” allows Apache to recognize the database and “php5-mysql” ensuring interaction between PHP and MySQL.
At this point we should have finished, However, we use this configuration “base” only for the production or testing, Please note that we do not set the bind address and password of MySQL, this is a clear safety issue internal server, that we can ignore because we're just talking about production and testing. Suggest for the management of / database package “phpmyadmin“. It should be extracted and put into a directory accessible by the server. Allows you to create, cancel, modify database, tabelle ed utenti. It is a very powerful tool and easy to use.
If we want the site to which we are working is visible only from the computer with which we are working (clearly increasing safety) I suggest you edit the file
/etc/apache2/ports.conf so that it contains
Listen 127.0.0.1:80. In this way the site we are working on will be accessible only by typing 127.0.0.1, practically only from the computer on which we are working.
After each installation of a new package that interacts with Apache, you need to restart Apache itself:
sudo / etc/init.d/apache2 restart