Setting up a LAMP development workstation using Ubuntu
No doubt Ubuntu and its variations are some of the most popular Linux distributions nowadays. This distributions, as well as other like OpenSuse and Mandriva had changed the image of GNU/Linux, early perceived as a system that's difficult to use and manage, only accessible to geeks.
Now the average user can see benefits in replacing proprietary operating systems with open source equivalents. Corporations from the start-up to the big tech companies are seeing advantages using GNU/Linux in their computers, ranging from stability and speed to the more obvious feature: cost.
Following the popularity of the Linux operating system comes the popularity of the PHP programming language, often tied with the Apache web server and MySQL database management system. This setup is often called “LAMP”, which stands for “Linux+Apache+MySQL+PHP”, or something like that.
I'll describe the steps required to get a LAMP development environment up and running. But I expect that you have the operating system installed, as I will not cover Ubuntu installation.
Installing Apache 2
PHP 5 can run in command-line, and you can create almost any type of software using it. But for websites and web applications, you need to run your scripts through a web server. Apache is the most natural option. That's why LAMP has an “A”.
Install it using apt-get. Apt-get will take care of any dependencies needed. Make sure you use “sudo” to run with super-user privileges.
# sudo apt-get install apache2
Apache is now installed and it's default document root is /var/www. Document root is the directory where the website files will be located. You can simply save your files under this directory and they will be accessible through http://localhost/.
Installing PHP 5
Apt-get will help us install PHP 5 as well as it did on Apache installation.
On the same command we can install also the libraries needed for PHP to access MySQL databases (package php5-mysql). Without this package, you can have MySQL running on the same machine you already have PHP, but PHP will be unable to access it.
# sudo apt-get install php5 php5-mysql libapache2-mod-php5
At this moment you can install other PHP extensions, if needed. They as packaged using names like php5-EXTENSION. For example, you can install GD library including php5-gd into the list of packages apt-get will install.
You guess it right. Apt-get will get MySQL server and client installed in your system, just as it did with other packages.
# sudo apt-get install mysql-server mysql-client
The mysql-client package will install the command-line mysql client. Most people don't like this kind of interface. You can be more productive using PHPMyAdmin, a browser-based MySQL management tool. Install it by running:
# sudo apt-get install phpmyadmin
PHPMyAdmin will be installed in the subdirectory phpmyadmin of your document root, which means that it's accessible via the address:
Setting MySQL root password
After MySQL installation, you have to set the root password. Don't confuse it with the system user root. On the typical Ubuntu install root not even have a password. The MySQL root user needs to have a password set, and this user will be used for any management operations on MySQL.
Set a root password by running:
# sudo mysqladmin password NEW_PASSWORD
The command will work this way only on the first run, when you do not have a password. After you have a password set, mysqladmin will require your current username and password to change the password, for obvious security reasons.
If you need to change the MySQL root password later, use the following command:
# sudo mysqladmin password -u root -pCURRENT_PASSWORD NEW_PASSWORD
Note that there are no spaces between “-p” parameter and your current password.
Team working and web applications
If you work with other people in the same network, of course you can barely follow this same steps on every machine and have several stand-alone development workstations. But it's not the optimum setup. I have some additional piece of advice on setting up a group of development machines.
Have a CVS or another version control system
It's not only for web development. CVS (or any similar version control system, like Subversion) is a must-have for any development team. Without version control, manage who have the most updated version of each single file is the hell. And when two or more developers happen to change the same file, you have a problem that's nearly to impossible to resolve.
Use a single database server
Development can be simpler by having just one database server and all other machines in the network accessing them. Having just one database takes from your hands the responsibility of synchronize the databases between all the development machines.
Other benefit of this setup is that you turn your environment more homogeneous. With the same code, developers can reproduce situations that other developers find to be tricky, and you eliminate the “this doesn't happen on my machine” problem.
An exception to the rule occurs when the development process includes constant drastic changes to the database, frequent drops and backup restore. In other words, when a developer leaves the database useless for the others. This situation can be solved by having a separate database for the user who need to do this operations. If all (or most) developers have this behavior, may be better just stick with the traditional approach (everyone has its own database server).
Setting MySQL privileges
If you decided to have a single database server, you can have a machine just for doing that or simply elect one of the developer's workstation for that, if the load will not be a problem for its owner.
Whatever the case, you have to do some additional setup to get this to work. MySQL by default doesn't allow connections from other machines. Here we go:
- Edit the file /etc/mysql/my.cnfYou can do it by typing on command-line:sudo gedit /etc/mysql/my.cnf (on Ubuntu)orsudo kwrite /etc/mysql/my.cnf (on Kubuntu)
- Uncomment the following line:# bind-address = 127.0.0.1You uncomment it by removing the “#” character on the beginning of the line.
- Now you have to grant the users' privileges again, but allowing them to connect from other machines. You were used to grant privileges like this:GRANT ALL PRIVILEGES ON database.* TO user IDENTIFIED BY 'password';Now you need to do:GRANT ALL PRIVILEGES ON database.* TO 'user'@'%' IDENTIFIED BY 'password';The '%' wildcard means that the username “user” can connect from any IP address. You can specify the addresses you want, or even ranges, by using for example “192.168.1.%”. But for a local network, “%” will be OK.
More by this Author
No comments yet.