Table of Contents
Install PHP and Required Extensions
Set Up a Web Server (Apache or Nginx)
Test Your Setup with a Simple PHP File
(Optional) Install MySQL and Composer for Full Stack Development
Home Backend Development PHP Tutorial Steps to configure a PHP development environment on Linux

Steps to configure a PHP development environment on Linux

Jun 30, 2025 am 01:57 AM

To set up a PHP development environment on Linux, install PHP and required extensions, set up a web server like Apache or Nginx, test with a PHP file, and optionally install MySQL and Composer. 1. Install PHP and extensions via package manager (e.g., sudo apt install php php-mysql php-curl php-mbstring). 2. Install Apache (sudo apt install apache2) or Nginx and PHP-FPM (sudo apt install nginx php-fpm), then configure and restart the server. 3. Test by creating an info.php file in /var/www/html/ and accessing it via browser. 4. Optionally install MySQL (sudo apt install mysql-server) and secure it, then install Composer for dependency management using the official installer.

Steps to configure a PHP development environment on Linux

Setting up a PHP development environment on Linux is straightforward, especially if you're using a popular distro like Ubuntu. The key is to install the right tools and configure them properly so you can start building and testing PHP applications locally.

Steps to configure a PHP development environment on Linux

Install PHP and Required Extensions

The first step is getting PHP installed on your system. Most Linux distributions have PHP in their package repositories, so you can use the built-in package manager.

Steps to configure a PHP development environment on Linux

On Ubuntu or Debian-based systems, run:

  • sudo apt update
  • sudo apt install php

This installs the core PHP package. However, most projects require additional extensions like php-mysql, php-curl, or php-mbstring. You can install them individually:

Steps to configure a PHP development environment on Linux
  • sudo apt install php-mysql php-curl php-mbstring

Make sure to install the extensions that match your project’s needs — it’s better to install them early than to debug issues later.

Set Up a Web Server (Apache or Nginx)

PHP alone isn’t enough — you need a web server to run PHP scripts through a browser.

For Apache:

Install Apache with:

  • sudo apt install apache2

Then restart Apache after installing PHP to ensure everything loads correctly:

  • sudo systemctl restart apache2

Your PHP files should go into /var/www/html/ by default.

For Nginx:

Install Nginx and PHP-FPM:

  • sudo apt install nginx php-fpm

Then configure Nginx to handle PHP requests. Open your site config file (e.g., /etc/nginx/sites-available/default) and make sure it includes:

location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
}

Restart Nginx afterward:

  • sudo systemctl restart nginx

Both servers work well, but Nginx tends to be more lightweight and efficient for high-traffic setups.

Test Your Setup with a Simple PHP File

Once everything is installed, test your environment to confirm it's working.

Create a simple PHP file:

  • sudo nano /var/www/html/info.php

Add the following content:

<?php
phpinfo();
?>

Save and exit, then visit http://localhost/info.php in your browser. If you see the PHP info page, everything is configured correctly.

If not, check:

  • That the web server is running (systemctl status apache2 or nginx)
  • That the file is placed in the correct directory
  • That PHP modules are enabled if needed

You can delete this file afterward since it exposes system details.

(Optional) Install MySQL and Composer for Full Stack Development

If your project uses a database, installing MySQL or MariaDB is a good idea:

  • sudo apt install mysql-server

Secure it with:

  • sudo mysql_secure_installation

Then create a database and user for your project.

Also, install Composer, the PHP dependency manager:

  • Download with: php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
  • Run the installer: php composer-setup.php --install-dir=/usr/local/bin --filename=composer

Now you can use composer init or install packages like Laravel or Symfony easily.


That’s basically all you need to get a basic PHP development environment up and running on Linux. It’s not complicated, but each step has small details that can trip you up if skipped.

The above is the detailed content of Steps to configure a PHP development environment on Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1503
276
PHP Variable Scope Explained PHP Variable Scope Explained Jul 17, 2025 am 04:16 AM

