Score:0

practice php on ubuntu laptop

by flag

I only have a laptop with ubuntu 20.04 installed.
I am anxious to learn php but the book I have only explains how to install php and set up local server for Window and Mac users. I found a stack overflow page that explains how but it is 10 years old and I decided to ask this question.
So could you please explain how I can set up a local server and practice and test php programming?

muru avatar
us flag
Does this answer your question? [What's the easiest way to set up a LAMP stack?](https://askubuntu.com/questions/34/whats-the-easiest-way-to-set-up-a-lamp-stack)
Score:1
in flag

There are three things you will need for this:

  1. an Internet connection (to install software)
  2. Apache
  3. PHP

Here's how you can get a bare minimum installed and running on your system:

  1. Open Terminal (if it's not already open)
  2. Update apt:
    sudo apt update 
    
  3. Install Apache:
    sudo apt install apache2
    
  4. Test Apache works by opening a browser and visiting http://127.0.0.1. You should see something that looks like this: Apache Test Page
  5. Install PHP (and some common development libraries):
    sudo apt install php libapache2-mod-php php-dev php-xml php-json php-mbstring
    
  6. Restart Apache:
    sudo service apache2 restart
    
  7. Create a test file in the Apache root directory:
    sudo nano /var/www/html/testing.php
    
  8. Paste the following into the new file:
    <?php phpinfo(); ?>
    
  9. Test PHP works by visiting http://127.0.0.1/testing.php in your browser. You should see something like this: PHP Info Your version number will likely be a bit different, as this was done on a 21.10 installation.
  10. Start learning PHP

That's all there is to a basic setup with just Apache and PHP.

Score:1
in flag

Use the builtin webserver from php:

Installation:

sudo apt install php-cli

Usage (From inside your test projects directory):

php -S localhost:8000

Then point your browser to localhost:8000.

It will automatically load the index.php file if there is any. You can create it with any text editor and start programing:

<html>
 <head>
  <title>PHP Test</title>
 </head>
 <body>
 <?php echo '<p>Hello World</p>'; ?> 
 </body>
</html>
Taro avatar
by flag
how can i stop the builtin server?
pLumo avatar
in flag
You can stop it with normal job control. So, if you started it in foreground, you can stop it with Ctrl + C.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.