In this article we are showing how to create a development environment for your PHP + MySQL projects. LAMP is acronym for Linux, Apache2, MariaDB, PHP. I would suggest LAMP stack for the development of powerful CMS such as WordPress, Drupal, Magento.
So this tutorial make sure you have the development environment ready for your next project.
Install Apache2 htpp server
Run the below commands to upgrade your Ubunutu new packages
sudo apt-get update
sudo apt-get upgrade
Now we are ready to install Apache2
sudo apt install apache2
Next, run the below command to start apache
sudo systemctl start apache2.service
To start Apache2 at startup , even if you reboot your server, runt the below command.
sudo systemctl enable apache2.service
Next, we can check our Apache installation in browser.
visit http://localhost or http://ipaddress , if you are seeing the below screen, your installation is success.
Install MariaDB Database server
MySQL server was the popular database server for a while, but now MariaDB is taken over.
Run the following command to install the MariaDB server
sudo apt-get install mariadb-server mariadb-client
After installing MariaDB you can use the below commands to stop, start MariaDB services.
sudo systemctl stop mysql.service
sudo systemctl start mysql.service
Run the below command to auto start the MariaDB service at the event of reboot.
sudo systemctl enable mysql.service
After that, run the commands below to secure MariaDB server by creating a root password and disallowing remote root access.
When prompted answer the below questions
- Enter current password for root (enter for none): Just press the Enter
- Set root password? [Y/n]: Y
- New password: Enter password
- Re-enter new password: Repeat password
- Remove anonymous users? [Y/n]: Y
- Disallow root login remotely? [Y/n]: Y
- Remove test database and access to it? [Y/n]: Y
- Reload privilege tables now? [Y/n]: Y
Restart the mysql service
sudo systemctl restart mysql.service
Next, we can test our mysql installtion, run the below command and enter your password when it prompted.
sudo mysql -u root -p
If it’s successful you will see MariaDB welcome message
Install PHP 7
PHP 7.1 is not a default in Ubuntu 16.04 , we have to get it from third party libraries .
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php
Then update and upgrade to PHP 7.1, this is a mandatory step as all the required modules should upgrade.
sudo apt update
Run the below commands to install the required modules
sudo apt install php7.1 libapache2-mod-php7.1 php7.1-common php7.1-mbstring php7.1-xmlrpc php7.1-soap php7.1-gd php7.1-xml php7.1-intl php7.1-mysql php7.1-cli php7.1-mcrypt php7.1-zip php7.1-curl
Now you are installed php7.1. Next, we can create phpinfo file test our PHP installtion
sudo nano /var/www/html/phpinfo.php
And inset the below code in the file
<?php phpinfo( ); ?>
Run the following url in browser
You will a screen such as below
This is how to install LAMP with Ubuntu 16.04 LTS Server.
I’ve used 1GB RAM Digitalocean droplet for the demo.