Common problems and solutions for PHP variable scope include: 1. The global variable cannot be accessed within the function, and it needs to be passed in using the global keyword or parameter; 2. The static variable is declared with static, and it is only initialized once and the value is maintained between multiple calls; 3. Hyperglobal variables such as $_GET and $_POST can be used directly in any scope, but you need to pay attention to safe filtering; 4. Anonymous functions need to introduce parent scope variables through the use keyword, and when modifying external variables, you need to pass a reference. Mastering these rules can help avoid errors and improve code stability.

Commenting Out Code in PHP Commenting Out Code in PHP Jul 18, 2025 am 04:57 AM

There are three common methods for PHP comment code: 1. Use // or # to block one line of code, and it is recommended to use //; 2. Use /.../ to wrap code blocks with multiple lines, which cannot be nested but can be crossed; 3. Combination skills comments such as using /if(){}/ to control logic blocks, or to improve efficiency with editor shortcut keys, you should pay attention to closing symbols and avoid nesting when using them.

How Do Generators Work in PHP? How Do Generators Work in PHP? Jul 11, 2025 am 03:12 AM

AgeneratorinPHPisamemory-efficientwaytoiterateoverlargedatasetsbyyieldingvaluesoneatatimeinsteadofreturningthemallatonce.1.Generatorsusetheyieldkeywordtoproducevaluesondemand,reducingmemoryusage.2.Theyareusefulforhandlingbigloops,readinglargefiles,or

Tips for Writing PHP Comments Tips for Writing PHP Comments Jul 18, 2025 am 04:51 AM

The key to writing PHP comments is to clarify the purpose and specifications. Comments should explain "why" rather than "what was done", avoiding redundancy or too simplicity. 1. Use a unified format, such as docblock (/*/) for class and method descriptions to improve readability and tool compatibility; 2. Emphasize the reasons behind the logic, such as why JS jumps need to be output manually; 3. Add an overview description before complex code, describe the process in steps, and help understand the overall idea; 4. Use TODO and FIXME rationally to mark to-do items and problems to facilitate subsequent tracking and collaboration. Good annotations can reduce communication costs and improve code maintenance efficiency.

Learning PHP: A Beginner's Guide Learning PHP: A Beginner's Guide Jul 18, 2025 am 04:54 AM

TolearnPHPeffectively,startbysettingupalocalserverenvironmentusingtoolslikeXAMPPandacodeeditorlikeVSCode.1)InstallXAMPPforApache,MySQL,andPHP.2)Useacodeeditorforsyntaxsupport.3)TestyoursetupwithasimplePHPfile.Next,learnPHPbasicsincludingvariables,ech

How to access a character in a string by index in PHP How to access a character in a string by index in PHP Jul 12, 2025 am 03:15 AM

In PHP, you can use square brackets or curly braces to obtain string specific index characters, but square brackets are recommended; the index starts from 0, and the access outside the range returns a null value and cannot be assigned a value; mb_substr is required to handle multi-byte characters. For example: $str="hello";echo$str[0]; output h; and Chinese characters such as mb_substr($str,1,1) need to obtain the correct result; in actual applications, the length of the string should be checked before looping, dynamic strings need to be verified for validity, and multilingual projects recommend using multi-byte security functions uniformly.

Quick PHP Installation Tutorial Quick PHP Installation Tutorial Jul 18, 2025 am 04:52 AM

ToinstallPHPquickly,useXAMPPonWindowsorHomebrewonmacOS.1.OnWindows,downloadandinstallXAMPP,selectcomponents,startApache,andplacefilesinhtdocs.2.Alternatively,manuallyinstallPHPfromphp.netandsetupaserverlikeApache.3.OnmacOS,installHomebrew,thenrun'bre

PHP get the first N characters of a string PHP get the first N characters of a string Jul 11, 2025 am 03:17 AM

You can use substr() or mb_substr() to get the first N characters in PHP. The specific steps are as follows: 1. Use substr($string,0,N) to intercept the first N characters, which is suitable for ASCII characters and is simple and efficient; 2. When processing multi-byte characters (such as Chinese), mb_substr($string,0,N,'UTF-8'), and ensure that mbstring extension is enabled; 3. If the string contains HTML or whitespace characters, you should first use strip_tags() to remove the tags and trim() to clean the spaces, and then intercept them to ensure the results are clean.

See all articles