Contents
Install LAMP
Automatic
i'm not suggesting this because more often than not i got error instlalation.
Run the below command in terminal:
-
php latest
wget --no-cache -O - https://raw.githubusercontent.com/akzn/lamp-stack-install/main/lamp-install.sh | bash
-
php 7.4
https://github.com/akzn/lamp-stack-install/blob/main/lamp-stack-install-php7.4
low spec device my suffer slow install or hang if using automatic install
Manual
php 7.4 follow https://github.com/akzn/lamp-stack-install/blob/main/lamp-stack-install-php7.4 then change mysql credential
First off, run the below command to update package index:
sudo apt update
Then run these commands in terminal separately to install each component:
Apache
sudo apt install apache2
MySQL
sudo apt install mysql-server
for a system with low mem, mysql could fail to run.
Add this line to /etc/mysql/my.cnf
#custom setting to reduce usage
[mysqld]
performance_schema = off
key_buffer_size = 16M
query_cache_size = 2M
query_cache_limit = 1M
tmp_table_size = 1M
innodb_buffer_pool_size = 1M
innodb_log_buffer_size = 1M
max_connections = 25
sort_buffer_size = 512M
read_buffer_size = 256K
read_rnd_buffer_size = 512K
join_buffer_size = 128K
thread_stack = 196K
then run mysql_install_db
and mysql_secure_installation
PHP
sudo apt install php php-mysql libapache2-mod-php php-cli
php-fpm version
tba read https://tecadmin.net/setup-apache-php-fpm-ubuntu-20-04/
Adjust Firewall
sudo ufw allow in "Apache Full"
Adjust permissions
sudo chmod -R 0755 /var/www/html/
Allow running Apache on boot up
sudo systemctl enable apache2
Start Apache server
sudo systemctl start apache2
Test Apache
xdg-open "http://localhost"
Create sample PHP script file
sudo echo "<?php phpinfo(); ?>" > /var/www/html/info.php
Run sample PHP script file
xdg-open "http://localhost/info.php"
Install phpMyAdmin
phpmyadmin installation
Warning : When the prompt appears, “apache2” is highlighted, but not selected. If you do not hit SPACE to select Apache, the installer will not move the necessary files during installation. Hit SPACE, TAB, and then ENTER to select Apache.
Run the below command in terminal to install phpMyAdmin and it's prerequisites:
sudo apt install phpmyadmin php-mbstring php-gettext
And then enable required extensions:
sudo phpenmod mcrypt
sudo phpenmod mbstring
Then restart Apache server:
sudo systemctl restart apache2
Now navigate to the phpMyAdmin:
xdg-open "http://localhost"
force phpmyadmin to https
assuming our site already has ssl/https running on our domain, read Securing Apache With Let's Encrypt SSL Certificate
just in case we want to secure phpmyadmin with ssl
open your domain config where we want to open phpmyadmin with. Usually your main domain name.
/etc/apache2/sites-available/[your domain name].conf
add this block line
<Directory /usr/share/phpmyadmin>
Options FollowSymLinks
DirectoryIndex index.php
AllowOverride All
</Directory>
restart apache service
sudo service apache2 restart
Disable PhpMyAdmin Temporary
To secure phpmyadmin, we can disable phpMyAdmin by disabling the module configuration and enabling it only when we need it.
to disable
sudo a2disconf phpmyadmin.conf
sudo /etc/init.d/apache2 restart
Enable it with
sudo a2enconf phpmyadmin.conf
sudo /etc/init.d/apache2 restart
Add new mysql user (optional)
- login to mysql console
sudo mysql
- make a new user within the MySQL shell:
mysql > CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
- provide the user with permission to access to the information they will need.
choose what type of access to grant- grant all access to user
mysql > GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';
- grant access to certain database only
tba
- grant all access to user
if you have error when importing database using SQLYog, try to import using PhpMyAdmin directly
even better import using mysql console
Manage Virtualhost
Script Way
use bash script for easy manage
wget -O virtualhost.sh https://raw.githubusercontent.com/RoverWire/virtualhost/master/virtualhost.sh
$ chmod +x virtualhost.sh
Manual Way
Step 1 - Create New Virtual Host Files
Apache comes with a default virtual host file called 000-default.conf
that we’ll use as a template. We’ll copy it over to create a virtual host file for each of our domains.
Start by copying the file for the custom domain:
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example.com.conf
Open the new file in your editor (we’re using nano below) with root privileges:
sudo nano /etc/apache2/sites-available/example.com.conf
We will customize this file for our own domain. Modify the highlighted text below for your own circumstances.
# file : /etc/apache2/sites-available/example.com.conf
<VirtualHost *:80>
ServerAdmin admin@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# Allow the use of .htaccess files
<Directory /var/www/example.com/public_html>
Options FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>
At this point, save and close the file.
Step 2 - Enable the New Virtual Host Files
With our virtual host files created, we must enable them. We’ll be using the a2ensite
tool to achieve this goal.
sudo a2ensite example.com.conf
sudo a2ensite test.com.conf
Next, disable the default site defined in 000-default.conf
:
sudo a2dissite 000-default.conf
When you are finished, you need to restart Apache to make these changes take effect and use systemctl status
to verify the success of the restart.
sudo systemctl restart apache2
Your server should now be set up to serve two websites.
Securing Apache With Let's Encrypt SSL Certificate
docs
gist
Digitalocean Article
File and Folder Permission Scheme
755 for Folder
sudo chmod 755 $(sudo find /var/www/[webapps] -type D)
644 for file
sudo chmod 644 $(sudo find /var/www/[webapps] -type f)
Cheatsheet
file_upload_size
to know where loaded php.ini located, create phpinfo file
open and edit php.ini
nano /etc/php/7.4/apache2/php.ini
upload_max_filesize = 2M
post_max_size = 2M
sudo systemctl restart apache2