How to Install Apache, PHP, PostgreSQL, MySQL in Ubuntu Server 17.04 from command line
Mini Bytes: Ubuntu 17.04 was released and most of the users are still struggling to install Apache, PHP, PostgreSQL or MySQL in the latest version of Ubuntu Server 17.04. Since Ubuntu 17.04 does not have GUI version (if needed we need to install the packages manually) we are going to install all the above mentioned packages through command line. I have tested all the below used commands in the Ubuntu Server 17.04 and i don’t tell that these commands may not work in another version of Ubuntu. You can try at your own risk in a non production server.
As the first step, we can see how to install and configure the web server and later on we can move to the further configurations. We need to install Apache at first because, later on while installing the database and the PHP server packages, they need to download the dependencies for the web server. To avoid any contingencies, as a first step we are installing the Apache Server.
How to install Apache:
sudo apt-get update
sudo apt-get install apache2
Basic Apache Configuration:
After installing the Apache server, you need to adjust the firewall setting to allow port 80 & port 443 to access the web server. To do this you need to follow the below steps.
sudo ufw app list
Running the above command will list the firewall applications like below.
Apache Full</code> ...
here you need to select “Apache Full”, its because Ubuntu firewall will allow Port 80 & 443 while enabling this option. You can enable this option by running the command below.
sudo ufw allow 'Apache Full'
After running the command successfully, make sure to check your Ubuntu firewall, whether it allows the “Apache Full” application. Below command can be used to check the status of the Ubuntu firewall.
sudo ufw status
Note: You can also disable the Ubuntu firewall for time-being to check the status of the Apache server. But it was not considered as a best practices. But i will give you the command to disable the firewall. “sudo ufw disable“. Running this command will disable the firewall from startup too.
After completing the above all task, you you need to restart the Apache service and check its status whether it was running status.
sudo systemctl restart apache2
sudo systemctl status apache2
In order to enable Apache service to start at the startup, you need to enable the service using the systemctl command.
sudo systemctl enable apache2
Its all done, not you can access your web server using the server’s IP address.
Config file location:
In order to make changes to you Apache server you need to change the default configurations in the config file. Regarding the configurations i will share you in another post. Below is the config file locations.
- /etc/apache2/apache2.conf -> Apache global configuration file.
- /etc/apache2/ports.conf -> Apache port configuration file.
Logs file location:
- /var/log/apache2/access.log -> Apache access log.
- /var/log/apache2/error.log -> Apache error log.
How to Install PHP 5.6:
Since PHP 5.6 is the stable version and contains most of the library files in this article i am going to show you how to install PHP 5.6 in the Ubuntu Server 17.04. Trust me we can use PHP 7 but we are still lack of many library files for the latest version of the PHP. They are still in development basis. For all my web projects i am still using PHP 5.6 only.
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt install php5.6
Above command will add the respected repositories in your server and later after doing an update, you can install the PHP 5.6. In order to install the PHP 7.1, you need to run first 3 command in your Ubuntu server and later on you need to run the below command to install the latest version of PHP.
sudo apt-get install php7.1
After successfully completing the installation of PHP, in order to check the PHP version simple run the below command.
Now both your Apache and PHP server was ready to use.
How to Install PostgreSQL in Ubuntu:
PostgreSQL is one of the most powerful database system which was used in most of the enterprise currently.