DEV Community

Livecodebase
Livecodebase

Posted on

Ubuntu Nginx wordpress Configration

create folder in your directory with domain name

mkdir example.com
cd example.com 
Enter fullscreen mode Exit fullscreen mode

Installing Additional PHP Extensions

sudo apt update
sudo apt install php-curl php-gd php-intl php-mbstring php-soap php-xml php-xmlrpc php-zip
sudo systemctl restart php7.2-fpm
Enter fullscreen mode Exit fullscreen mode

Download wordpress and change into writable directory

curl -LO https://wordpress.org/latest.tar.gz
tar xzvf latest.tar.gz
cd wordpress
mv * ../
cd ..
rm -rf wordpress
cd ..
sudo chown -R www-data:www-data example.com
Enter fullscreen mode Exit fullscreen mode

Configure Nginx

cd /etc/nginx/sites-available
nano example.com
Enter fullscreen mode Exit fullscreen mode

paste below sample configuration

server {
        server_name example.com;
        index index.html index.php;
        root /var/www/example.com;

        location / {
                try_files $uri $uri/ /index.php?$args;
        }

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

        location ~ /\.ht {
                deny all;
        }
}
Enter fullscreen mode Exit fullscreen mode

then press CTRL + X and press Y and enter to save configuration

Now time to add this file in nginx sites-enabled dir. It ln -s creates a link to sites-available directory in sites-enabled directory

cd ../sites-enabled
ln -s ../sites-available example.com
Enter fullscreen mode Exit fullscreen mode

Now finally run below command to test nginx configuration

nginx -t
Enter fullscreen mode Exit fullscreen mode

if not get any error then restart nginx

systemctl restart nginx
Enter fullscreen mode Exit fullscreen mode

Time to setup mysql

mysql
create database example;
Enter fullscreen mode Exit fullscreen mode

Top comments (0)