Howto: Setup Apache, PHP and MySQL
Something every developer should have. One can’t just put his development work online for testing purposes. That’s where an Integrated Development Environment comes in handy. Before publishing websites (or anything else for that matter), one should have tested the whole website locally on his or her computer. This tutorial will guide you through some easy steps to install an Integrated Development Environment (IDE) in Linux. This guide is written with Ubuntu as linux distribution in mind, but other distributions should have similar install instructions. Just replace apt-get install
with your package installer and corresponding package name in the repositories. After following these steps you will have Apache, PHP and MySQL working on your local linux machine. It is not meant to serve as a web server. You’ll want to take some extra security measures.
Install Apache 2
sudo apt-get install apache2
Install PHP 5
sudo apt-get install php5
Install MySQL 5
sudo apt-get install mysql-server
sudo apt-get install libapache2-mod-auth-mysql
sudo apt-get install php5-mysql
I also recommended you to install phpMyAdmin to access your SQL database easily via your web browser:
sudo apt-get install phpmyadmin
Configuring MySQL
For the default configuration of MySQL you can use this command:
cd /usr
sudo ./bin/mysql_install_db --user=mysql
To access MySQL with the root user type:
sudo mysql -u root
By default, there is no password set for the root user. This is absolutely NOT recommended, so we will set a password for root:
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('yourpassword');
with yourpassword being the password you want to have (deuh!….)
For normal use it is advised to create a regular user. To create a new user:
mysql> GRANT PRIVILEGE1, PRIVILEGE2 ON *.* TO 'yourusername'@'localhost' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION;
with yourusername, yourpassword, privilige1 and privilige2 the user, password and privileges you want.
Configuring Apache
To set your user as the php administrator:
gksudo gedit /etc/apache2/apache2.conf
and find the line that starts with “User” and “Group”. Change it to the user and group you work with. Now restart apache:
sudo /etc/init.d/apache2 restart
Let MySQL work with PHP
gksudo gedit /etc/php5/apache2/php.ini
and remove “;” in front of the line “;extension=mysql.so” and restart apache again:
sudo /etc/init.d/apache2 restart
Now everything is set and should be working. You can access your server by typing http://localhost or http://127.0.0.1 in your web browser. The directory for your web files is /var/www or /srv/http depending on your linux distribution.