Web development works are now very easier with the use of various open source application. One of the open source web development platform for Linux operating system is LAMP. LAMP indicates Linux (operating system), Apache (web server), MySQL (database server) and PHP (web scripting language) together as a web development stack. Web developers can easily install Apache, MySQL, and PHP based on the operating system to do all web development task locally. This article will help to install and test LAMP in Ubuntu 17.04.
Update Operating System
You need to update your operating system before starting any installation process. Open the terminal by pressing “Ctrl+Atl+T” and type the update command to do the task.
$ sudo apt-get update
Install Apache
To install Apache2 web server type the following command.
$ sudo apt-get –y install apache2
The following output will be shown if the apache server will install without any error.
Go to the browser and type http://locahost to test web server is working properly or not. If the following screen appears then the web server is working.
Install PHP 7
To install php 7 and others necessary PHP extensions type the following command from the terminal.
$ sudo apt-get install php7.0-fpm php7.0-mysql php7.0-common php7.0-gd php7.0-json php7.0-cli php7.0-curl libapache2-mod-php7.0
After the PHP installation, the following screen will appear.
Now test PHP installation. You have to create a PHP file under /var/www/html directory for the test. Only root user can access this folder by default. So set all for this folder by chmod command.
$ sudo chmod 777 /var/www/html
Type the following command to create phpinfo.php file using nano editor.
$ sudo nano /var/www/html/phpinfo.php
Type following PHP code in the editor to get all configuration information of the server.
<?php
phpinfo();
?>
phpinfo() is a built-in PHP function to get server related all information.
Press “ctrl+x” to save the file after writing the code. Type “y” and press enter to save the file. Now open any browser and type http://localhost/phpinfo.php to run the file. If the file is executed properly then the following output will be shown.
Install MariaDB 10
You can install MySQL 5.6 or MariaDB 10 in this step as a database server. MariaDB has more features than MySQL 5.6. MariaDB installation process is shown here. Type the following command to install MariaDB.
$ sudo apt-get install mariadb-server mariadb-client
After installation, the following screen will appear in the terminal.
Now check the current status of database server by typing the following command.
$ sudo systemctl status mysql
If the database server not working properly then type the following command to start the server.
$ sudo systemctl start mysql
Next step is to create root password for the database server and set other necessary settings. You can set empty password as root password. So type new root password for two times for confirmation.
Next, it will ask for other settings. Just type Enter in every step.
Type the following command and give your previously created root password to check your MySQL root password is working.
$ sudo mysql –u root –p
If the database server can connect successfully then it will show the following information. You can now do any database related operation from this prompt. Type exit to quit from the server.
You can easily create your local server on Ubuntu by using the above commands and deploy your web application to test before publishing in real hosting server.