I'm a web developer, developing website using PHP, MySQL, and CakePHP. I used to develop on windows machine using XAMPP, which is pretty great if you are working on windows machines. But what if you are like me using Ubuntu machine and want to develop websites, it doesn't make any sense to use LAMPP environment while Ubuntu provides everything at your hands with few buttons pressed.
Actually, I made that mistake at first and it wasn't easy and I faced a lot of problems and everything wasn't running smoothly as I expected and an expert friend of mine, told me "Why use LAMPP when you are using Ubuntu?!!" -- so I said he's right, what the heck!!
After some search trials, I found a video on youtube, it was good but yet it didn't contain all the details to keep everything up and running smoothly.
First of all, I assume you have uninstalled and removed any instance of Apache web server, PHP and MySQL. Then, let's start installing first things first:
1. Apache The Web server:
Open a terminal and write the below code:
sudo apt-get install apache2
then, wait for it to download all the packages and installs the Apache2. To make sure that the Apache server was installed correctly, open any web browser and go to http://localhost, if the content is saying it works then you are good to go!! Nice work
2. Install PHP
2.1. Write the code below
sudo apt-get install php5 libapache2-mod-php5
2.2. You have to restart the Apache to apply the changes after the PHP installation, and to do so write the following code:
sudo /etc/init.d/apache2 restart
If you get the following message while trying to restart the Apache, then do the following:
* Restarting web server apache2 apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
... waiting apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
... waiting apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
a. Go to the following path:
/etc/apache2/
b. Edit the configuration file for Apache named "apache2.conf":
sudo gedit apache2.conf
c. Alter the following section to be:
before:
### Section 1: Global Environment
#
# The directives in this section affect the overall operation of Apache,
# such as the number of concurrent requests it can handle or where it
# can find its configuration files.
#
# The directives in this section affect the overall operation of Apache,
# such as the number of concurrent requests it can handle or where it
# can find its configuration files.
after:
### Section 1: Global Environment
#
# The directives in this section affect the overall operation of Apache,
# such as the number of concurrent requests it can handle or where it
# can find its configuration files.
ServerName localhost
#
# The directives in this section affect the overall operation of Apache,
# such as the number of concurrent requests it can handle or where it
# can find its configuration files.
ServerName localhost
this will define the name of your localhost IP for the web server, now if you try to restart the Apache you will find no errors or warnings.
2.3. Back to PHP, to make sure that PHP was installed correctly you can do the following:
a. Go to the web root directory which is in
cd /var/www/
b. Edit a new file
gedit phptrial.php
c. And write in it the following:
<?php
phpinfo();
?>
phpinfo();
?>
d. Save the file and go to your browser, write the following address http://localhost/phptrial.php, if you see a large purple table containing information about the PHP installed on your machine, then you are on the right track proceed to the next!!
3. Install MySQL Server
sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql
Half way the installation, a screen will appear in your terminal asking you for a password for the database, it should be like this
If you want to enter a password then enter one, and you will be prompted to confirm it, if not just leave it blank and hit enter. The screen will appear once again since you didn't enter a password in first place, so don't worry, this is a normal behavior. After this your MySQL is installed and working. Now it is time for the PHPMyAdmin!!
4. Installing PHPMyAdmin
a. In your terminal, execute this
sudo apt-get install phpmyadmin
b. It will ask you on which web server you will be running the PHPMyAdmin, choose what suits you from either Apache or Lightpd
b. It will ask on how you want to configure the PHPMyAdmin
c. Then it will ask you to add a password for the administrative account to use the MySQL database, it is up to if you want to leave it blank or not
d. A confirmation message then will appear
If you chose a blank password for the PHPMyAdmin administrative account, then you should do the below step, if no, then skip it
e. Go to the following directory, which contains the PHPMyAdmin configuration file
run in the terminal
cd /etc/phpmyadmin
then edit the configuration file
sudo gedit config.inc.php
and uncomment the following line
// $cfg['Servers'][$i]['AllowNoPassword'] = TRUE;
After finishing all the above steps, you will have everything up and running perfectly smoothly. Now, try to add a project to your /www/ web directory and visit it through your browser, Holy Crap!!! .. There is no styling applied and your folders are not rewritable.
Don't panic, this is normal, you have to enable the mod_rewrite module for the Apache.
This is how you will do it
1. Run this to install the rewrite module for apache
sudo a2enmod rewrite
2. Edit the Apache configuration file
browse to the following directory
cd /etc/apache2/sites-enabled/
then edit the following file
sudo gedit 000-defaultCheck
and change the following sections to be as written below
DocumentRoot /var/www/ <Directory />
Options FollowSymLinks
AllowOverride all
</Directory>
<Directory /var/www/>
Options FollowSymLinks
AllowOverride all
Order allow,deny
allow from all
</Directory>
Options FollowSymLinks
AllowOverride all
</Directory>
<Directory /var/www/>
Options FollowSymLinks
AllowOverride all
Order allow,deny
allow from all
</Directory>
Well this is the last and final step in our journey in setting your Ubuntu machine to be a web and database server.
Everything should be up and running now very smoothly, if you have any problems I would like to help.
Now let's start some development!!!