For any dynamic commo website, there should be certain group of software needed in server. A LAMP stack is short form of software groups which stands Linux, Apache, Mysql/MariaDB and PHP/Perl/Python. In this article we will install this group of softwares which is needed to run website.
Prerequisites:
You need to have non-root user account logged in with sudo privileges to set up on your server.
Step 1. Install Apache2 web server.
Apache web server is most popular web server and it is already included in Ubuntu's package manager. So we can install Apache by running this command.
sudo apt-get update
sudo apt-get install apache2
Now you have installed apache server. Now edit your apache2 global configuration file by running following command.
sudo nano /etc/apache2/apache2.conf
Find the following lines in the file and change AllowOverride None to AllowOverride All in the following lines.
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
Change this to bellow content:
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
This will give apache2 server access to read and override /var/www/
directory:
After that save file by pressing shortcut key CTRL + X
and SHIFT + Y
.
Now edit bellow file by running following command.
sudo nano /etc/apache2/sites-available/000-default.conf
Now remove comment or add the following line at bottom and change your domain name instead of www.example.com.
It will make run domain name on /var/www/html
directory:
Now restart apache2 server by running command:
sudo service apache2 restart
Now your apache2 is configured. You can check your apache2 installed by running IP address or domain name in your web browser,
you will see bellow apache2's default page located at /var/www/html/index.html
.
Step 2. Install MySQL
MySQL is open source relational database server that will make your website content dynamic.
Follow these steps to install MySQL server:
sudo apt-get install mysql-server mysql-client libmysqlclient-dev
This command will install mysql-server package in the server.
During installation, it will ask for configuration selection like web server, root user's password.
For web server select apache2 by pressing SPACE
key and for navigation use TAB
key.
Step 3. Install PHP
PHP is open source general-purpose scripting language for dynamic web development. PHP script can be embedded into HTML.
To install PHP, we will use 3rd party repository by Ondřej Surý. Run following command to add PHP repository:
sudo add-apt-repository ppa:ondrej/php
Then update your package list:
sudo apt-get update
Finally install PHP by running following command:
sudo apt-get install php7.2
After that edit /etc/apache2/mods-enabled/dir.conf file.
sudo nano /etc/apache2/mods-enabled/dir.conf
In <IfModule mod_dir.c>
directive put index.php in first position,as seen bellow picture.
It will make apache2 server will load php file first.
To verify if PHP is installed, run the following command:
php --version
There are some most common php modules that needs to be install. Run following command to install PHP 7.2 modules:
sudo apt-get install php7.2-curl php7.2-mbstring php7.2-gd php7.2-zip php7.2-mysql php7.2-xml
In order to make changes in effect, restart the apache2 server by running following command:
sudo systemctl restart apache2
Conclusion
Now you have installed all required softwares to built LAMP stack in Ubuntu server. Now it will use to built common dynamic websites on your server.