¡Esta es una revisión vieja del documento!
# LEMP stack
Let's set up a LEMP stack (Linux, Nginx, MySQL, PHP) on your Ubuntu server. This combination allows you to serve dynamic web pages and applications written in PHP. Here are the steps:
## Install
- Install Nginx:
sudo apt update
sudo apt install nginx nginx-extras
sudo ufw allow 'Nginx HTTP'
- Install MySQL:
sudo apt install mysql-server
sudo mysql_secure_installation # - Secure your MySQL installation:
- Install PHP:
sudo apt install php php-fpm php-mysql
## Configure Nginx to Use PHP:
- Create a new server block configuration file for your website (replace
example.com with your domain):
sudo nano /etc/nginx/sites-available/example.com
- Add the following content (adjust paths and domain as needed):
server {
listen 80;
server_name example.com www.example.com;
root /var/www/example.com/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
- Enable the configuration:
```bash sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/ ```
## Test PHP with Nginx:
- Create a PHP test file:
sudo nano /var/www/example.com/html/info.php
- Add the following content:
```html <?php phpinfo(); ?> ```
- Save the file and visit http://example.com/info.php in your browser.
## Create a MySQL database and user:
sudo mysql
CREATE DATABASE mydb;
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';
GRANT ALL PRIVILEGES ON mydb.* TO 'myuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
## Troubleshooting & tips
* Update your PHP configuration to use the correct database credentials. * Remember to replace example.com, mydb, myuser, and mypassword with your actual domain, database name, username, and password. Once done, you'll have a functional LEMP stack on your Ubuntu server! 🚀. * `systemctl restart nginx php8.1-fpm`. * Empty browser cache.