How to setup php, mysql, apache and phpMyAdmin on Debian
22-06-2014

How to install and configure php, mysql, apache and phpMyAdmin on Debian
In this tutorial I'll show you how to setup php, mysql, apache and phpMyAdmin on Debian Linux what you need for this is a minimal Debian install if you are not sure how to do that have a look at my tutorial for doing a minimal Debian install here follow that tutorial until you hit the part where you reboot, make sure you don't go through the xorg part or anything that would be useless in a webserver after you reboot come to this tutorial that is where I'm starting from, now lets get on with setting up the server.

So first thing to do is make sure everything's up to date make sure you're logged in as root, you can type su then put your root password in, next fun the following command to make sure everything is up to date.
apt-get update
apt-get upgrade -y
Now everything's up to date we can install the stuff we need run the following commands.
apt-get install apache2
apt-get install php5
apt-get install mysql-server
I'll install phpMyAdmin later as not everyone uses it.

Now to configure apache for php.
The first file you need to edit is /etc/apache2/sites-enabled/000-default so run the following command.
nano /etc/apache2/sites-enabled/000-default
The first thing you need to change in this file is the server admin email so where is says ServerAdmin [email protected] change that to your public email for the server, if you're just setting up apache for programming you can leave it as it is.

If you want to use apache's mod rewrite if you want to use it change AllowOverride None to AllowOverride All.

Now edit /etc/apache2/ports.conf by running the following command.
nano /etc/apache2/ports.conf
Comment out NameVirtualHost *:80 to do this put a # at the start of it like this #NameVirtualHost *:80. After that add ServerName aboredcoder.com:80. You should set where is says aboredcoder.com to your domain name if you're only running apache on localhost though you can change it to 127.0.0.1 or change it to your host name it's not too important if you're only running apache locally a quick example if I was setting this up for this site it would look like this ServerName aboredcoder.com:80 you don't need to put http://.

Next change this "Listen 80" this is the port you want apache to listen on 80 is default and it is probably best to keep it as 80 to set this up you need to set it to your servers ip if you want apache to only run locally set it to 127.0.0.1:80 if you're setting this up for a public webserver change 127.0.0.1 to your servers ip.Now to test it is all working first we need to restart apache so all of the changes we have made work type the following command.
service apache22 restart
The default directory for apache on Debian is /var/www/ so type "nano /var/www/index.php" in there put the following php code.
Save it and then go to the servers address that you are setting up if you are setting this up to run on localhost you can just type in localhost or 127.0.0.1 into a browser and if it shows the php info it's all working and we're done with setting apache and php up.[br][br]If you want to install any php extensions like mysqli etc you can install them with the following command, remove what you do not want.
apt-get install php5-mysql php5-mysqli php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl php5-json
There really is a lot more to setting up apache and php but Debian dose it all automatically for you it annoys me a bit because I'm not used to it I guess, but a lot of people like it mysql-server is also automatically setup that is why while you install it it asks what you want to set the mysql root password as I don't recommend using the root user for a website though you should add a new user for your site to use and limit its privileges as much as possible.

Now for the last part phpMyAdmin this is made very easy by Debian and you really don't have to configure anything at all I do recommend securing phpMyAdmin a bit if you do want to use it though if you're going to use it only enable it when you want to use it then disable it while you are not using it. So to install phpMyAdmin type the following command.
apt-get install phpmyadmin
Now restart apache and it should be working fine.


Name:
*

Email:
*

Website:





Page generated in 0.0067 seconds.