Comprehensive Guide to PHP, Apache, and MySQL Installation on Ubuntu

Step-by-Step Guide :  Installing PHP with Apache Server and MySql on Ubuntu.


Welcome to my comprehensive guide on setting up a web development environment with PHP, Apache, and MySql on your Ubuntu machine. This tutorial will walk you through each step, allowing you to create web applications effortlessly.

Open a terminal and ensure your system is up to date.

In terminal write following commands:

1) Install Apache Web Server

Apache is a popular web server. Install it using command `sudo apt install apache2`



After writing command enter your password and press Enter.
Note : it won't show password.
it will ask to continue - press y and Enter.
now files will start downloading.


2) Verify Apache Server

After installation, start Apache and check its status by writing command `sudo systemctl start apache2`

after writing command Open a web browser and navigate to 'https://localhost/' to ensure Apache is running. You should see the default Apache landing page.


3) Install PHP and Modules

Install PHP and necessary modules for Apache and MySql :
`sudo apt install libapache2-mod-php -y`



Now restart apache server by writing command :
`sudo systemctl restart apache2`

4) Verify PHP installation

to test php write command :
`sudo gnome-text-editor var/www/html/phpinfo.php`
This will open gnome-text-editor 

In text-editor write <?php phpinfo() ?> and save it.
Now open a brwoser and write `localhost/phpinfo.php`




5) Install MySql Server

Open a terminal again and write below following command to install MySql.
`sudo apt install mysql-server`



Now write `sudo apt install mysql-client` command


Write following commands 





Congratulations! You've successfully set up PHP with Apache server and MySql on your Ubuntu machine.

Here's a Sample Demo Program :

Open a terminal and navigate to the desired directory where you want to create PHP file using
`cd /var/www/html/`

Create a new file and save it with a `.php` extension by writing 
`sudo touch demo.php`

open gnome-text-editor
`sudo gnome-text-editor /var/www/html/demo.php`

Inside php file,


Now run PHP script by typing :
`php demo.php` 
Or open browser and type localhost/demo.php.




Comments

Popular posts from this blog