Skip to content

Instantly share code, notes, and snippets.

@enniosousa
Last active January 6, 2020 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enniosousa/74922b13601394f429d459fcbebce092 to your computer and use it in GitHub Desktop.
Save enniosousa/74922b13601394f429d459fcbebce092 to your computer and use it in GitHub Desktop.
Install LAMP (Linux Apache MySQL and PHP 7.3), Composer and SQL Server PHP PDO Driver

References

Useful Articles

Usefull Helpers

  • Laravel
    • Folder permission: browser to Laravelprojetc and run this command sudo chmod -R 775 storage && sudo chmod -R 775 bootstrap && sudo chown -R root:www-data .
    • Starting The Scheduler
      1. Open cronjob config crontab -e
      2. Paste the cronjob config documented here * * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1

Installs

Run sudo command without a password

  1. Backup your /etc/sudoers file by typing the following command: sudo cp /etc/sudoers /root/sudoers.bkp
  2. Edit the /etc/sudoers file by typing the visudo command: sudo visudo
  3. Append the following entry to run ALL command without a password for a user named tom: tom ALL=(ALL) NOPASSWD:ALL
  4. It must be like this image https://i.imgur.com/OWDs8jG.jpg

Update System

sudo apt update

Install Cron Job

sudo apt-get install cron

Install LAMP

Installing Apache and Updating the Firewall

Install Apache

sudo apt install apache2 --yes

Allow Apache port on firewall

sudo ufw allow in "Apache Full"

Hide System info in Apache config(Well explained here)

sudo nano /etc/apache2/conf-enabled/security.conf

Set this configs

ServerTokens Prod
ServerSignature Off 

Installing MySQL

sudo apt install mysql-server --yes
sudo mysql_secure_installation
sudo mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'passwordhere';
FLUSH PRIVILEGES;
exit

Installing PHP

sudo apt install php libapache2-mod-php php-mysql
sudo systemctl restart apache2

Installing Composer

sudo apt install curl php-cli php-mbstring git unzip --yes # install php dependences
cd ~ # browser do user directore
curl -sS https://getcomposer.org/installer -o composer-setup.php # download composer setup
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer # run composer setup and install into binaries path
rm composer-setup.php # delete composer setup

Microsoft SQL Server PDO Driver

Step 1. Install 7.3

sudo su
add-apt-repository ppa:ondrej/php -y
apt-get update
apt-get install php7.3 php7.3-dev php7.3-xml -y --allow-unauthenticated
exit

Step 2. Install prerequisites

Driver version 17.2 or higher is required for Ubuntu 18.04 support. Driver version 17.3 or higher is required for Ubuntu 18.10 support.

This tutorial is to Ubuntu 18.10. To others versions, please verify over Para outras versões verifique here.

sudo su 
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
exit
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install msodbcsql17
sudo ACCEPT_EULA=Y apt-get install mssql-tools
sudo echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
sudo echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
sudo apt-get install unixodbc-dev --yes

Step 3. Install Ubuntu Dependencies

sudo apt-get install libc6 --yes #(>= 2.21)
sudo apt-get install libstdc++6 --yes #(>= 4.9)
sudo apt-get install libkrb5-3 --yes
sudo apt-get install libcurl3 --yes
sudo apt-get install openssl --yes
sudo apt-get install debconf --yes #(>= 0.5)
# sudo apt-get install unixodbc --yes #(>= 2.3.1-1)

Step 4. Install the PHP drivers for Microsoft SQL Server

sudo pecl install sqlsrv
sudo pecl install pdo_sqlsrv
sudo su
echo extension=pdo_sqlsrv.so >> `php --ini | grep "Scan for additional .ini files" | sed -e "s|.*:\s*||"`/30-pdo_sqlsrv.ini
echo extension=sqlsrv.so >> `php --ini | grep "Scan for additional .ini files" | sed -e "s|.*:\s*||"`/20-sqlsrv.ini
exit

Step 5. Install Apache and configure driver loading

sudo su
apt-get install libapache2-mod-php7.3 apache2
a2dismod mpm_event
a2enmod mpm_prefork
a2enmod php7.3 #enable php 73
a2dismod php7.2 #disable php 72
echo "extension=pdo_sqlsrv.so" >> /etc/php/7.3/apache2/conf.d/30-pdo_sqlsrv.ini
echo "extension=sqlsrv.so" >> /etc/php/7.3/apache2/conf.d/20-sqlsrv.ini
exit

Step 6. Restart Apache and test the sample script

sudo service apache2 restart

Language and Time zone

sudo dpkg-reconfigure locales # regenerating the supported locale list
sudo update-locale LANG=pt_BR.UTF-8 #change the current default locale

Time zone

sudo dpkg-reconfigure tzdata

Run sudo command without a password

Step 1. Backup your /etc/sudoers file by typing the following comma

sudo cp /etc/sudoers /root/sudoers.bkp

Step 2. Edit the /etc/sudoers file by typing the visudo command

sudo visudo

**Step 3. Append the following entry to run ALL command without a password for a user named tom **

tom ALL=(ALL) NOPASSWD:ALL

Step 4. It must be like this image https://i.imgur.com/OWDs8jG.jpg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment