Complete Web Server Setup(Apache2, php, mysql, phpmyadmin)

$ sudo apt-get update
$ sudo apt-get install apache2
$ sudo ufw app list
$ sudo ufw allow 'Apache Full'
$ sudo ufw status
$ sudo systemctl status apache2
$ hostname -I
$ sudo apt-get install curl

Manage the Apache Process

$ sudo systemctl stop apache2
$ sudo systemctl start apache2
$ sudo systemctl restart apache2
$ sudo systemctl reload apache2
$ sudo systemctl disable apache2
$ sudo systemctl enable apache2

How to install PHP

$ apt-get update
$ apt-get upgrade
$ apt-get install php
$ php -v
$ apt-get install php-pear php-fpm php-dev php-zip php-curl php-xmlrpc php-gd php-mysql php-mbstring php-xml libapache2-mod-php
$ apt-cache search --names-only ^php
$ systemctl restart apache2

How To Install MySQL 

$ sudo apt update
$ sudo apt install mysql-server
$ sudo mysql_secure_installation
$ sudo mysql -u root -p
$ sudo systemctl status mysql.service

How To Install and Secure phpMyAdmin 

$ sudo apt update
$ sudo apt install phpmyadmin php-mbstring php-gettext
ON UBUNTU 20
$ sudo apt install phpmyadmin php-mbstring php-zip php-gd php-json php-curl

If Error

mysql> UNINSTALL COMPONENT "file://component_validate_password";

After phpmyadmin installation

mysql> INSTALL COMPONENT "file://component_validate_password";
$ sudo phpenmod mbstring
$ sudo systemctl restart apache2

Grant Permissions in MySQL

mysql> GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';
mysql> FLUSH PRIVILEGES;

Enabling mod_rewrite

$ sudo nano /etc/apache2/apache2.conf
$ sudo nano /etc/apache2/sites-available/000-default.conf


<Directory /home/ubuntu/public_html/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>


$ sudo a2enmod rewrite
$ sudo systemctl restart apache2

Install and Secure Redis on Ubuntu 18.04

$ sudo apt update
$ sudo apt install redis-server
$ sudo nano /etc/redis/redis.conf
$ sudo systemctl restart redis.service

Testing Redis

$ sudo systemctl status redis
Note: This setting is desirable for many common use cases of Redis. If, however, you prefer to start up Redis manually every time your server boots, you can configure this with the following command:

$ sudo systemctl disable redis
$ redis-cli
127.0.0.1:6379> ping
127.0.0.1:6379> set test "It's working!"
127.0.0.1:6379> get test
127.0.0.1:6379> exit
$ sudo systemctl restart redis

enable/disable site in ubuntu

a2ensite, a2dissite - enable or disable an apache2 site / virtual host

DESCRIPTION

This manual page documents briefly the a2ensite and a2dissite commands.

       a2ensite  is  a  script  that  enables  the specified site (which contains a <VirtualHost>
       block) within the apache2  configuration.   It  does  this  by  creating  symlinks  within
       /etc/apache2/sites-enabled.   Likewise,  a2dissite  disables  a  site  by  removing  those
       symlinks.  It is not an error to enable a site which is already enabled, or to disable one
       which is already disabled.

       Apache  treats the very first virtual host enabled specially as every request not matching
       any actual directive is being redirected there. Thus it should be  called  000-default  in
       order to sort before the remaining hosts to be loaded first.

OPTIONS

 -q, --quiet
              Don't show informative messages.

       -m, --maintmode
              Enables  the  maintainer  mode,  that  is  the  program  invocation  is effectuated
              automatically by a maintainer script. This switch should not be used by end users.

       -p, --purge
              When disabling a module, purge all traces of the module in the internal state  data
              base.

EXIT STATUS

       a2ensite  and  a2dissite  exit with status 0 if all sites are processed successfully, 1 if
       errors occur, 2 if an invalid option was used.

EXAMPLES

              a2dissite 000-default

       Disables the default site.

FOR Enable SSL Module 

 sudo a2enmod ssl
 sudo a2ensite default-ssl 

FILES

       /etc/apache2/sites-available
              Directory with files giving information on available sites.

       /etc/apache2/sites-enabled
              Directory with links to the files in sites-available for enabled sites.

header set not working in ubuntu

$ sudo a2enmod headers
$ sudo service apache2 reload

after that write bellow config in your .htaccess file


 Header set X-XSS-Protection "1; mode=block"
  Header set X-Content-Type-Options nosniff


Leave a Reply