💾 Archived View for darknesscode.xyz › linux › lemp-server.gmi captured on 2023-07-10 at 13:34:23. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2021-12-05)
-=-=-=-=-=-=-
* [nginx and php]
* [nginx and PhpMyAdmin]
All this is for **ubuntu server 20.04** it should work in **debian 10** but phpmyadmin needs to be install from source
Install nginx
sudo apt install nginx
When the istallation is done, check in your web browser
http://server_domain_or_ip
It will show something like "Welcome to nginx!"
Check [here](https://darknesscode.xyz/notes/nginx-setup) to setup nginx. Nginx is setup only to work with html in it base configuration you need to create a new server block to work with php.
Install mysql
sudo apt install mysql-server
When the installation is done, run a security script that comes pre-installed with MySQL
sudo mysql_secure_installation
Follow the instructions to setup the root password and other security checks for MySQL. Then run
sudo mysql
To check that everything works fine. If you have problems with your passwork check [here](https://darknesscode.xyz/notes/reset-mysql-root-password/) to reset the root password for MySQL.
Install PHP to process code and generate dynamic content for the web server
sudo apt install php-fpm php-mysql
Now that everything is install, let's jump to the fun part
Create a new server block to work with php, this is a new server that will point to a new website out of the html/ directory
First create a new directory (replace mydomain.xyz for your domain)
sudo mkdir /var/www/mydomain
Create a new nginx block in sites-avaible
sudo vim /etc/nginx/sites-avaiable/mydomain
Copy and paste this block, and make all the changes you need
server { listen 80; server_name mydomain.xyz www.mydomain.xyz; root /var/www/mydomain; index index.html index.htm index.php; 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; } }
When you done, save it and close it. Then enable your new domain
sudo ln -s /etc/nginx/sites-avaiable/mydomain /etc/nginx/sites-enable/
Now reload nginx
sudo systemctl reload nginx
And if you like you can re-start nginx as well
sudo systemctl restart nginx
Before your test your new server, create a php file in your root directory
echo "<?php phpinfo(); ?>" >> /var/www/mydomain/index.php
Now test your new php web site, it will show all the informations for php.
I like to use phpmyadmin to manage my databases, it's simple. To install if run
sudo apt install phpmyadmin
In the installation process phpmyadmin will ask some question to setup the config of ti. Answer to the questions
* **Answer YES**
* **write it down the password you setup in MySQL**
* **Don't select nothing in here, just press ok**
In here we need to create a new nginx server block with another domain or alias, in this case i will use and alias phpadmin.mydomain.xyz
Create a new file in
sudo vim /etc/nginx/conf.d/phpmyadmin.conf
Copy and past this block, and make all the changes you need
server { listen 80; listen [::]:80; server_name phpadmin.mydomain.xyz; root /usr/share/phpmyadmin/; index index.php index.html index.htm index.nginx-debian.html; access_log /var/log/nginx/phpmyadmin_access.log; error_log /var/log/nginx/phpmyadmin_error.log; location / { try_files $uri $uri/ /index.php; } location ~ ^/(doc|sql|setup)/ { deny all; } location ~ \.php$ { fastcgi_pass unix:/run/php/php7.4-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; include snippets/fastcgi-php.conf; } location ~ /\.ht { deny all; } }
Save it and close the new file. phpMyAdmin files are storage in **/usr/shara/phpmyadmin** direcotry
Test nginx configurations
sudo nginx -t
If any errors aren't show realod nginx
sudo systemctl reload nginx
Now go and test the domain you setup, in this case has phpadmin.mydmoain.xyz if everything whent well you will see phpmyadmin login.
Try out the script to automate all the process
git clone https://github.com/codedarkness/lemp_stack
----------
----------
© DarknessCode