How to set up an LNMP environment in Ubuntu?
You can set up an LNMP environment (Linux + Nginx + MySQL + PHP) on Ubuntu system by following these steps:
- Install Nginx:
Execute the following command in the terminal to install Nginx. - Update using sudo apt and install nginx.
- To install MySQL:
Execute the following command in the terminal to install MySQL: - Install mysql-server using the following command: sudo apt install mysql-server.
- Install PHP:
Run the following command in the terminal to install PHP and its related plugins: - Install php-fpm and php-mysql with administrative privileges using the apt command.
- Set up Nginx:
Create a Nginx configuration file, such as /etc/nginx/sites-available/example.com, and add the following content to it: - server {
Port 80 is listening on the server for the domain example.com, with the root directory set to /var/www/html. The index files to be served are index.php, index.html, and index.htm.For the root location /, the server will attempt to serve the requested URI or directory, falling back to index.php if it’s a file or folder.
Requests for PHP files will be passed to PHP-FPM through the fastcgi protocol.
- Then execute the following command to enable the configuration file and reload Nginx:
- Create a symbolic link from /etc/nginx/sites-available/example.com to /etc/nginx/sites-enabled/, check the Nginx configuration, and then reload Nginx.
- Test LNMP environment:
Create a file named index.php in the directory /var/www/html with the following content: - Retrieve information about the PHP configuration by displaying the PHP information.
- Then, visit http://example.com in your browser. If you see the PHP information page, it means the LNMP environment has been successfully set up.
The process of setting up an LNMP environment on the Ubuntu system has been completed. If there are any questions, feel free to ask me at any time.