Setting Up Your Own LAMP Machine for PHP Development -Setting MySql and PHP

| Comments

<< Previous: Setting up Apache

Well, after setting up the apache http daemon, it’s time for the database management system, the ‘M’ of LAMP.

Installing MySql

It can’t be easier. Just shoot the terminal and type:
sudo apt-get install mysql-server
Yup! That’s it. You’ll get some prompts and will be asked to enter the password for root user (root user of MySql not the Operating System). Just enter the details and that’s all for the MySql.

Removing Mysql from Startup

Yeah, just like Apache daemon, mysql put itself on startup too. And it will not get removed by just running update-rc.d. We need to comment out a couple lines in the mysql.conf file. So, shoot the terminal and do this.



  • sudo kate (or gedit) /etc/init/mysql.conf
  • Comment out the two starting lines (they should say “start on” and something)
That’s it. MySql is now removed from the startup. To run the Mysql daemon after this, use following command
sudo service mysql start


Installing PHP5

After we’ve set Apache and MySql, it is time for the real sexy. Although PHP can be installed via Ubuntu packages with apt-get install php5, but it will install php5.3(.something). That’s no good as we wanna use the latest version. Remember I told you about the inbuilt server provided with php that almost eliminates the need for the Apache server in development environment? It come with PHP5.4 and is not available in PHP5.3. Beside that there are many more awesome features which make it worth installing. So let’s install the latest version of PHP.

Installing Latest PHP in Ubuntu

Shoot the terminal and enter following commands:
sudo add-apt-repository ppa:ondrej/php5
And then update apt-get repository info and install apache php mod, php5 itself and php mysql extension to use mysql with php.
sudo apt-get update
sudo apt-get install php5 libapache2-mod-php5 php5-mysql

Running PHP server (not Apache)

To run the php server instead of Apache, just run following command in terminal.
php -S localhost:8080
This will run a server listening at port 8080. So, we’ll need to go to http://localhost:8080 to run the server. In order to run the server as simply http://localhost, we’ll need to run the server at port 80, and for that we need to run the above command with sudo and 80 instead of 8080. Here’s what I mean:
sudo php -S localhost:80

Benefits of using PHP Server


  • PHP server run as the current working directory as the root server dir. So there is no need to go through the hassle of creating different sites in apache.
  • Running php server helps a lot in debugging by displaying all the messages, errors and warnings in the terminal itself. So no need to change php.ini to enable debugging or use some other method. 
  • It is really cool to use it (don’t know why, but I feel like it is cool :P)
Here’s a snapshot of how it look when running php server.




Comments