Php mysql debian server at

How to install Apache, PHP and MySQL on Debian 12 or 11

Combined Apache, PHP, and MySQL create a basic but popular web development stack known as LAMP (Linux, Apache, MySQL, PHP). This open-source stack is widely used for building PHP-based web applications and websites. In this, article we will discuss the commands used to install the LAMP server on Debian 12 Bookworm or 11 Bullseye.

LAMP comprises a Linux OS running Apache, PHP, and MySQL. Apache is a popular open-source web server managing millions of websites to deliver content over the Internet. It is highly scalable web server software with support for multiple operating systems, such as Linux, Windows, and macOS.

Whereas PHP (Hypertext Preprocessor) is not some unknown programming server-side scripting language, instead it has been used by most web developers around the globe. Often developers used it in combination with a web server such as Apache, Nginx, and more.

Further, PHP language apps can interact with various database systems to store data including MySQL or MariaDB. Well, MySQL is also an open-source relational database management system (RDBMS) widely used to store data for web applications, content management systems (CMS), and e-commerce websites.

Читайте также:  How to write json file in python

1. Update the Debian 12 or 11 Server

The first step you should follow on the Debian server or desktop is to make sure the system is up to date. Therefore, on your command terminal run the given command which refreshes the APT package index cache as well.

sudo apt update && sudo apt upgrade -y

2. Install the Apache Web server

Next, we will install the Apache web server packages that are available to download using the default APT package manager of both Debian 12 and 11.

3. Start and Enable Apache Service

After completing the installation process, let’s start and also enable the Apache service so that it can start automatically every time we reboot our system or in case it gets crashed.

sudo systemctl start apache2
sudo systemclt enable apache2

To confirm the service status, use:

4. Install PHP on Debian 12 or 11

The default version of PHP to install on Debian would not be the latest one. For example, while doing this article, for Bookworm version 12 the PHP was 8.2, and for 11 Bullseye- PHP7.4.

So, if you want to go for the system’s default PHP versions, then you just need to run:

Whereas common PHP extensions can use:

(optional) Now, if you want to have the latest available version of PHP, if not available on your Debian then use a third-party repository called Sury.

Download GPG key

sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg

Add the Sury.org repository.

sudo sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'

Run system update

After that run the default command we have shown at the beginning of this step.

5. Install MySQL/MariaDB Server

Those who want the complete stack of LAMP servers also have to install MYSQL or MariaDB. And to do that we need to execute the command as mentioned below:

Unfortunately, MySQL is not available by default to install from the Debian 11 and 12 repositories, therefore, first, we need to configure it manually. See our article: How to install MySQL on Debian 11 or 12.

However, we recommend using MariaDB because it is a fork of MySQL and works exactly like MySQL.

sudo apt install mariadb-server

Other Articles:

Источник

How To Install Linux, Nginx, MySQL, PHP (LEMP stack) on Debian 9

How To Install Linux, Nginx, MySQL, PHP (LEMP stack) on Debian 9

The LEMP software stack is a group of software that can be used to serve dynamic web pages and web applications. This is an acronym that describes a Linux operating system, with an Nginx web server. The backend data is stored in the MySQL database and the dynamic processing is handled by PHP.

In this guide, you’ll install a LEMP stack on a Debian server using the packages provided by the operating system.

Prerequisites

To complete this guide, you will need a Debian 9 server with a non-root user with sudo privileges. You can set up a user with these privileges in our Initial Server Setup with Debian 9 guide.

Step 1 — Installing the Nginx Web Server

In order to display web pages to our site visitors, we are going to employ Nginx, a modern, efficient web server.

All of the software we will be using for this procedure will come directly from Debian’s default package repositories. This means we can use the apt package management suite to complete the installation.

Since this is our first time using apt for this session, we should start off by updating our local package index. We can then install the server:

On Debian 9, Nginx is configured to start running upon installation.

If you have the ufw firewall running, you will need to allow connections to Nginx. You should enable the most restrictive profile that will still allow the traffic you want. Since we haven’t configured SSL for our server yet, in this guide, we will only need to allow traffic on port 80 .

You can enable this by typing:

You can verify the change by typing:

You should see HTTP traffic allowed in the displayed output:

Output
Status: active To Action From -- ------ ---- OpenSSH ALLOW Anywhere Nginx HTTP ALLOW Anywhere OpenSSH (v6) ALLOW Anywhere (v6) Nginx HTTP (v6) ALLOW Anywhere (v6)

Now, test if the server is up and running by accessing your server’s domain name or public IP address in your web browser. If you do not have a domain name pointed at your server and you do not know your server’s public IP address, you can find it by typing one of the following into your terminal:

This will print out a few IP addresses. You can try each of them in turn in your web browser.

Type one of the addresses that you receive in your web browser. It should take you to Nginx’s default landing page:

Nginx default page

If you see the above page, you have successfully installed Nginx.

Step 2 — Installing MySQL to Manage Site Data

Now that we have a web server, we need to install MySQL, a database management system, to store and manage the data for our site.

You can install this easily by typing:

Note: In Debian 9 a community fork of the MySQL project – MariaDB – is packaged as the default MySQL variant. While, MariaDB works well in most cases, if you need features found only in Oracle’s MySQL, you can install and use packages from a repository maintained by the MySQL developers. To install the official MySQL server, use our tutorial How To Install the Latest MySQL on Debian 9.

The MySQL database software is now installed, but its configuration is not complete.

To secure the installation, we can run a security script that will ask whether we want to modify some insecure defaults. Begin the script by typing:

You will be asked to enter the password for the MySQL root account. We haven’t set this yet, so just hit ENTER . Then you’ll be asked you if you want to set that password. You should type y then set a root password.

For the rest of the questions the script asks, you should press y , followed by the ENTER key at each prompt. This will remove some anonymous users and the test database, disable remote root logins, and load these new rules so that MySQL immediately respects the changes you have made.

At this point, your database system is now set up and secured. Let’s set up PHP.

Step 3 — Installing PHP for Processing

We now have Nginx installed to serve our pages and MySQL installed to store and manage our data. However, we still don’t have anything that can generate dynamic content. That’s where PHP comes in.

Since Nginx does not contain native PHP processing like some other web servers, we will need to install fpm , which stands for “fastCGI process manager”. We will tell Nginx to pass PHP requests to this software for processing. We’ll also install an additional helper package that will allow PHP to communicate with our MySQL database backend. The installation will pull in the necessary PHP core files to make that work.

Then install the php-fpm and php-mysql packages:

We now have our PHP components installed. Next we’ll configure Nginx to use them.

Step 4 — Configuring Nginx to Use the PHP Processor

Now we have all of the required components installed. The only configuration change we still need is to tell Nginx to use our PHP processor for dynamic content.

We do this on the server block level (server blocks are similar to Apache’s virtual hosts). We’re going to leave the default Nginx configuration alone and instead create a new configuration file and new web root directory to hold our PHP files. We’ll name the configuration file and the directory after the domain name or hostname that the server should respond to.

First, create a new directory in /var/www to hold the PHP site:

Then, open a new configuration file in Nginx’s sites-available directory:

This will create a new blank file. Paste in the following bare-bones configuration:

server < listen 80; listen [::]:80; root /var/www/your_domain; index index.php index.html index.htm; server_name your_domain; location / < try_files $uri $uri/ =404; >location ~ \.php$ < include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; >> 

This is a very basic configuration that listens on port 80 and serves files from the web root we just created. It will only respond to requests to the name provided after server_name , and any files ending in .php will be processed by the php-fpm process before Nginx sends the results to the user.

Save and close the file when you’re done customizing it.

Activate your configuration by linking to the config file from Nginx’s sites-enabled directory:

This will tell Nginx to use the configuration next time it is reloaded. First, test your configuration for syntax errors by typing:

If any errors are reported, go back and recheck your file before continuing.

When you are ready, reload Nginx to make the changes:

Next we’ll create a file in our new web root directory to test out PHP processing.

Step 5 — Create a PHP File to Test Configuration

Your LEMP stack should now be completely set up. We can test it to validate that Nginx can correctly hand .php files off to our PHP processor.

We can do this by creating a test PHP file in our document root. Open a new file called info.php within your document root in your text editor:

Type or paste the following lines into the new file. This is valid PHP code that will return information about our server:

When you are finished, save and close the file.

Now, you can visit this page in your web browser by visiting your server’s domain name or public IP address followed by /info.php :

You should see a web page that has been generated by PHP with information about your server:

PHP page info

If you see a page that looks like this, you’ve set up PHP processing with Nginx successfully.

After verifying that Nginx renders the page correctly, it’s best to remove the file you created as it can actually give unauthorized users some hints about your configuration that may help them try to break in.

For now, remove the file by typing:

You can always regenerate this file if you need it later.

Conclusion

You should now have a LEMP stack configured on your Debian server. This gives you a very flexible foundation for serving web content to your visitors.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Источник

Оцените статью