Install LAMP
LAMP is common and popular web service stack. You can use LAMP for building dynamic web sites and web applications.
LAMP is acronym:
L
stands for Linux operating system.A
stands for Apache HTTP Server.M
stands for MySQL relational database or its fork MariaDB.P
stands for PHP PHP programming language.
In this tutorial, we will see how to prepare ubuntu for PHP development.
step 1 - Install apache2 package
user@demo:~# sudo apt install -y apache2
...
step 2 - Install mariadb package
user@demo:~# sudo apt install -y mariadb-server
...
step 3 - Install PHP and mod-php
We install PHP and mod-php apache2 module which allow to serve PHP pages.
user@demo:~# sudo apt install -y php libapache2-mod-php
...
step 4 - Install commnon php extensions
user@demo:~# sudo apt install -y php-mysql php-dom php-zip
...
step 5 - Install composer
Composer is the defacto dependency management tool for PHP and have gain popularity with PHP developers, Let’s install it.
user@demo:~# sudo apt install -y composer
step 6 - Install phpMyAdmin
While you can use mysql command line client or mysql workbench visual tool for database administration, I prefer to use phpMyAdmin web application for this task. Let’s install it.
user@demo:~# sudo apt install -y phpmyadmin
Follow the install wizard:
| Please choose the web server that should be automatically configured to │
│ run phpMyAdmin. │
│ │
│ Web server to reconfigure automatically: │
│ │
│ [*] apache2 │
│ [ ] lighttpd │
│ │
Select apache2 and click OK
| The phpmyadmin package must have a database installed and configured │
│ before it can be used. This can be optionally handled with │
│ dbconfig-common. │
│ │
│ If you are an advanced database administrator and know that you want to │
│ perform this configuration manually, or if your database has already │
│ been installed and configured, you should refuse this option. Details on │
│ what needs to be done should most likely be provided in │
│ /usr/share/doc/phpmyadmin. │
│ │
│ Otherwise, you should probably choose this option. │
│ │
│ Configure database for phpmyadmin with dbconfig-common? |
Click Yes.
Now provide the the password and verify
│ Please provide a password for phpmyadmin to register with the database │
│ server. If left blank, a random password will be generated. │
│ │
│ MySQL application password for phpmyadmin: |
| Password confirmation: |
We want to phpmyadmin to serve at port 8080. To do so, Edit /etc/phpmyadmin/apache.conf
:
- Comment the exising directives at the begining of the file (alias and directory)
- Add the virtual host and Listen directives
# phpMyAdmin default Apache configuration
## Alias /phpmyadmin /usr/share/phpmyadmin
## <Directory /usr/share/phpmyadmin>
## Options SymLinksIfOwnerMatch
## DirectoryIndex index.php
## # limit libapache2-mod-php to files and directories necessary by pma
## <IfModule mod_php7.c>
## php_admin_value upload_tmp_dir /var/lib/phpmyadmin/tmp
## php_admin_value open_basedir /usr/share/phpmyadmin/:/etc/phpmyadmin:/var/lib/phpmyadmin/:/usr/share/php/php-gettext/:/usr/share/php/php-php-gettext/:/usr/share/javascript/:/usr/share/php/tcpdf/:/usr/s>
## </IfModule>
## </Directory>
# Disallow web access to directories that don't need it
<Directory /usr/share/phpmyadmin/templates>
Require all denied
</Directory>
<Directory /usr/share/phpmyadmin/libraries>
Require all denied
</Directory>
Listen 8080
<VirtualHost *:8080>
TransferLog "/var/log/apache2/phpmyadmin_access.log"
ErrorLog "/var/log/apache2/phpmyadmin_errors.log"
DocumentRoot "/usr/share/phpmyadmin"
</VirtualHost>
Now restart apache2
user@demo:~# sudo service apache2 restart
Now you can connect to phpmyadmin at port 8080.
step 7 - Start Developing
Now , we can start develop our site in PHP.
Your document root is under /var/www/html.
Let’s check whether we successfully configure apache. Open /var/www/html/main.php in favorite editor and enter the following content:
<?php phpinfo()
Now, access http://demo/main.php in your webbrowser. You should see the familiar page: